LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how can i use a wait function with a termination char xD

Solved!
Go to solution

hello

 

I want to read a serial data every second. I tried to use a Wati (ms) , but it not working if i set a termination char xD. How can i read serial data every second? 

0 Kudos
Message 1 of 14
(4,752 Views)

Hi liviya,

 

using a TermChar you should read "as fast as possible" - the VISARead will wait for full messages on its own.

 

When you want to read once a second you should switch off the TermChar and read the whole buffer - or use the TermChar, but empty the buffer each second. Otherwise it may happen you read data less often than your device is sending them!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 14
(4,737 Views)

You have conflicting options.  You set up your VISA command to (a) wait 10 seconds before it times out, and (b) require that a termination character be received for a successful read.  This means that when you issue a VISA Read for 1024 characters, but none are coming in, the VISA command will "block" and won't return for 10 seconds.  Your While loop, meanwhile, has a 1 second wait, but if the VISA blocks, the Wait will simply expire.

 

One way to fix this is to change the VISA Timeout to 1 second.  When the VISA command finishes, check the Return Count, and if it is zero, you'll know that there was nothing read.  You can choose to leave the 1-second Wait in place or to remove it -- it controls what happens when there is data that VISA reads.  With the Wait in place, you will generate VISA Read requests once per second, but with the Wait removed, as soon as a VISA read succeeds (because there was data) or fails (because it timed out), you will "ask for more", and potentially read from your VISA device much faster than once per second.

 

Bob Schor

0 Kudos
Message 3 of 14
(4,721 Views)

 


 

When you want to read once a second you should switch off the TermChar and read the whole buffer


 if i switch off the TermChar and read the whole buffer then i am missing the data (say: completly missing data some times and some time it is displaying 2 instead of 72, 8 instead of 98..................... and some times not reading the data at that second(displaying previous second data for next 2 r 3 seconds). How can i fix this?

 

0 Kudos
Message 4 of 14
(4,694 Views)

Right now your termination is enabled by default and set to look for xA  (linefeed).  I fyou want it to be xD, then you need to wire a constant in there.

 

There is no good reason for you to be losing data right now.

 

How fast is your data coming in?  Faster than a second? Longer?  Is it fairly regular or inconsistent in timing?

 

You still seem to be talking about some conflicting requirements.  What are you trying to do with your 1 second wait/read requirement?

 

Let your serial communication control your speed.  Let your VISA timeout value be long enough to guarantee you'll get full messages, but not so long to be intolerable.  (To me a 10 second wait is too long.  For normal, short messages, 2-3 seconds is reasonable timeout value.)

 

Generally, it is a bad idea to have a shift register on your error wire unless you are taking special care of error messages in your code (which you aren't here).  But in your case it doesn't matter because you are stopping the loop on error anyway.   Consider an error on VISA communication to be a very plausible occurrence.  For instance, someone could accidentally knock out a cable and you'll get timeout errors.  If you have a shift register there, the timeout error will go to the beginning of the next loop iteration cause the VISA Read to never happen again because of the incoming error.  In your case, the error will just stop your loop and end the program forcing you to restart it.  (And in that case you will lose data.  I sure hope you aren't running this VI by using the Continuous Run button!)

 

What kind of device are you talking to?  Are you sure it is reliably sending data?

 

 

0 Kudos
Message 5 of 14
(4,675 Views)

How fast is your data coming in?  Is it fairly regular or inconsistent in timing?


As of know 100 counts/sec.(i am giving 100 counts/sec for checking purpose)           Yes it is inconsistent in timing.(Measuring radiation counter using Geiger Counter).

 


What are you trying to do with your 1 second wait/read requirement?


I need to measure the Count rate (no. of counts/sec), for this i need to read the data every second. If there is any possibility of measuring the count rate(counts/sec)  without reading the data every single second, it also helps for me. If possible please give me a way to do it.

 


What kind of device are you talking to?  Are you sure it is reliably sending data?


Psoc 4, i am sure it is sending the data reliably. And i am recieving exact data (in labview) which it is sending. But when i try to read the data every second i am having this trouble.

 

i need to read the serial data every second or i need to mesure the cout rate by reading the continours serial data(inconsistent in timing).

 

 

 

 

0 Kudos
Message 6 of 14
(4,668 Views)

Here is what I recommend you do:

Use the Bytes At Port to see if a message has started coming in (number of bytes greater than 0).

If a message has started, read the message, otherwise wait 100ms.  Put that in a loop and you will be ready to go.

NOTE: There is a 100ms wait in the FALSE case.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 14
(4,648 Views)
Solution
Accepted by topic author liviya

@liviya wrote:

How fast is your data coming in?  Is it fairly regular or inconsistent in timing?


As of know 100 counts/sec.(i am giving 100 counts/sec for checking purpose)           Yes it is inconsistent in timing.(Measuring radiation counter using Geiger Counter).

 


What are you trying to do with your 1 second wait/read requirement?


I need to measure the Count rate (no. of counts/sec), for this i need to read the data every second. If there is any possibility of measuring the count rate(counts/sec)  without reading the data every single second, it also helps for me. If possible please give me a way to do it.

 


What kind of device are you talking to?  Are you sure it is reliably sending data?


Psoc 4, i am sure it is sending the data reliably. And i am recieving exact data (in labview) which it is sending. But when i try to read the data every second i am having this trouble.

 

i need to read the serial data every second or i need to mesure the cout rate by reading the continours serial data(inconsistent in timing).

 

 


That VI you attached is the same one you attached before.

So it is sending 100 readings per second, but you want  only want to work with the data that occurs at the 1 second intervals?

If that is the case then even the 1 second timeout value on the VISA configure should not be a problem.

 

Then you want to proceed to read all the data as it comes in.  You can't directly control the device and how frequently it sends, so just keep reading as fast as it sends it.  Use the termination character to your advantage so that you know you are getting complete messages.

 

Now if you only want to actually the use the data every 1 second, then use and elapsed time VI  with a 1 second count on it to drive a case structure that actually processes the data.

 

Now you'll get all the data that comes in, but will work with the data at the interval that you want.

Message 8 of 14
(4,622 Views)

Hello,

 

Now i can read the serial data every second. But, here comes another problem when i am reading data suddenly it is falling to single digit or it enormously increasing to value of millions, i dont know why it is reading like that. The same data i am reading in an LED is perfect but when i try to read the data in labview this problem occurs. How can i over come this problem? i have tried by changing timeout , byte count, flow control, parity bit, baud rate , almost everything but nothing happens to work.

Is there any problem with my laptop OS( windows 10) or with labview (2014 student trial version)?

 

 

 

 

 

 

Download All
0 Kudos
Message 9 of 14
(4,543 Views)

Are you getting any timeout values?  That could be a reason you are getting zero values.  You'd get an empty string that would show up as 0 when converted from string to a number.

 

For the large numbers,  you must be getting sets of numbers appended together without your linefeed character.

 

Maybe you have an issue with your communication wire.  Maybe it is a problem with the device sending data.

 

Create an array of the strings come in each iteration from the VISA Read.  Look a that.  It should give you clues as to why the data is not matching what you are expecting.

0 Kudos
Message 10 of 14
(4,537 Views)