I'm having trouble in setting up the COM port using the SerialPort
class. There are a number of settings that get set differently than I need them to be when I call the SerialPort
constructor. Using a port monitor application I have noticed the following:
- ReadIntervalTimeout = -1 (should be
0) - ReadTotalTimeoutMultiplier = -1
(should be 0) - ReadTotalTimeoutConstant = 1000
(should be 0) - WriteTotalTimeoutMultiplier = 0 (OK)
- WriteTotalTimeoutConstant = 0 (OK)
- EoFChar = 26 (should be 0)
- ErrorChar = 63 (should be 0)
- Break char = 63 (should be 0)
- XOn Limit = 1024 (should be 2048)
- XOff Limit = 1024 (should be 512)
- FlowReplace = 0x87 (should be 0)
How do I change these settings (I'm using C#)?
Best Answer
Those values cannot be set with the SerialPort wrapper class. It is an incomplete wrapper. You can look here for an example of changing the XON and XOFF characters. For the rest you'll have to refer to the DCB documentation.
Updated
The DCB flag values are bit fields in the DCB structure.
And in case you were wondering how SetDcbFlag figures out which bits you're manipulating, here it is (courtesy of Reflector):
You can see that for Bit #4 or #12 it uses a 2-bit mask, for Bit #15 a 17-bit mask, and for the rest a 1-bit mask.