Setting Serial Port Buffer Size
-
Hello All I am developing in eVC++ an application that reads from the serial port the binary data sent by a GPS receiver (Sirf protocol) The way of reading is the typical one, with a thread as shown in the tty example (Pocket PC 2002). Every time a character arrives, I do more or less the following:
BOOL bReturn = TRUE; DWORD dwCodsError, dwNumBytes, dwNumBytesRead; COMSTAT ComState; unsigned char BufferRead[5600]; ClearCommError(m_hPort, &dwCodsError, &ComState); dwNumBytes=ComState.cbInQue; if(dwNumBytes>0) { bReturn=ReadFile(m_hPort, BufferRead, dwNumBytes, &NumBytesRead, NULL); }
The problem is that the application does a lot of work, and from time to time, when the application is busiest, I lose some of the messages of the reveiver. In such cases, I have notice that cbInQue value is 2047, and that it never exceeds that number. I guess that is the maximum value of the Port Serial buffer-in. That should be the reason why subsequent messages are not stored in the buffer. At present I am trying not to overload so much the application, but I would like to know if it is possible to change the buffer-in size. In this way, I would not lose so many messages. I have tried with: SetupComm(m_hPort,BUFFER_IN_SIZE,BUFFER_OUT_SIZE); with BUFFER_IN_SIZE = 4095 and BUFFER_OUT_SIZE = 2047, but it doesn't work. Any Suggestions? Thanks in Advance PD: I am using the Emtac PCMCIA GPS receiver (just in case it was a problem with the driver) Carlos -
Hello All I am developing in eVC++ an application that reads from the serial port the binary data sent by a GPS receiver (Sirf protocol) The way of reading is the typical one, with a thread as shown in the tty example (Pocket PC 2002). Every time a character arrives, I do more or less the following:
BOOL bReturn = TRUE; DWORD dwCodsError, dwNumBytes, dwNumBytesRead; COMSTAT ComState; unsigned char BufferRead[5600]; ClearCommError(m_hPort, &dwCodsError, &ComState); dwNumBytes=ComState.cbInQue; if(dwNumBytes>0) { bReturn=ReadFile(m_hPort, BufferRead, dwNumBytes, &NumBytesRead, NULL); }
The problem is that the application does a lot of work, and from time to time, when the application is busiest, I lose some of the messages of the reveiver. In such cases, I have notice that cbInQue value is 2047, and that it never exceeds that number. I guess that is the maximum value of the Port Serial buffer-in. That should be the reason why subsequent messages are not stored in the buffer. At present I am trying not to overload so much the application, but I would like to know if it is possible to change the buffer-in size. In this way, I would not lose so many messages. I have tried with: SetupComm(m_hPort,BUFFER_IN_SIZE,BUFFER_OUT_SIZE); with BUFFER_IN_SIZE = 4095 and BUFFER_OUT_SIZE = 2047, but it doesn't work. Any Suggestions? Thanks in Advance PD: I am using the Emtac PCMCIA GPS receiver (just in case it was a problem with the driver) CarlosTry to increase the priority of the reading thread! Daniel ;) --------------------------- Never change a running system!