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: 

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

Solved!
Go to solution

The termination character can be set via the configure port VI. There are optional inputs on it to enable the termination character and what the character is. The default is to have it enabled and the default termination character is a new line '0x0A'. I suspect that the data being returned from your device has a new line in it which is causing your read to terminate on that character, not the full 34 bytes requested. Try changing the termination character (wire a U8 constant with a value of 0x5A) and see if that resolves your problems.



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 11 of 26
(1,551 Views)

Thanks again.

 

I have tried wiring the 0x5A constant to the VISA configure VI. The problem now seems to be, however, that anytime it encounters 0x5A, it stops reading, so the short read string happens more often. From this, I assume that the termination character input in the VISA Configure VI has preference over the byte count input in the VISA Read VI, right? Is there a way to reverse this, or the termination character, be it 0x5A or the default 'new line', has always preference?

 

Thanks a lot,

 

Gabriel

0 Kudos
Message 12 of 26
(1,533 Views)

@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?



Exactly. Since Visa Read needs the output from Visa Write as input, it must wait.

Often you want a small wait in between, which is one of the few instances where you need a sequence or express vi. Since Wait doesn't have error in/out you'll need to put it in a sequence and run the error wire through it.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 13 of 26
(1,514 Views)

Thanks everyone.

 

OK, so I have been reading about this whole quite a lot, and thought I had figured it out, but no luck yet, so I hope you guys can help me. Below is a detail of the new VIs I have implemented. I have added the small time delay and also a property node. In the property node I added 'End mode for Read', changed it to write and set it to (0) None. According to Labview Help, (0) None means 'The read does not terminate until all of the requested data is received (or an error occurs)'. So my understanding of this is that it should always wait for the 34 bytes to come in. However, it keeps reading a short string sometimes. For instance, this is the last one I caught:

A52E CDEF 4140 C9EF 4119 01BF 41E8 0048 420A

This one is 18 bytes long, but they vary in length. One thing I also noticed is that the last byte is always 0x0A (regardless of the string length).

 

Any ideas of why this could be happening? Am I connecting something wrong?

 

Thanks very much

0 Kudos
Message 14 of 26
(1,508 Views)

Sorry, forgot the attachment

0 Kudos
Message 15 of 26
(1,507 Views)

I would have to say that you did not properly change the termination character for the VISA read. Try wiring it to the VISA Init that you use after you open the connection. If that still gives you problems I would disable th eread until termination character and always read 34 bytes. Validate the response by checking that the last character is 0x5A.



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
0 Kudos
Message 16 of 26
(1,487 Views)

Thanks.

 

I am not sure I understand the explanation. I have tried wiring both 0x5A and nothing (so 0x0A, since it's the default) to the termination character input in the VISA Configure Serial Port VI. In both cases, no matter whether I set the End mode for Read property to (0)None or (2)Term. char, the string crops when it finds the respective termination character. So what I wonder is what the difference between (0None and (2)Term. char really is and what 'reading until all the requested data is received' means.

 

In terms of disabling the read until the termination character and always reading 34 bytes, I don't know how that would be done, but I would like to do it. In fact, what I would really like to do is to always read 34 bytes, or if not, get the first byte (0xA5), read 32 more, and then check if the 34th is 0x5A.

 

Sorry for the rumbling, and I appreciate the help.

0 Kudos
Message 17 of 26
(1,481 Views)

Where is your serial configure VI?

 

That is where you should be disabling or enabling the termination character and defining what the character is.  Then you won't need to add a VISA property node in the middle of execution to change the read mode.

0 Kudos
Message 18 of 26
(1,471 Views)

If the short stringalways ends with 0A, that is because the termination character is enabled and set to its default value, 0A.  You need to disable the termination character.  Don't worry about changing it, just disable it.  Do this by wiring a False constant to the "Enable Termination Character (T)" input to the VISA Serial Configuration VI.  See the picture below.

 

Example_VI_BD.png

 

 

- tbob

Inventor of the WORM Global
Message 19 of 26
(1,464 Views)
Solution
Accepted by gabrielcasano

Doesn't this sound familiar. I have done a lot of work with serial input and output. Setting the termination character enable to false never used to be enough, so I loaded my LabVIEW 2010 and looked at the context help for the Serial Settings property node: End Mode for Reads. here is what it says:

 

LabVIEW Serial Help.jpg

I learned back in LabVIEW 5.1 that setting the Termination Character Enable to False did not work as advertised. There is more work to be done. After setting this property node, reading 34 bytes from the serial port should work well.

 

You can also read the number of bytes at the serial port if you want to check how many bytes have come in.

 

     Rob

Message 20 of 26
(1,462 Views)