LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Add headings to writing file

I dont really know, I've just always used while loops so i figured i should use one 🙂

If I wanted to put a loop around the part that writes data to the file,
which loop would I use, and how?

Thanks,
Cory

Cory K
0 Kudos
Message 11 of 19
(992 Views)

I have attached my latest version of the said VI.

I have 3 "Write to Spreadsheet File" functions.

The first is to write any pertanent comments before any measurements are taken.
The second is to write all the column labels.
The third (theoretically) continually writes data as it is given from my attached instrument.

However, when I run the program, this goal is not achieved.

Do I need a loop around the third write function?
Or is there some error I made somewhere along the way?

- Cory

Cory K
0 Kudos
Message 12 of 19
(966 Views)

You don't understand the basics of a while loop I think. Your VI will write the comments, write the header, and do a single serial read. It will then stop. You have the status Boolean of the error cluster wired to the termination terminal of the while loop. The termination terminal is set to be Continue if True. The only way that the while loop will run more than once is if an error occurs. The status Boolean of the error cluster is false if NO error occurs. The only way you can get more than one acquisition is if you run the program from the start again or if you are using run continuous mode. DO NOT USE run continuous mode. Ever.

Change the termination terminal of the while loop to Stop if True and OR it with a front panel Stop button.

0 Kudos
Message 13 of 19
(961 Views)
"The status Boolean of the error cluster is false if NO error occurs. The only way you can get more than one acquisition is if you run the program from the start again or if you are using run continuous mode. DO NOT USE run continuous mode. Ever.

Change the termination terminal of the while loop to Stop if True and OR it with a front panel Stop button."

I think I need some combination of your idea with mine.
If I get rid of the while loop all together, the data only reads once.

If I change the termination terminal of the while loop to Stop if True,
the file is written correctly, but the data is displayed incorrectly.

If I leave the termination terminal as I had it,
the file is written incorrectly, but the data is displayed correctly.

I am now thoroughly confused, because the displaying and writing of the data is in the same part of my code.
How can one be working and not the other?

Cory K
0 Kudos
Message 14 of 19
(952 Views)
Define 'data is displayed incorrectly'. You are doing a read of 110 bytes and you are doing a read with no termination character. If the instrument is constantly sending out data, how are you synchronizing the data? It How do you know when a packet starts and when it starts?
0 Kudos
Message 15 of 19
(942 Views)
data is sent literally like this:
--> \r\n
# \r\n
date \r\n
# \r\n
# \r\n
# \r\n
 
then you know it starts again when you get another:
--> \r\n
 
I figured out that that happens every 110 bytes.
 
The reason I said no termination character, was because otherwise, it would only read one line, and then stop.
And each line is a different number of bytes, so I cant make it read one line at a time.
Cory K
0 Kudos
Message 16 of 19
(927 Views)
You can make it read more than one line at a time and if each line is terminated with a CR/LF, you don't need to know how many bytes are available.
 
Aside from that, you really haven't described how the data is not correct anymore nor how you are synchronizing it all. Since it sounds like it is always sending data, when you start your read of 110 bytes, how do you know that the first x number of bytes are for your first indicator, the next x number of bytes are for indicator 2, .etc. You could be starting the read at the beginning, middle, or end of each transmission. Frankly, just looking at the code, I don't see how you ever get consistent results.
0 Kudos
Message 17 of 19
(913 Views)

Well, I set the device so it will send data on an interval, which I set to 1 second.
I could put the read, and write to file in a timed loop, that iterates once per second,
but I'm worried the program and the device wont syncronize and I will miss some data maybe.

You said "how do you know that the first x number of bytes are for your first indicator, the next x number of bytes are for indicator 2, .etc"
I don't know how many bytes each piece of data is, however, I do know what line to expect it.

That is why I have a dozen or so of the "Index String Array" functions.
I just know where in the array each data SHOULD be....

No one ever taught me LabVIEW, I kind of taught myself.
This is also only my third month of using LabVIEW.
So if my methods are unorthodox, that is probably why.

I'm doing the best I can though.

Cory K
0 Kudos
Message 18 of 19
(900 Views)
I just came across the "Timed Sequence" structure.
That may be a possibility.
 
I was using a shift register on my While Loop,
to clear out each line as I read it.

Is there an equivelent to a shift register in a Timed Sequence structure?
Cory K
0 Kudos
Message 19 of 19
(892 Views)