Showing results for 
Search instead for 
Did you mean: 

How to read data from a text file?

Go to solution

How to read data from a text file?

How can I read numeric data from a text file?

Actually, I want to use a while loop and each time just read one array (one line) from the file. 


Then convert array to cluster. (I know this step, I used the function "array to cluster", right? )


Then assign this cluster to be the robot coordinates. (I connected the output of "array to cluster" to the "denso move by coordinates")


Anyone has any suggestions for me? Thanks! 

0 Kudos
Message 1 of 4
Accepted by topic author ZSH2010
08-27-2015 04:09 PM

Re: How to read data from a text file?



You have quite a few options to do this, and the best solution really depends upon what you are wanting to accomplish.  Here are a couple basic options, though.


First, is it important that you read from the text file each iteration?  Could you simply read out the entire file's position data then cycle through that data later?  If so, you could just read the file once at the beginning and use a FOR loop to cycle through the points.  Here is a screenshot of an example:



This example reads a text file with the following data:






It will read out the data into a 2D array which can be fed directly into a FOR loop to cycle through each line of position data. The use of indexed tunnels allows the FOR loop to only iterate the number of dimensions of the array (number of rows in this case).  Note that when using the Array to Cluster function, you will need to specify the number of elements as 7.  It does not dynamically adjust.  If you must read from the text file each iteration, here is another simple example using a While Loop:



Again, simple examples so you would want to make sure and check the robot status and do proper error handling for each method.  Is this close to what you were looking for?  I would also look into the File I/O examples that ship with LabVIEW for other options.
Message 2 of 4

Re: How to read data from a text file?

Thank you for your fast response! In first case, does the for loop automatically read one row each iteration? anything else I need to set?  

0 Kudos
Message 3 of 4

Re: How to read data from a text file?

Yes, since the position array's tunnel is set to be auto-indexed, it will cycle through each line of the 2D array each iteration.  When you connect an array to side of a FOR loop, it will be set to auto-indexed by default, so you do not have to change that.
0 Kudos
Message 4 of 4