Serial Control in Windows Vista/7 Doesn’t Work Properly

I’ve had one of those weeks where I thought I was going crazy (crazier?).  My cross-platform application that works fine on Mac OS X was behaving very strangely in Windows but only sometimes.  This particular application talks to a hardware via a serial port.  My standard test platform is Windows 7 with Windows XP as the secondary and both of these are run in VMWare on my Mac.  So a bunch of things might be at fault but after trying this out on an old Windows XP laptop I quickly narrowed the problem down.

The data packet the hardware device sends is very small – 4 characters to be exact.  What I was experiencing was that RB captured the first character on the first send – but not the whole packet.  Then it would complete the first message on the 2nd message and only get part of the 2nd message.  It would go something like this:

  1. A
  2. B | A
  3. C | A
  4. D | A

Where A is common to all messages so they should be AB, AC, AD and so on.

These messages in the real world are sporadic and with the exception of a regular hardware pass message it might be days or weeks in between messages so as you can imagine, this problem mucks up the logic quite a bit.

If you are not familiar with the Serial control, the DataAvailable event fires when there is data available (duh) and there you can check what’s in the serial buffer by using the LookAhead function.  LookAhead in this case showed just the first character.  The other property to check is  BytesAvailable which should tell you how much is still in the buffer.  It simply returned zero so I should have a complete message.  Definitely something screwy going on there.

Invoking Serial.Poll via timer did not produce any different results.  Neither did forcing a ReadAll.

One other thing that I discovered was the Serial Port Monitors are worth their weight in gold.  Using one, you can at least verify that the data got to the computer.  A free 14 day trial was good enough but if I do any other serial projects it will be worth it.

The good news is that I wasn’t crazy.  The client is okay with Windows XP for now.  The bad news is that it might take a release cycle (or more) to get it fixed. Oh well, battles for another day….

For those that care, the Feedback id is 12723.

2 thoughts on “Serial Control in Windows Vista/7 Doesn’t Work Properly

  1. Thanks, Keith, but I spent way too much time in Windows 7 before trying Windows XP and Vista. The scary thing is is someone who only had Vista/Win7 would have just given up and assumed RB doesn’t work.

    Not that this problem is particular to RB, but I think a lot of new or part-time developers give up on a language or tool when they run into a problem they can’t figure it out right away. They’d like to ask someone (like the forums) but they’re not even sure what the right question is to ask or things to search for. Very frustrating.

Comments are closed.