I wrote a simple C # 2.0 application using the .Net Framework 2.0 Serialport class to communicate with the controller card through COM1.
Recently, there has been a problem with invalid bytes returned by the Read method. It returned the correct number of bytes, only the values were incorrect. A similar application written in Delphi still returned the correct values.
I used Portmon to record activity on the serial port of both applications, comparing the two logs and where some (apparently) slight different settings, and I tried to emulate the Delphi application as close as possible, but to no avail.
So what can affect the byte values returned by the Read method?
Most settings between the two applications are identical.
Here is a list of lines that differed in the Portmon log:
Delphi app:
IOCTL_SERIAL_SET_CHAR Serial0 SUCCESS EOF: dc ERR: 0 BRK: 0 EVT: 0 XON: 11 XOFF: 13
IOCTL_SERIAL_SET_HANDFLOW Serial0 SUCCESS Shake: 0 Replace: 0 XonLimit: 256 XoffLimit: 256 IOCTL_SERIAL_SET_TIMEUUTS Serial0 SUCCESS RI: -1 RM: 100 RC: 1000 WM: 100 WC: 1000 IOCTL_SERALIALS RIALXSTIAL RJTSIALS RIALXSMIALSTRIALSSTIAL_SERIAL_STRIAL_SERIAL_TRIAL_STERIAL_SERIAL_TRIAL_STERIAL_SERIAL_TRIAL_STERIAL_STRIAL_STERIAL_STERIAL_STRIAL_STERIAL_STERIAL_STERIAL_STERIAL_TRIAL_STERIAL_STERIAL_STERIAL_STERIAL_STERIAL_STRIAL_STERIAL_STERIAL_STERIAL_STERIAL_STRIAL_STERIAL_TRIAL_STERIAL_TRIAL_STERIAL_STERIAL_TRIAL_STERIAL_STERIAL_LESS
C # application:
IOCTL_SERIAL_SET_CHAR Serial0 SUCCESS EOF: 1a ERR: 0 BRK: 0 EVT: 1a XON: 11 XOFF: 13 IOCTL_SERIAL_SET_HANDFLOW Serial0 SUCCESS Shake: 0 Replace: 0 XonLimit: 1024 XoffLimit_SERIAL_TIMEITIAL_TIMEITIAL_ITIAL_TECIALTITIALTECIALTIMEIT WM: 0 WC: 1000 IOCTL_SERIAL_SET_WAIT_MASK Serial0 SUCCESS Mask: RXCHAR RXFLAG CTS DSR RLSD BRK ERR RING
UPDATE:
The correct bytes returned were: 91, 1, 1, 3, 48, 48, 50, 69, 66, 51, 70, 55, 52, 93 (14 bytes). The last value is a simple checksum.
Incorrect return values: 91, 241, 254, 252, 242, 146, 42, 201, 51, 70, 55, 52, 93 (13 bytes).
As you can see, the first and last five bytes are returned.
The ErrorReceived event indicates that a framing error has occurred that may explain incorrect values. But the question is, why does SerialPort encounter a cropping error when the Delphi application does not seem to do?