01-25-2015 07:43 PM - edited 01-25-2015 07:45 PM
Given a minimal serial transmission such as:
string<CR> string<CR> <HT> parameter: value<CR> <HT> parameter: value<CR> <HT> string<CR> <HT> <HT> parameter: value<HT> parameter: value<CR> <HT> <HT> parameter: value<HT> parameter: value<CR> <HT> string<CR> <HT> parameter: value<CR> <HT> parameter: value<CR> string<CR> string<CR> :
which happens over about five discrete transmissions, meaning a couple lines are sent at a time. I would like to read a line at a time, placing each line as an element in a string array. I don't want to count on fixed byte-length. After EOT, for instance,
<CR>:
is reached, I'd like to iterate over the cell array in order to parse the parameter names and values.
Any comments on how to structure the .vi, and how to implement the reading a line at a time/exit a loop when an EOT is received would be most appreciated.
Chris
01-25-2015 08:20 PM
Since you are using a serial port, use the VISA API. Make sure the termination character is enabled and that it is set to the Carriage Return (I'm pretty certain both of those are the default when using the Configure Serial Port). Do the serial read in a loop and have the strings autoindex out of the loop. When you terminate your loop, you will have an array of the lines you recieved.
02-02-2015 07:48 AM
Thanks very much for the suggestions. Specific questions I'm left with which pertain both to your proposed solution and to my original question are:
1) How do I `autoindex the strings'
2) When I do not provide a number of bytes to read to the VISA serial read .vi I get an error (How to enable reading until terminator)
3) How could I implement a loop in which a VISA serial read .vi resides, the received string is scaned for / compared to an end of transmission (EOT) sequence. The loop is exited when the EOT is received.
Chris
02-02-2015 08:22 AM - edited 02-02-2015 08:22 AM
I would recommend looking at the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours
02-02-2015 02:59 PM
1) How do I `autoindex the strings'
Right-click on the output tunnel of your loop. there is an option there to autoindex
2) When I do not provide a number of bytes to read to the VISA serial read .vi I get an error (How to enable reading until terminator)
Then just use a unrealistically large number for the number of bytes to read.
3) How could I implement a loop in which a VISA serial read .vi resides, the received string is scaned for / compared to an end of transmission (EOT) sequence. The loop is exited when the EOT is received.
You can do the comparison on each read string.
02-02-2015 04:15 PM
Thanks for the comments. I can see lines of data showing up in the string indicator, however, it seems to me my string array is empty. I realize that I have some other code/vi's here, maybe these are the source of some issue? I'd like to next be able to cycle through the string array and start operating on the entries, searching for data, writing to numeric.
02-02-2015 04:26 PM
When you stop the loop (by pressing the stop button), your array indicator will populate. This is basic dataflow. The output(s) of the loop will not be available until the loop is done running.
02-02-2015 07:58 PM
Please take the tutorials I linked to.