LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

is this a correct way to write data each time the loop is excuted?

Solved!
Go to solution

I created a VI and my purpose is to log data each time the loop is executed. SO far I only learned to write binary file...I wish I could write numeric value directly....

 

The only problem is I dont if my method is correct because I am afraid that each time the loop is executed, the previous binary data will be overwritten... I dont want that happen.

 

Do you think my logic is proper in terms of logging data?

 

Thank you!

0 Kudos
Message 1 of 11
(2,893 Views)
Solution
Accepted by topic author ivy037

Your logic is fine. You won't overwrite data because the file pointer will move as your data is written. If your program stops and then you start it again, and you want data to be appended to the file, you can use the set file position VI and set the pointer 0 bytes from the end. Set this position one time, after you open the file (so outside the loop) and then data will be appended.

 

If what you mean by "write a number directly" is write something in a human redable format, you can use write to text file instead of write to binary file. Then use either the format string VI or number to fractional string VI to convert your double to a string and write it.

0 Kudos
Message 2 of 11
(2,885 Views)

thank you, yes, replace it with write to text and convert number to string will do the work

 

I have another question. after the logging is done, I want to read it, then, I did this in VI. However, my VI only reads the first value, how to ask the VI to read the last value?

 

 

0 Kudos
Message 3 of 11
(2,875 Views)

Without seeing what you did in your VI, I'm not sure. My guess is the file pointer is still at the end of the file, and you need to move it back to the beginning before doing the read. You can use the same "set file position" VI and put the offset at 0 bytes from beginning. If you are reopening the file after you close it, then something is wrong. There may only be one number in the file, but you said the logging was now working so that wouldn't make much sense.

 

Again, I can't be sure this is the problem without seeing exactly what you did. Can you attach all VIs and a sample log file?

 

Edit: I know what it is. You need a delimiter. You are writing all the numbers with no spaces so when you read the string back in you get 928756 instead of 9 2 8 7 5 6 separately. When you write to the file you need to make your text either space delimited, comma delimited etc. Then, when you read the file, use "spreadsheet string to array" and "fract/exp string to number" to convert the individual numbers to doubles.

0 Kudos
Message 4 of 11
(2,867 Views)

thank you

first, I corrected the issue by adding comma using this thread:

http://forums.ni.com/t5/LabVIEW/insert-space-character-between-every-character-in-a-string/td-p/1113...

 

however, it's not perfect, it logs string in one row but I like to log each string at different row

so I revised it by adding carriage return sign and it's successful, but there is no comma or space added. 😞

 

then, I try to read my string using the method in this thread:

http://forums.ni.com/t5/LabVIEW/Using-spreadsheet-function-to-convert-string-to-1d-array/td-p/104869...

 

it's successful.

 

Actually, my goal is to convert string text file to DBL 1-D array so that I can access the last last value. Is it still necessary to add comma after each string value?

 

If you think my attached VI is not smart enough, please let me know how to improve it.

 

Thank you :0

 

 

PS I should not say it's my VI because I borrowed previous poster's and all helper's help . thank you NI forum

0 Kudos
Message 5 of 11
(2,837 Views)

I think i got it, namely:

write each string followed a space and a carriage return sign

 

0 Kudos
Message 6 of 11
(2,825 Views)

You don't need the space. Just use the carriage return as your delimiter. When you read the file, use a carriage return as the dilimiter and wire up a 2D array constant to the spreadsheet string to array function. You will then get all your data in a multiple row, single column 2D array. Use index array and index column one to get a 1D array of your data.

0 Kudos
Message 7 of 11
(2,816 Views)

what does 2D array constant mean?

 

 

and since this problem is solved, I am going to add one more column of data. i mean each time the data in the input array is accessed, i want to log time also. it will be done like this

4/22/2013 10:00am   9

4/22/2013 11:00am   6

4/22/2013 12:00am   7

4/22/2013 13:00am  7

4/22/2013 14:00am   5

4/22/2013 15:00am   8

 

will there be a big modification to the write VI?

 

Thank you so much

0 Kudos
Message 8 of 11
(2,808 Views)

@ivy037 wrote:

what does 2D array constant mean?

 

will there be a big modification to the write VI?

 

Thank you so much


Nope, no big modifications...see if you can figure it out yourself 😉 And your'e right, you can also use "read from spreadsheet file" to do what you need to. 

0 Kudos
Message 9 of 11
(2,800 Views)

 OK, I succeeded , please see attachment

 

Now, the last challenge, since my talbe contain time and data, data is located in the 3rd column. I want to read the last value. I tried to add another read From Spreadsheet and set it to double, but failed.
 What's wrong with this?

 

 

0 Kudos
Message 10 of 11
(2,788 Views)