LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to code this with serial communication?

Here's What I Want To Do.

There are two computers A and B. I send some variational data, 1.2,3.4 for example, from A to B once per second. If B has received the right data, he will send "Yes" to A, otherwise he will say "No". If received "Yes", A will get ready for the next data-sending. If "No", A will send the data again.

The examples with LabVIEW for VISA communication are all like that one computer is listening and the other one is writing all the time. So can you help me with two simple VIs for computer A and B?

Regards.
0 Kudos
Message 1 of 8
(3,037 Views)
You can "transmit" and " receive" data within the same VISA session on both computers. What you will need to do is to determine a way of how to connect the two computers so they can talk to each other. As long as you have them connected, open a VISA session on A and starting "writing" to B, B will "read" from the same resource, analyze the data, "write" back to A, so on.

The code for both computer will be similar and A will write first while B will read first.
0 Kudos
Message 2 of 8
(2,997 Views)
Look at examples: LabVIEW<->GPIB.vi or Basic Serial Write and Read.vi. Both are bidirectional. If you put these Vis on both computers you should be able establish two-way communications. When you are ready to automate the communications it is usually better to use lower level VIs and separate the read and write functions. If you are using the RS-232 serial ports checking the number of bytes at port (using a property node) and then only reading the number that is actually available is good practice.

Lynn
0 Kudos
Message 3 of 8
(2,992 Views)
You need to connect the two computers' serial ports with a Null Modem Cable (Tx/Rx, CTS/RTS, DTR/DCD reversed). The put the attached vi on computer A. It will send a command from an array, and wait for a response from computer B. If the response is Yes, then the next command will be sent. If not Yes then A will send the same command again and wait for a response. There is an Abort button if you want to abort, but it will only abort the current command. You can modify it to abort the whole thing by using a while loop to replace the for loop, and using the abort button to exit the while loop. I'll leave the coding up to you. You will have to write a vi to reside on B. I'll describe it but you can code it, good practice. Computer B should start off initializing the com port, like in the attached vi. Then loop at Bytes at Port until some bytes come in, then read the bytes. Use a comparison (equal) to check if the data is good. Use a case structure to define what to send back to computer A (Yes or No). Then write it back using Visa Write. Loop around the entire thing except for the com port init. Close the Visa after the main loop.
- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 8
(2,989 Views)
Thank you for your reply.
tbob,
i found something wrong with it, maybe time-delay is needed between the "visa write.vi" and the "vsia read.vi", any advice?
0 Kudos
Message 5 of 8
(2,970 Views)
If you are using the Bytes at Port in a loop between write and read, that should be OK without a delay. The read will not take place until there are bytes to read. If not using bytes at port, you should put in a delay. However, it is much better practice to use the bytes at port function before a read.
- tbob

Inventor of the WORM Global
0 Kudos
Message 6 of 8
(2,951 Views)
Here is the code for Computer B, it is almost the same as tbob suggested. You can choose to use "Bytes at serial port" or a wait before "read" starts. The number of iterations depends on how many data you are expected to receive, the for loop will stop after the last data being correctly received.
0 Kudos
Message 7 of 8
(2,944 Views)
hope this, too, helps!
Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
0 Kudos
Message 8 of 8
(2,921 Views)