Andy
Andy

Reputation: 937

Break Condition on COM Port Open

I have an application developed in C that opens a COM port and sends data. This works fine and has done for years.

Now I have one user where it behaves incorrectly. On their PC when my code opens the COM port it generates a break condition. It does this until 11ms before the first byte of data is transmitted at which point the transmit goes back to logic 1. So it is:

When they use a third-party terminal program on the same PC it doesn't generate a break condition when opening the COM port.

I double-checked on my PC and sure enough the transmit signal stays at logic 1 until the first start bit, as expected.

I have no reports of this problem from other users. This particular user is using a COM port from a laptop docking station.

I configure the COM port using SetCommState and SetupComm. I call ClearCommError and PurgeComm at the end of initialization. I use CreateFile to open the port.

Here is the port configuration I am using:

mydcb.fBinary = TRUE;
mydcb.fParity = FALSE;
mydcb.fOutxCtsFlow = FALSE;
mydcb.fOutxDsrFlow = FALSE;
mydcb.fDsrSensitivity = FALSE;
mydcb.fOutX = FALSE;
mydcb.fInX = FALSE;
mydcb.fNull = FALSE;
mydcb.Baudrate = 19200;
mydcb.Parity = NOPARITY;
mydcb.StopBits = ONESTOPBIT;
mydcb.ByteSize = 8;
mydcb.fAbortOnError = FALSE;
mydcb.fDtrControl = DTR_CONTROL_DISABLE;
mydcb.fRtsControl = RTS_CONTROL_DISABLE;

COM port open:

comport = CreateFile(resourcename, GENERIC_READ | GENERIC_WRITE, 0,
  NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);

Does this problem ring any bells with anyone? Are there any hints or suggestions on where to look?

Upvotes: 1

Views: 629

Answers (1)

unwind
unwind

Reputation: 399803

OK, I'll try donning my Captain Obvious hat.

Did you try using the EscapeCommFunction() call to explicitly clear the break state of the port, right after opening it? Perhaps the UART drivers on that particular user's machine are buggy, so why not be epxlicit about what you want.

Upvotes: 2

Related Questions