LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to executing serial commands from text document

I'm looking for some direction on how to read and execute a page of serial commands from a text file.  I have an instrument is controlled by serial communication.  Currently I have been using a state machine to operate the instrument.  The issue is that if I wish to change the sequence of commands I have to go back and rewrite the state machine to change the strings.  I had the idea of being able to just write the string commands to a text file with each line being a discrete command and after selecting the file the VI would execute the text page one line at a time.  I just don't  know where to start and have been unable to find an example to get me started.  This is above my programming level and I could use some direction on where to start.  The one issue I need to be able to address is if the VI executing the page of serial commands I have to have a way to abort the sequence if necessary.  

 

Thank you

 

Danny

Danny
0 Kudos
Message 1 of 7
(2,552 Views)

Standard Read from text file => character string

Use function Character string to array => array of string where each line in textfile is new element

USe for loop to iterate through the text file

Kind regards,

- Bjorn -

Have fun using LabVIEW... and if you like my answer, please pay me back in Kudo's 😉
LabVIEW 5.1 - LabVIEW 2012
0 Kudos
Message 2 of 7
(2,547 Views)

If you save your text file as a tab delimited (or comma, or just about any delimiter) it can be read and edited as a spreadsheet. With a delimited file you can then read it directly into an array from the file, using the "Read Spreadsheet" function in the "File" palette. You can then "pop" each line off the array (a number of ways come to mind, keeping track by storing on a shift register and incrementing the array index each time one is executed is one way, loading them onto a queue is another).

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 3 of 7
(2,543 Views)

Use the Read Text File.  There is an option via the right click menu to reads by lines.  Use that and set the number of lines to read to -1.  That will read the entire file and give you an array.  Now just use a FOR loop to index through the array.


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

LV_Pro, I didn't think about using shift registers to keep track.  Would that be the simplist way to do it?  I don't need high preformance and it's not a huge amout of data.  Probably looking at running 50-100 string commands for each analysis proceedure with just some simple feedback graphs.  It's not very demanding application.  I'll get started thinking about how to build some test VI to work through this.  Thank you for the help.

 

Danny

 

 

Danny
0 Kudos
Message 5 of 7
(2,524 Views)

If you want to process the entire array of commands in a state engine, indeed the better way of keeping track of where you are in the array would be a shift register.

When you're reading a new line, increase the index with one and put the new index in the shift register.

Kind regards,

- Bjorn -

Have fun using LabVIEW... and if you like my answer, please pay me back in Kudo's 😉
LabVIEW 5.1 - LabVIEW 2012
0 Kudos
Message 6 of 7
(2,497 Views)

@ABCPrograms wrote:

If you want to process the entire array of commands in a state engine, indeed the better way of keeping track of where you are in the array would be a shift register.

When you're reading a new line, increase the index with one and put the new index in the shift register.


That seems overly complicated, unless you want to go back and repeat steps.  But from the description from the OP, this is not desired.  The point of the text document is to easily change the state order.  Autoindexing is by far the simplest way to accomplish this.  If you really want to know what index you are on, just use the i terminal.


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 7
(2,490 Views)