Author Topic: Virtual Com port and "serial purge"  (Read 16415 times)

Jan Andersson

  • Member
  • ***
  • Posts: 15
Virtual Com port and "serial purge"
« on: March 15, 2011, 12:05:01 pm »
Hello,

I have run into a problem which seems to be caused by a combination of the behaviour of my device which implements a virtual Com port and a PC program which treats the Com port a bit "odd"(it reads character one by one). Sometimes my device happen to previously have buffered data for delivering to the PC, but the PC is issuing commands expecting other replies. When that happens the PC program sends a "serial purge" to the driver in order to empty the buffer and so get in sync once again. The problem I see is that my USB device doesn't get a notification telling it to purge its buffers too, and so the out of sync condition remains. So my question is: Is there support for that at all?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Virtual Com port and "serial purge"
« Reply #1 on: March 15, 2011, 12:51:40 pm »
Serial ports typically have a hardware buffers in the port hardware and software buffers in the driver. The details for the hardware buffers vary with the port hardware.

As an alternative the PC could read the previous response completely before issuing the next command.

Jan

mdlayt

  • Member
  • ***
  • Posts: 40
Re: Virtual Com port and "serial purge"
« Reply #2 on: March 15, 2011, 09:12:21 pm »
This is a recurring communication problem.

For a start:  If your host side program is really the only one that initiates communication, then I would start by making sure that the host side always *finishes* each communication, ie takes all the response that can possibly come.

If either side can initiate, you may need to tag your communication events so that each side can keep reading until it gets the response to the event *it* started.  (If you just try to flush with a timeout, you will still have the race that the device side may initiate just *after* you finish flushing.)

Jan Andersson

  • Member
  • ***
  • Posts: 15
Re: Virtual Com port and "serial purge"
« Reply #3 on: October 24, 2011, 10:44:16 am »
This thread is a bit old now, but the problem is still there. I didn't explicitly mention that I do not have control over the PC program as it is made by another company, so I simply have to adapt to the way it behaves. And that way is to issue serial purge commands when it feels the communication is out of sync. Seems I have to make my own virtual Com port driver and stop relying on usbser.sys?
« Last Edit: October 25, 2011, 04:46:41 am by Jan Andersson »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Virtual Com port and "serial purge"
« Reply #4 on: October 24, 2011, 05:26:42 pm »
On receiving a command from the PC, can the device purge whatever is in its transmit buffer and respond to the new command? And would that fix the problem?

It sounds like the problem is in the communication protocol the PC is using, not the COM-port driver.

Jan