|
More duh.
I see: dwSettableBaud in the list of COMMPROP structure
I can change that value ? In C# ?
The biggy: can I change it to 921600 ?
Super nice would be able to select it from a list
|
|
|
|
|
The reason I linked to the original article is because it's a C# version - so all the hard work has been taken care of for you.
|
|
|
|
|
I'm studying the example you suggested, "Basic serial port listening application". I'm trying to grasp the section titled, "...Updating baud rates supported by the selected device..."
I see that he opens the port, and then does some really really strange things to to something with the BaudRate (still trying to grasp the concepts) with something like eleven different levels of magic words, parentheses (2, 3, or 4 of them, not really sure at this moment) and some "or" lines, I think.
After all that, he closes the port.
Will the port remain at the speed he chose for the next open ?
|
|
|
|
|
The values there are instance values, so as long as the class is held by an instance, and as long as there is no other code changing these values, they will remain the same. Bear in mind that this is purely an example of the code in his library, it doesn't necessarily mean that he's closing the port immediately after he opens it - that's just the way he's presented the methods, with the close quite logically following the open.
|
|
|
|
|
Pete O'Hanlon wrote: as long as there is no other code changing these values, they will remain the same.
Okay, so, if I put that in an "init" sort of section, then I can open and close all day long and still keep the same speed ?
If so, that could help things a lot.
|
|
|
|
|
You should be able to - it really depends on whether you need to free that port up for anything else.
|
|
|
|
|
No, he is totally stuck with the external box the whole time. The customer wants it that way; in fact, it's a part of the entire system design; their people, processes, the whole works.
I'm still trying to figure out how to put different stuff in different files and let everybody see it.
|
|
|
|
|
Reading and studying, what does this sentence mean ?
"...The field dwSettableBaud from the COMMPROP structure is a join of all supported baud rates...."
I think I'm clear on the word "structure" but I don't get what the author means by the word "join".
|
|
|
|
|
Think of it as a flag. This means you can do logic like
if ((dwSettableBaud & BAUD_1200) == BAUD_1200) I'm assuming here that you know how to work with logical ands. If not, have a look at this[^] page.
|
|
|
|
|
Pete O'Hanlon wrote: I'm assuming here that you know how to work with logical ands.
Check.
My super-duper skillset is in low-level embedded systems; ANDing, ORing, XORing, NOTing, NEGing, complementing, and so on; clear on that. I normally do that to the individual byte/bit/word/whatever in the machine, I/O port, control registers, blah blah blah,,, so the elementary boolean stuff is okay with me.
Never really got much further than a few identities with the actual real live boolean algebraic equations; although what little I did was a brain blast all the way. Too bad nobody will pay you to do Boolean Algebra all day long.
I wish C# had some sort of facility to just define the byte you want, where you want it, and then put that byte in that place. Seems there are about a thousand rules involved for anything like that.
But, thanks for your concern. References are welcome always.
I still am trying to figure out how to make the groups of bytes in one file visible to the methods in another one. These source files are going to grow to well over a thousand lines; not good in my book.
|
|
|
|
|
Okay, I'm studying the suggested app from the 2nd message in this thread.
I see this magic word "SerialPortManager" in different files, and C# knows they are there.
When I try to put something in a different file, C# can't see it.
What's going on with this correct app that isn't going on with mine ?
I'll mark the SerialPortManager with bold type in these file clips.
File: SerialPortManager.cs
File: MainForm.cs
namespace SerialPortListener
{
public partial class MainForm : Form
{
SerialPortManager _spManager;
public MainForm()
{
InitializeComponent();
UserInitialization();
}
private void UserInitialization()
{
_spManager = new SerialPortManager();
(more stuff)
(more stuff)
(more stuff)
(more stuff)
(more stuff)
File: SerialPortManager.cs
namespace SerialPortListener.Serial
{
public class SerialPortManager : IDisposable
{
public SerialPortManager()
{
_currentSerialSettings.PortNameCollection = SerialPort.GetPortNames();
_currentSerialSettings.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_currentSerialSettings_PropertyChanged);
if (_currentSerialSettings.PortNameCollection.Length > 0)
_currentSerialSettings.PortName = _currentSerialSettings.PortNameCollection[0];
}
~SerialPortManager()
{
Dispose(false);
}
Sorry, no clue why the formatting goes into all italics in the second code snip
Anyway, which lines in his code are giving him the ability to share the names between files ? Why can't I share the name of this group of bytes between files ?
namespace SerialPortPractice_03
{
public partial class Form1 : Form
{
public byte[] This_Does_Not_Work = new byte[] { 0x01, 0x02, 0x03, 0x04 };
public byte[] A_Test_To_Experiment = new byte[] {
0xFF, 0xFE, 0xFD, 0xFC,
0x11, 0x22, 0x33, 0x44,
0x55, 0x66, 0x77
}
;
}
Really hate this, but until I figure out the secret, I'm going to have to adopt the use of one huge source file with all 17 commands typed out.
|
|
|
|
|
Ahhh. I think I see where you're having a problem. Each class there is in a separate namespace. In order to use a class from one namespace in another namespace, you need to make this visible in the class you are trying to use it in.
That's a quite confusing sentence, so a practical demo is in order here - there are two ways to see the class in a different namespace: the first way is to add a using statement before your class. So, in MainForm to see the SerialPortManager class, do this:
using SerialPortListener.Serial;
namespace SerialPortListener
{
public class MainForm : Form
{
private SerialPortManager portManager = new SerialPortManager();
....
}
} The other method to do this (in place of the using statement) is to fully qualify the classname by including the namespace in it like this:
namespace SerialPortListener
{
public class MainForm : Form
{
private SerialPortListener.Serial.SerialPortManager portManager = new SerialPortListener.Serial.SerialPortManager();
....
}
} If you are using Visual Studio and you have a class that is in a different unreferenced namespace, you should see a little blue square at the start of the class name (under the first letter). Either click this to bring up a menu or press Shift+Alt+F10; in both cases, it should let you choose whether to add the using statement or whether you want to fully qualify the class name.
|
|
|
|
|
Pete O'Hanlon wrote: Each class there is in a separate namespace.
Okay, so, the fact that all the files have the same line in them, near the top, i.e., this one...
namespace SerialPortPractice_03
namespace SerialPortPractice_03
...does not mean that they can see each other.
In other words, there is no "linker" (such as I am accustomed to having) which combines all the labels in different files into the same area in memory (even with the namespace line at the start) to allow one guy to call the other guy whenever he wants.
Am I close ?
|
|
|
|
|
C-P-User-3 wrote: Am I close ?
No. In the example you listed above, there were three separate namespaces. If your classes are in the same namespace, they can see each other.
|
|
|
|
|
Pete O'Hanlon wrote: No. In the example you listed above, there were three separate namespaces.
I'm going to double check that right now.
I was certain; like extremely certain; and made a deliberate effort; to make sure that every file had the same namespace.
Let me check that
Okay, the protocol file starts with these two lines...
using System;
namespace SerialPortPractice_03
The Form1.cs file starts off with these 9 (or 10 if you count the blank) lines...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
namespace SerialPortPractice_03
Do I have the correct idea about the keyword namespace in my mind ?
|
|
|
|
|
Yes. They are in the same namespace.
|
|
|
|
|
Still trying to figure out what's going on.
I see the phrase, "SerialPortListener", by itself, and in another place with a dot and "Serial" after it, like this: SerialPortListener.Serial;.
I'm looking at this section, several times over...
Pete O'Hanlon wrote: using SerialPortListener.Serial;
namespace SerialPortListener
{
public class MainForm : Form
{
private SerialPortManager portManager = new SerialPortManager();
....
}
}
I see the "using" line with the name, and a dot, and the word "Serial" on one line, then in another line, I see the exact same word used with the namespace directive, then again with the private descriptor (sorry for my vocabulary) then in the same line, with the new keyword; but this time with empty parentheses appended.
It would help me greatly if I could get some sort of idea as to what bytes are being placed where, when these words are used.
By the way, thanks for all this time and direction. Hope I'm not annoying you or the gang here. One of these days I would like to help others like you guys have been helping me.
|
|
|
|
|
What's probably confusing you is that the namespaces and class names are all very close. Let's simplify this with an easy example. Suppose we have a very simple vehicle creating system. I'm going to arbitrarily break this up like this:
namespace WeMakeVehiclesForOthers
{
public class BaseVehicle
{
protected void Buy() {}
}
} Now, in a namespace that we are going to call Cars, we are going to add a specific manufacturer:
using WeMakeVehiclesForOthers;
namespace Cars
{
public class Ford : BaseVehicle
{
public void BuyCar()
{
Buy();
}
}
} Now finally, we have a set of car dealerships that want to sell custom Fords. They might look like this:
using Cars;
namespace Dealers
{
public class PetesDealers
{
private Ford ford = new Ford();
public void BuyFord()
{
ford.BuyCar();
}
}
} As you can see, you have full access to Ford and all the methods it has available. I hope this makes sense
|
|
|
|
|
Pete, Dave, anybody else, thank you.
King of the clueless, reigns supreme again.
Just learned something: in order for one method in one file to see another thing (anything) in another file, in C#, you can't just open a file and type in the same namespace.
No, you must put the cursor over the name of your project, then right click, then choose "Add", then choose "Class", then go through a drop-down menu and choose "Class" again, then give that class a name, then click something else (my brain isn't good enough to catalog the full procedure, but you get the idea) and then some more stuff, and when you follow that procedure, C# does ninety seven magic tricks and the names in one file are visible to the other files.
I am sorry, sorry, sorry for creating such needless useless questions and draining your time in such an absurdly obtuse manner.
Honest, I saw the other files, and thought I could just say "File", "New", "File", and start typing.
Be respectful; you are in the presence of the King Of The Clueless.
|
|
|
|
|
C-P-User-3 wrote: I have seen other apps run 921600 on this very machine right in front of my
eyes.
That baud rate has to be user defined. It's not going to be in the base Windows API or the .NET Framework. It's extremely rare to find any use for a RS232 port faster than 115200.
Frankly, with a baud rate like that, the cable would have to be sheilded in lead and a max of 3 feet long for it to work with any reliability.
|
|
|
|
|
Clarification: I'm using BlueTooth across a USB (i.e., Fake-out) UART.
This is the hardware which I've seen do 921600 Bits Per Second, with "Terminal by Br@y" and 230400 with "TERMite" and maybe Hyperterminal as well.
(Hyperterminal hates my guts; he's really got it in for me; don't know why.)
|
|
|
|
|
Total time waste. Sorry for the trail of the red herring.
I discovered the big liar in all this.
Well, not sure exactly who is lying, but I have at least dissected the lie from the truth.
The lie: the limit is 115200
The truth: If you open that port at a speed of 115200, he can, and will, and does, deliver a speed of 921600. It also works at even lower speeds.
To really grasp the magnitude of this, check out these results...
-- I opened the port at 1200 bps.
-- The other side was doing 921600.
-- It worked.
|
|
|
|
|
How can I dispatch 30 threads to do 30 things ?
How do those threads inform each other of what they are doing ?
I looked up the word "Semaphore" on the MSDN site, and here as well. Apparently, C# and embedded systems have markedly different definitions of that term.
Still newbee noclue.
I'm watching some YouTube videos on the topic, still learning, really interesting, I think that threading will do what I want it to do.
Input is welcome.
|
|
|
|
|
|
Thank you. This stuff is relevant to my interests !
|
|
|
|
|