01-15-2014 04:35 AM
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!!
PS: what should I do if the bytes I'm receiving at the port is variable ?! use Bytes at port?
Solved! Go to Solution.
01-15-2014 05:28 AM
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.
01-15-2014 06:34 AM
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.
01-15-2014 07:39 AM
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)
01-16-2014 03:54 AM - edited 01-16-2014 03:57 AM
01-16-2014 06:48 AM
@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.