05-02-2013 08:35 AM
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
05-02-2013 09:10 AM
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
05-02-2013 09:18 AM - edited 05-02-2013 09:19 AM
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).
05-02-2013 09:20 AM
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.
05-02-2013 10:03 AM
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
05-03-2013 01:25 AM
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.
05-03-2013 06:31 AM
@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.