943,734 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 8862
  • C RSS
You are currently viewing page 1 of this multi-page discussion thread
Feb 9th, 2008
0

Real COM port vs. USB-to-Serial cable

Expand Post »
Hi there,

recently I wrote a small C program utilising the Windows API to communicate with a device over the serial port (COM1, a real serial port of my PC).

This worked fine, but I am aware of the fact that those real COM ports are replaced more and more by USB-to-Serial adapter cables. So I have such a cable here, it's a Prolific USB-to-Serial Comm Port configured to be accessed through COM5.

So I thought since the COM5 should be emulating a real COM device, my program only needs to open COM5 instead of COM1. But I was proved wrong, it did not work. I tried to debug what was happening, but could not find a solution yet. I compared all the COM port's settings (baudrate, flow control, start/stop bits...) but there was no difference between the settings of COM1 and COM5.

What else can be the problem here?

Best Regards
Chris
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
friendfx is offline Offline
4 posts
since Feb 2008
Feb 9th, 2008
1

Re: Real COM port vs. USB-to-Serial cable

Take a look at:
http://www.lvr.com/usb.htm
Reputation Points: 309
Solved Threads: 43
Practically a Master Poster
ZZucker is offline Offline
676 posts
since Jan 2008
Feb 9th, 2008
0

Re: Real COM port vs. USB-to-Serial cable

Click to Expand / Collapse  Quote originally posted by ZZucker ...
Take a look at:
http://www.lvr.com/usb.htm
Sorry, but this link isn't very useful. There are no C code examples either, only VB.NET and C#.NET.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
friendfx is offline Offline
4 posts
since Feb 2008
Feb 10th, 2008
0

Re: Real COM port vs. USB-to-Serial cable

ive done a lot of work with COM ports, both real and virtual. Generally, I've not had problems accessing any of the com ports that are assigned by USB-RS232 converters. Ive gone all the way up to COM16 or maybe higher.

when ive had problems, its been for one of two reasons:

(1) the default Windows COM settings is preventing the use of any com ports numbers above a certain default number, typically "COM4"... there is a way to set this higher, pretty easy once you find it. Unfortunately my home computer is running Linux so I can't recall where this setting is found.

(2) sometimes USB - RS232 converters made by lower-end manufacturers have problems. especially with handshaking. If all else fails try a different manufacturer.

First what i would do is make sure you can talk through the USB-RS232 cable manually. Use TeraTerm or PuTTy or HyperTerm or whatever terminal emulator you like. Make sure that your converter cable actually works via COM5 in the emulator as the "real" port does on COM1 separate from your program. If it does work, and your program truly is apples-for-apples, then I would work on tracing down the problem i described above in (1).

good luck
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008
Feb 11th, 2008
0

Re: Real COM port vs. USB-to-Serial cable

Thanks for your suggestions, jephthah!

I used the Windows HyperTerminal program to test both COM ports. The protocol I am using is really simple, I write the string "mem" to the port and receive the answer. If I connect my device to COM1, it works correctly, with COM5, no answer is recieved.

To test if COM5 can talk to itself, I shorted the TX and RX signals and there it is: the echo in the HyperTerminal program. So this is working correctly, at least it is able to understand it's own signals ;-)

The next test was to connect COM1 to COM5, so I created a small adapter cable where RX of COM1 connects to TX of COM5 and vice-versa. Using two HyperTerminal programs, I tried to type into one of them and look if the text appears in the other. But, unfortunately, this did not work.

So I guess there's a difference between the voltage levels of the two ports so maybe you're right and the USB-to-Serial bridge is not designed to meet the real RS232 standards.

Concerning the handshake signals: The two cables I am using have only 3 signal lines (RX, TX and GND I guess) populated through a headphone jack. Therefore I have always set the Handshake option to "none". I hope this is correct?

Best Regards
Chris
Reputation Points: 10
Solved Threads: 0
Newbie Poster
friendfx is offline Offline
4 posts
since Feb 2008
Feb 11th, 2008
0

Re: Real COM port vs. USB-to-Serial cable

connecting one serial cable to the other, and running two instances of HyperTerminal on the two different ports will verify whether or not it works correctly.

but the thing to remember is both of your com ports are acting as a DTE ... in order to communicate straight through, one has to be a DTE and one a DCE. the difference between DTE (data terminal emulator) and DCE (data communication equipment) is that the TX and RX pins are swapped (pins 2 and 3, on a DB-9)

therefore you need a "null modem" cable to communicate between two com ports on two DTE machines (ie, typical PCs). In other words, cross over your pins 2 and 3 and retry :-) here's a good reference

since you're not using handshaking, your task is much easier. if you can get both of the COM ports to communicate back and forth -- in each direction -- then the problem is not your USB-Serial converter. If it's not the hardware, and you're certain your code is correct, then I would think its a Windows application setting. Perhaps your API limits the default Com Ports to COM1 - COM4 ?

if you get a chance, try using TeraTerm. it's open source freeware, and highly configurable, and IMO much better application than HyperTerminal. I think you'll like it.
Last edited by jephthah; Feb 11th, 2008 at 5:42 pm.
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008
Feb 11th, 2008
0

Re: Real COM port vs. USB-to-Serial cable

they work fine

i work in a shop selling computer h/w and electronic kits/components and custmers regularly use usb/serial converter cables to program small microprocessor boards etc... so they shold work fine
Moderator
Featured Poster
Reputation Points: 1764
Solved Threads: 574
Moderator
jbennet is offline Offline
16,505 posts
since Apr 2005
Feb 11th, 2008
0

Re: Real COM port vs. USB-to-Serial cable

Quote ...
I work in a shop selling computer h/w and electronic kits/components and custmers regularly use
i'm sure they do ... but which manufacturers are "they", that you're talking about working "fine"?

i mean, certainly *all* the various manufacturers don't work fine. because I've had *some* that don't work worth a damn, or they only work intermittently. often these are off-brand devices some people buy cheap off the internet. not to mention that even the good ones can fail.

Now, I don't know about his particular brand off the top of my head. It probably is fine.

but before I go debugging any code, i'm going to verify the hardware works first. I already learned that lesson, the hard way. Because I'm slightly dense, I learned it a few times.
Last edited by jephthah; Feb 11th, 2008 at 9:08 pm.
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008
Feb 12th, 2008
0

Re: Real COM port vs. USB-to-Serial cable

do a google for maplin electronics
Moderator
Featured Poster
Reputation Points: 1764
Solved Threads: 574
Moderator
jbennet is offline Offline
16,505 posts
since Apr 2005
Feb 12th, 2008
0

Re: Real COM port vs. USB-to-Serial cable

i think we are two trains passing each other in the night.
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: manipulation of strings
Next Thread in C Forum Timeline: c basic game





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC