Are there any com port programmers here? Need help...

NuclearNed

Raconteur
May 18, 2001
7,854
344
126
My company uses Magtek magnetic stripe readers to read information from employee id cards. Most pc's in my company has one of these readers installed. Until recently, we have been using a third party dll to communicate with the readers, but alas, this dll is showing signs of age (it was written for Win95). We have recently been getting a lot of phantom errors from this software (badge reader not detected, etc.)

A few weeks ago I took it upon myself to write a new communications dll using VC++, MFC, and standard API calls. The new dll works like a dream on all pc's except one in our test platform. All these pc's are roughly equivalent - their software configuration has no glaring differences. On the problem pc, the software works in some cases (i.e. it can detect whether or not the reader is present), but when the user is asked to swipe their badge, the badge reader seems to never send any data to the pc. In other words, in my test program I have written code to display the retrieved string from the badge reader in a messagebox. This code never gets fired, which means that the badge reader is never returning any data to the pc.

Does anybody have any ideas? I'm really stumped on this one.
 

UCJefe

Senior member
Jan 27, 2000
302
0
0
Has your baud rate been set correctly? Are you using the correct type of serial cable (null modem vs. normal)?

For any type of serial port programming, this tool has been absolutely invaluable. PortMon Using PortMon you can see whether the bytes are actually coming out over the serial port and just not being reeceived by your application or something else.

Anyway, baud rate or cabling is the normal culprit. If those are correct then post back with what Portmon told you. It does sound like a very strange problem

edit: fixed my horrible link
 

NuclearNed

Raconteur
May 18, 2001
7,854
344
126
Thanks for the reply. I'm pretty sure the baud rate is not the problem because I have a loop set up that will attempt to connect at various rates, starting with high rates and progressively working downwards. The way the loop works is that I set the baud rate and send the reader this string: "<esc>I". If the connection is successful, the badge reader returns this string: "R". I loop through different baud rates until I exhaust all possibilities, or I get a good connection. This part of my code always works successfully (i.e. I always get a truly successful connection, or I get the error message).

The baud rate idea was a good one, and I am starting to think that one of the other connection parameters might be different on the problem pc, specifically parameters dealing with buffer control. In general, I am allowing the connection parameters to use default values. Maybe I need to force known working values.

If I find a solution to the problem I'll post it.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
You should have your program set the proper paremeters, not count on defaults.

Also, depending on the H/W being used, the I/O buffer chips may be different on the test bed.

I ran into that using USB communications on a project. Buffering of data was handled differently, I had to adjust the applicaiton to compensate for partial data coming in on a read.
 

NuclearNed

Raconteur
May 18, 2001
7,854
344
126
The problem was being caused by using default values for some of the items in the DCB. I was forcing some of the DCB's members to known working values, but some I was allowing to default. When I began forcing all the members to known working values, the code started working as expected.

For a veteran programmer, I should have seen this right off, but I didn't.

Thanks for all the help, guys.