Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

[begineer] restarting a 'while' loop while reading from serial port

Solved!
Go to solution

Hi there! I'm reading some data from a COM port. I want to read my like this "S %d ". the device is sending the data continously and depending on when i push the run button in labview, it may start reading the data from its middle (%d is a four digit number). like: '23 S 15 '

 

whenever the first character of my data isn't 'S", i need to restart the reading. i read data in a while loop. so i need to stop the while loop. According to what i found on the internet, I used a case, another while loop and shift registers.

 

but somehow I get stuck at the inner while loop. my VI is attached. Thanks in advance and sorry if my code is a mess!! Smiley Tongue

 

PS: what should I do if the bytes I'm receiving at the port is variable ?! use Bytes at port?

0 Kudos
Message 1 of 6
(5,098 Views)

something just came to my mind. Is my method suitable to what I'm trying to do?! will this method restart the whole reading from port for me?! or I should use Invoke Node or sth like that?

 

any comment is much appreciated.

0 Kudos
Message 2 of 6
(5,088 Views)
Solution
Accepted by topic author Neo_Ev

Does the device send an End of Line character at the end of each message?  You are currently setup for that by enabling the termination character (currently set to be an End of Line/10/0xA).  If that is correct, then just set the bytes to read on the VISA Read to something rediculously high.  It will stop reading when it finds that termination character.  From there, you just have to check for the correct format.  If it isn't the right format, ignore it.  Otherwise do your logging.

 

I managed to clean up your code quite a bit based on this.


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
Message 3 of 6
(5,079 Views)

Thanks for the code. It looks so much better than the original one 😉

 

I think the terminating character is space. I'm not sure. The last character that it sends after the number is space. Unfortunately I'm not at the lab right now, I need to check the result and update it here.

 

one question: if I set the number of bytes to be read in Visa Read to a high number, can I use the code for online data logging ?!  what about the timeout? (If I were at lab I would check them)

0 Kudos
Message 4 of 6
(5,068 Views)
crossrulz: thank you so much for the code. I made some modifications to it and it works just the way I want it to. in variable bytes case, if there is a termination character sent, I need to set the bytes received in configuration higher than what I'm actually recieving. Right?!! what if there is no termination character sent with the data. how can I read variable bytes at serial port?! VISA Bytes at port?!
0 Kudos
Message 5 of 6
(5,028 Views)

@Neo_Ev wrote:
crossrulz: thank you so much for the code. I made some modifications to it and it works just the way I want it to. in variable bytes case, if there is a termination character sent, I need to set the bytes received in configuration higher than what I'm actually recieving. Right?!! what if there is no termination character sent with the data. how can I read variable bytes at serial port?! VISA Bytes at port?!

If there is a termination character, just set the bytes to read to something rediculous.  Yes, larger than what you expect in a message.

 

If there is no termination character, then you need to turn it off with your VISA Configure Serial Port (Boolean value on the top of the VI) and you will need to use Bytes at Port.


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
Message 6 of 6
(5,015 Views)