| | |
Real COM port vs. USB-to-Serial cable
Thread Solved
![]() |
•
•
Join Date: Feb 2008
Posts: 4
Reputation:
Solved Threads: 0
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
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
Take a look at:
http://www.lvr.com/usb.htm
http://www.lvr.com/usb.htm
Never argue with idiots, they'll just bring you down to their level and beat you with their experience.
•
•
Join Date: Feb 2008
Posts: 4
Reputation:
Solved Threads: 0
Sorry, but this link isn't very useful. There are no C code examples either, only VB.NET and C#.NET.
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
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
•
•
Join Date: Feb 2008
Posts: 4
Reputation:
Solved Threads: 0
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
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
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.
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.
•
•
•
•
I work in a shop selling computer h/w and electronic kits/components and custmers regularly use
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.
![]() |
Similar Threads
- pop ups are back (Viruses, Spyware and other Nasties)
- Removing Party POker popups (Viruses, Spyware and other Nasties)
- Help me save my old scanner (Apple Hardware)
Other Threads in the C Forum
- Previous Thread: getopt - help
- Next Thread: Need help turn this into a recursive function
| Thread Tools | Search this Thread |
* adobe ansi api array binarysearch centimeter changingto char character cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax database directory feet fflush fgets file floatingpointvalidation fork frequency function givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux highest histogram homework i/o inches infiniteloop input interest intmain() iso keyboard kilometer km linked linkedlist linux linuxsegmentationfault list locate looping lowest match meter microsoft mqqueue mysql oddnumber odf open opendocumentformat openwebfoundation owf pattern pdf performance posix power probleminc program programming pyramidusingturboccodes read recv recvblocked repetition reversing scanf scheduling segmentationfault send single socketprograming socketprogramming stack standard string suggestions systemcall unix urboc user voidmain() wab whythiscodecausesegmentationfault win32api windows.h windowsapi






