LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to make a VI wait to execute until another one finishes

Solved!
Go to solution
Highlighted

Hi all,

 

I have been reading the labview help for the sync functions, but I am still confused about how to perform this simple task. I have a labview program that connects to a DSP via serial (RS232). I use VISA Read and VISA Write to read to and write from the device. My goal is to first write, wait until writing is finished, then wait for, say, 100 ms (so that it is ensured that all the data has been sent correctly), and then perform the read operation.

At the moment I have VISA Write connected to VISA Read via the error out-to-error in wire. However, I am not sure that they perform one after the other correctly, so I would like to implement a more robust synchronisation.

 

Thank you very much in advance

0 Kudos
Message 1 of 26
(3,560 Views)
Highlighted

Hi!

 

LabVIEW ships with many examples. I a LabVIEW window, click on "help" and then "find examples". Click on the search tab and search for "Serial". There you'll find a basic serial read/write Vi you can study. If you use the error wires between the write and read VI's you'll ensure that they will excecute one after eachother, since LabVIEW follows the dataflow paradigm.

Regards,
Even
_________________________________
Certified LabVIEW Associate Developer

Automated Test Developer
Topro AS
Norway
Message 2 of 26
(3,555 Views)
Highlighted

What LabVIEW version?

 

It appears there may have been a bug in LV2010 VISA async/sync 

 

http://forums.ni.com/t5/Instrument-Control-GPIB-Serial/What-is-the-difference-between-doing-a-VISA-r...

 

 


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

0 Kudos
Message 3 of 26
(3,535 Views)
Highlighted

Thanks.

 

So, just to make sure I undertand correctly, if I wire 'error out' from VISA Write to 'error in (no error)' from VISA Read, it means VISA Read always executes once VISA Write has executed correctly?

0 Kudos
Message 4 of 26
(3,527 Views)
Highlighted

There is also another issue with the synchronous mode on VISA calls. As far as LabVIEW is concerned it is done once the data has been handed to the OS or lower level drivers. For instance, if you use the synchronous call for a VISA write on a TCP connection it will virtually always return immediately even though a trace (using something like Wireshark) clearly shows the data being delaying, buffered and sent out well after the call to the write complete. Given this is NI's position on how this call should work I imagine you could run into the same thing with other interfaces. Their position is that once they have handed the data to the lower level for delivery the call is complete, regardless of whether the data transfer actually was completed.

 

Even so, if you know what the data you expect back looks like you can simply use the read timeout to effectively give you the delay. Putting arbitrary delays in such as the wait 100 ms may work now but not work in the future. You are far better off to use your actual data streams to control your synchronization. This is especially true in a command/response type of protocol.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 5 of 26
(3,523 Views)
Highlighted

@gabrielcasano wrote:

Thanks.

 

So, just to make sure I undertand correctly, if I wire 'error out' from VISA Write to 'error in (no error)' from VISA Read, it means VISA Read always executes once VISA Write has executed correctly?


Yes, this is the definition of data flow. A node or VI cannot run until all of it's inputs are satisified. The outputs of a node or VI are not there until everything in that VI/node has completed. Therefore your read cannot happen until the write completes because the error out will not be present until the write has completed.

 

See my above post though regarding the synchoronus mode of teh VISA write.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 6 of 26
(3,517 Views)
Highlighted

Knowledgebase Article re: VISA comms:

 

The Effect of Asynchronous vs Synchronous VISA Write and Read Functions

 


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

0 Kudos
Message 7 of 26
(3,509 Views)
Highlighted

Thanks Mark.

 

I hope you don't mind me asking again, I've only been using labview for a couple of weeks.

 

What I am basically doing is sending a string of 27 bytes and reading a stream of 34 bytes. The DSP is programmed so that both the read and write strings must start with A5 (165) and finish with 5A (90). I've put a couple of indicators so I can see the strings that are being sent/received. The process seems to work fine, but sometimes (it seems randomly) the read function reads less than the necessary 34 bytes, so the finish bytes is not 5A.

Now, I don't know why this happens. Could it be because the Read function is not synchronised correctly and therefore reads less data after sometime? I have also written a little subVI that takes either the Read or Write string and check the first and last byte to see if they are what they are supposed to be. How could I use this to synchronise them?

 

Again,

0 Kudos
Message 8 of 26
(3,502 Views)
Highlighted

What is the timeout value you have on the VISA read? You have a couple of options you can do. You can set the termination character for the VISA read to your 0x5A and let it read until it receives that. This will help you to keep in sync with the data. If your return data will always be 34 bytes you could simply read 34 bytes at a time. You could test the end character to ensure it is 0x5A therefore validating the data you read. Either of these approaches will work You also have to make sure you give your reads enough time (the timeout) to allow the device to respond. It will return as soon as it has all the data (either the termination character or the exact 34 byte read). It will give you an error if those conditions aren't met within the timeout period.

 

BTW, could you post your code? It would be easier to offer help if we can see exactly what you are doing.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 9 of 26
(3,497 Views)
Highlighted

Thanks again Mark,

 

As you can see in the attachment, I have it set up so that it reads exactly 34 bytes (I don't know how to set the termination character). With respect to the timeout, if I understand correctly, it is 10 seconds. I have tried setting the read and write functions to be in synchronous mode, but the random read error keeps occurring.

 

Thanks a lot again,

 

Gabriel

0 Kudos
Message 10 of 26
(3,490 Views)