From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Communication over 2 serial ports help - timeout

Hi all,

I'm using LV 8.0
The problem is the following:
I have to set up a serial port communication between 2 computers (or between 2 different serial ports of 1 computer). I need to create a VI which works in the following way:
- 2 fronts panels (1-1 for the different computers)
- 1st front: there is a button and a thermometer
- 2nd front: LED and a knob
So the 2 PC's are connected with serial cable, and if I push the button on the 1st front, the LED must be turned on on the 2nd; and when I'm changing the values of the knob on the 2nd, the thermometer must follow it on the 1st.

My biggest problem is still, that I simply can't communicate between the 2 ports.
I did the port tester successfully (with the basic serial read and write.vi by shorting the port's 2&3 pin with a jumper), so the ports are working.
I connected the 2 serial ports of 1 PC to each other with a null-modem cable. (male+converter/female)
Than I try to use the "Basic 2 port serial read and write.vi" and I always get an error:

"Error -1073807339 occurred at VISA Read in Basic 2 Port Serial Write and Read.vi

Possible reason(s):

VISA: (Hex 0xBFFF0015) Timeout expired before operation completed."

Please help to solve this. Everything's on default value.
0 Kudos
Message 1 of 14
(2,916 Views)

To make sure your cable is good, try shorting out the Tx Data and Rx Data pins on the far side and see if the data gets returned.  If you have a breakout box, make sure your handshaking signals are OK (DTR, DSR, CD, RTS, CTS).

You could also use Hyperterminal on both computers to see if the data is going across both ways.  Do this first.  If OK, post your code.

- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 14
(2,913 Views)
Thanks for answering,

The cable is good for sure, I tested it now again and is working with the basic serial read and write.vi.

I don't know if I have a break out box (than I guess I don't have). I just have a computer with 2 serial ports (COM1, COM2) and a null-modem cable from COM1 to COM2 directly.

I also tried Hyperterminal http://www.ni.com/support/serial/verhyper.htm but it fails to double the characters I wrote. But if the vi above is working I guess the ports are ok, just like the cables.

I don't have a code right now, because I wanted to run successfully the basic 2 port serial read and write.vi for first, and I wanted to use it as a stepping stone.
0 Kudos
Message 3 of 14
(2,906 Views)
For the characters to be doubled, the cable has to have Tx shorted to Rx.  Never mind that, connect the two PCs with the Null Modem cable.
Run hyperterminal on both PCs.  When you type on PC1, do the characters show up on PC2?  When you type on PC2, do they show up on PC1?  Both directions have to work before the vi can work.
- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 14
(2,901 Views)
Oh. That was the mistake. I didn't short the Tx and Rx. But now it works on hyperterminal too.

I made this loopback test for both ports, so the vi should work. So the problem should be in LV. Maybe I don't use the example vi in a good way?

I connect the 2 ports and run the example vi. "basic 2 port serial write and read.vi". It occurs a timeout error. When I try debug mode, I see it writes the entered string correctly. The initialization of the other port is also correct. I have the same properties for both ports. The data flow stops when entering into the VISA read.

Do u have any idea about it?
0 Kudos
Message 5 of 14
(2,895 Views)

OK, I just looked at the Basic 2 Port Serial vi.  This vi is expecting two connections to two different com ports on the same computer.  This isn't what you want I think.  What you want is a vi on one computer that writes then waits for serial bits to read.  On the other computer, you want to read first then write.  Write your own vi's using the Basic Serial vi as an example on how to write and read.  One exception, you need to use the Bytes at Port function to wait for serial bytes to arrive before attempting to read them.  Look at the picture below:

Add this to your code.  It waits in a loop for bytes to arrive at the serial port.  After arriving, it reads the bytes.  The timeout control value is in tenths of a second and is used in case the serial port never receives anything.  The Num Bytes control is used in case you want to wait for a certain number of bytes before reading.  You can set it to 0 and it will read all bytes.

Message Edited by tbob on 10-30-2006 12:14 PM

- tbob

Inventor of the WORM Global
0 Kudos
Message 6 of 14
(2,894 Views)
Well, I need to test this in one PC, because I don't have serial port on the other. So I use 1 PC's 2 ports.

I created 2 vi-s based on the basic serial vi and started to run both. Nothing happened. Run both without errors.


0 Kudos
Message 7 of 14
(2,882 Views)

So you have just one PC with a null modem cable between COM1 and COM2?  You are writing to COM1 with one vi and expecting to read from COM2 with the other vi?  It could be that when you are closing the VISA session to either COM port that the data is lost.  Don't close the COM port yet.  Write just one vi and do this:

1.  Initialize COM1 and COM2.

2.  Write some characters to COM1.

3.  Read characters from COM2.

4.  Close both ports.

User Error In/Out to dictate the execution flow.

- tbob

Inventor of the WORM Global
0 Kudos
Message 8 of 14
(2,875 Views)
Yes, I exactly want to do that. I deleted the VISA Close from my vi. When I write something to com1 then the data don't arrive to com2, so ends with timeout.

0 Kudos
Message 9 of 14
(2,871 Views)
Delete the Error Out wire from the 2nd VISA Initialize going to the Bytes at Port loop.  Wire Error out from the VISA Write vi to the Bytes at Port loop.  Wire the VISA Read Error Out to the Merge errors vi.  This will make the write take place before the Bytes at Port and Read.  Be sure to set the timeout to something like 50 (5 seconds).  This should work.
- tbob

Inventor of the WORM Global
0 Kudos
Message 10 of 14
(2,860 Views)