-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Description
COMMPROP describes dwMaxBaud as max baud rate in a table of enumerations but the code in SerialStream.Windows.cs compares the max baud rate directly to the baud rate in several place. If commProp.dwMaxBaud is 64 (1200 bps) and baudRate is 1200 bps, the exception is thrown that it's out of range.
Lines 626-627
if (_commProp.dwMaxBaud != 0 && baudRate > _commProp.dwMaxBaud) throw new ArgumentOutOfRangeException(nameof(baudRate), SR.Format(SR.Max_Baud,_commProp.dwMaxBaud));
Reproduction Steps
- Find a com port device that has a max baud rate defined as an enum
- Attempt to open a com port created with the max baud rate.
- Observe the exception thrown.
`
// COM6 max baud rate is 64, which is enum for 1200.
using (var sp = new SerialPort("COM6", 1200))
{
sp.Open(); // throws exception that max baud rate is 64.
}
`
Expected behavior
Successful opening of com port when dwMaxBaud is not zero by converting the dwMaxBaud enum to a baud rate value.
Actual behavior
Exception thrown because it's comparing an enum to a value
Regression?
No idea.
Known Workarounds
For the com port device we have this issue, it does work if setting the baud rate to 64 since only one baud rate is valid for the device.
Configuration
.netstandard20
Windows 11
Any CPU (x64)
Other information
No response