LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to check rs232 connection is working proprely

Hi,
I d like to know if there a way to check the rs232 connection status, I have tried to use GetComConnectionState (1)==1) but it always give me an error but I get the error code -1
I guess it is because" This function works only with NI Serial hardware. The function returns an Unknown System Error with other hardware ports." as it is notified in functiun help
I also tried to use if (GetComStat (1)!=0)  but even when I haven't connected the cable no error appears.

Does anyone have a suggestion.

Thanks

Olivier

0 Kudos
Message 1 of 4
(9,220 Views)
You can install a callback to be fired in case of some hardware errors (frame, parity and overrun errors) by using InstallComCallback (com, LWRS_ERR, 0, 0, ErrorHandlerCallback, 0);
But I must advise you that in my experience I never saw this callback fired even in case of faulty cables and connectors that lead to intermittent connections Smiley Sad I had to add some message checking immediately after reading the port to filter out some unrecognized messages that I occasionally receive.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 4
(9,206 Views)
I've used the NI serial library and both NI and third party serial hardware and I've never seen a "hardware error" reported either.

My experience is that you have to grind through cable and connector issues, and independently verify that you have things right with the cable. 

The single biggest issue is knowing if your devices are configured as DTE or DCE, as that dictates connector pinout and that in turn dictates cable wiring.

Once you know the cabling is OK, you need to check com port configuration on both ends.  Data width, bit rate, stop bits, parity must all agree.  You can always use and extra stop bit on the sending end in case the receiving port is having trouble with frame to frame timing. 

Substituting one end or the other with a PC running Hyperterminal, or TerraTerminal, or Terminal (my current favorite) can also help you gain insight as to what's happening.

Worst case you can hook up a logic analyzer and look at everything at the signal level.    I use to have an old Biomation K100D with an rs-232 probe that I hauled all over the world for the worst problems.  Seems like overkill but it often served as my "final answer".

You can simplify your connection scenario while you figure out cabling / config issues - use short cable runs, lower the bit rate, etc.

Sometimes cable length and ground loop issues will hose up a connection even though you're kosher as far as cable wiring and config.  NI makes opto-isolated serial ports to manage the ground loop problem.  Work out your cable wiring and port config issues with the simplest possible connection scenario first if you're still having trouble.

Menchar
Message 3 of 4
(9,192 Views)
An explanation far better than my off the cuff reply is at

http://en.wikibooks.org/wiki/Serial_Programming:RS-232_Connections

The section on connections explains serial cabling and also has some external links that are worthwhile.

I've used C Programmer's Guide to Serial Communications  ISBN 0-672-30286-1

and

Serial Port Complete ISBN 096508192-3

But there's a lot of info on the web about serial ports, cabling, connectors, protocols, etc.

It takes some patience to work through serial connection issues - everything pretty much has to be right or it doesn't work, though with many if not most port config issues you'll see something come across even if it's garbled.

I didn't mention flow control or protocols, this is also relevant.

NI did rework the serial library in 8.1 RTE, and some poorly implemented serial ports may break, I think due to shorter inter-frame delays when issuing a buffer using ComWrt.

Menchar


0 Kudos
Message 4 of 4
(9,157 Views)