LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial read, store each line in string array

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

0 Kudos
Message 1 of 8
(4,902 Views)

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.


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 2 of 8
(4,885 Views)

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

0 Kudos
Message 3 of 8
(4,798 Views)
0 Kudos
Message 4 of 8
(4,786 Views)
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.

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 5 of 8
(4,769 Views)

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.

 

ftp_identify_vi_screencapture_a.png

0 Kudos
Message 6 of 8
(4,760 Views)

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.


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 8
(4,757 Views)

Please take the tutorials I linked to.

0 Kudos
Message 8 of 8
(4,738 Views)