serial comm timeout problem?
-
I´m writing an application that is communicating with an external device through the serial port (programming in VC++ .net with createfield etc). I am sending some characters to the device, end expect to get an answer. The problem is that I always get more characters back than I should. I expect the characters “22001C” however, depending on the values of WriteTotalTimeoutMultiplier and WriteTotalTimeoutConstant I get replies like: “222001C” , “220001C” and “220011C” , always a character too much. I think it is a problem with the timeout configurations, but I´m not sure, as I am just a beginner to c++. Does anybody have a clue as to what might be the problem, and how to solve it ?? Best regards doneirik
-
I´m writing an application that is communicating with an external device through the serial port (programming in VC++ .net with createfield etc). I am sending some characters to the device, end expect to get an answer. The problem is that I always get more characters back than I should. I expect the characters “22001C” however, depending on the values of WriteTotalTimeoutMultiplier and WriteTotalTimeoutConstant I get replies like: “222001C” , “220001C” and “220011C” , always a character too much. I think it is a problem with the timeout configurations, but I´m not sure, as I am just a beginner to c++. Does anybody have a clue as to what might be the problem, and how to solve it ?? Best regards doneirik
If there is a problem with the data reception, I doubt the problem has anything to do with the timeout values for writing. If the received data differs depending on your writing timeout values it's more likely you have a timing problem accessing the port. If you have opened the port non-overlapped a reading operation will prevent a writing operation until it reaches its timeout and vice versa. Are you sure that no other signals have to be manipulated such as DTR and/or RTS? Usually they have, try with HyperTerminal which sets both RTS and DTR to active state if you select no handshaking. This is easily done with the DCB struct and SetCommState. To nail down the real problem, try this: 1. Do not use read/write timeouts. MSDN tells you how to set this up. 2. Connect to another PC or COM-port and open it with HyperTerminal, see if you can receive expected data sent from HT. Alternate 2: create a loop-back by connecting Rx and Tx (pin 2 and 3) and see if you can read the data you are sending. Hope this helps -- Roger