Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Question about sending and receiving on RS485 in 2 wire mode

I am working with a PXI-1000B unit with a 8241 card in it which contains 4 RS485 ports, identified by COM3, COM4, COM5, and COM6 respectively. I set up the necessary connections to do an RS485 loopback test in two wire mode as described in this article:

http://digital.ni.com/public.nsf/3efedde4322fef19862567740067f3cc/d5cc369b3e3e6f0586256d1600563245?OpenDocument

I set up the loopback test using ports COM3 and COM4. I was then able to open 2 hyperterminal sessions, one for COM3 and one for COM4, and send messages back and forth. Whatever I typed into one window would be displayed in the other. I then took the Labview example program "Serial Communication.vi" (it's in the demos, go to help->find exam
ples->Hardware Input and Output->Serial) and modified it slightly. I made a separate Resource name input for the Serial Read VI instead of using the one output from the VISA read VI. I then ran the program and set the first resource to COM3 (the port which writes the string), and the second one to COM4 (the one which reads the string back). The program ran correctly and read the input string back without any error. But then when I try to run the program again, it doesn't read anything back and the error out box displays the following:

VISA Read in Serial Read with Timeout.vi->RS422.vi

The error code is 0x3FFF0006

I found out that if I switched which COM port was reading and which was writing, the program would run correctly again. But then every time I run the program, I have to switch which COM port is reading and which is writing. How can I prevent this and make it so that COM3 is always writing the string, and COM4 is always reading it?
0 Kudos
Message 1 of 2
(2,924 Views)
It is possible that you are attempting to read some number of bytes that are not available in the buffer on your second read of a given port, which causes the read function to time out. You can reconcile this by including a termination character, because the read function will read until it sees a). a termination character, or b). the number of bytes specified to read, or c). a timeout occurs (whichever of those 3 occurs first). By default, the termination character is the linefeed if you are using the VISA Configure Serial Port VI; you can include this character at the end of your write string by simply typing after typing the text you would like to send. If you do not want to type this everytime, you can add a termination character programatically usin
g the string concatenation function from the string palette, where you should concatenate your write string and a linefeed (or end of line constant for platform independence) before wiring into the write buffer input of the write function.

Hopefully this helps.

Regards,

Jassem
Applications Engineer
National Instruments
Best,
JLS
Sixclear
0 Kudos
Message 2 of 2
(2,924 Views)