07-14-2009 03:19 PM
im reading values from a device that puts out a string, but i need it to save that string in a text file or excel spreadsheet. i cannibalized some example vi but cant get it to work. another thing i need to work on is getting it to save every six readings. it doesnt matter if the program prompts the user every six readings, but im not sure how to do it. the data does not even have to be saved as a string... it is a string containing numbers, and all i care about are the numbers. im excited about labview but all this graphical programming is daunting and confusing... so any help will be appreciated!
thanks!
07-14-2009 03:20 PM
07-14-2009 03:41 PM
07-14-2009 06:39 PM
hello. thanks for replying! sorry, i did not make my post clear enough:
my temperature reader is connected to six thermometers, but only has one input channel. therefore i use a seperate circuit to switch between the six thermometers, taking one reading at a time.
i start the program, and press "read" to obtain readings from a temperature reader. the temperature reader displays temperature constantly, but since my application is in steady-state, i just care about getting one reading, ie temperature reading at the instant I press "read". that is why, for collecting data, i do not think need a loop.
when i write "c" i am sending a "clear" command to my temperature reader, so that i can take another reading. i do not remember the exact response at the moment, though i could post it tomorrow. i am not very familiar with daq and interfacing, but i found that this seems to work for my device; that is the only reason i write "c".
so, i would like to be able to do the following:
read one value from my instrument (which will be displayed as a string). store that value in an array or something (maybe i could have it so the user presses a button, which tells the program to store whatever string is displayed into the array). then use my external switching circuit to switch to another thermometer. write "c" to clear, and then read again. store that value in the array or whatever. repeat until i've cycled through all six thermometers. once i'm done, i want to be able to save the set of six readings as an excel file (text file is also acceptable).
my thought is that i was on the right track with the vi i posted, though i may be completely wrong. the program as of now prompts me to specify the filename and directory, but i cannot seem to get past that. this might be a problem with loop placement? i also am a bit stuck on how to get the program to store six readings in a file.
thank you!
07-14-2009 07:34 PM
Your problem with loop placement is that you don't have any kind of loop. Your program runs once.
In the current state, you need to have your buttons pressed, then press the run button, then it will pop up with a dialog box to pick a file, write it out, close the file and end. Then to get the next reading, you have to press the run button again. (Please don't tell me you are using the Run Continuously button.) At which time it will ask for the filename again.
Use a filepath control on the front panel. With that, you can select the file once. Wrap your Clear and Read sections in a while loop. You probably actually want both buttons to be Latched when Released rather than Switch when pressed, so that they only occur once for each button press. Put a small Wait statement in that loop so it doesn't run full speed.
Put your open file ahead of the while loop and the close file after the while loop.
I would recommend you learn more about LabVIEW from here. How to Learn LV
07-15-2009 12:16 PM
hello ravens fan. thanks for your reply!
in fact i was using the run continuously button (sorry!), which explains why i kept on getting prompted to select a file. i have played around with the loop quite a bit and have it somewhat working. following your suggestions, i was able to get it so that the program continuously reads from the temperature reader, and appends each reading to the same file. almost exactly what i want. i am in a hurry at the moment so i will not be able to collect my thoughts until later, but here are some issues i plan on tackling:
i just need it to record the reading the instant at which the user clicks the read button. currently, the program reads continuously every 50ms, and i'm not sure how to fix that.
i also need it to have a space in between readings in the text file, so that when i open it in excel it will be able to separate the data into cells. (is it possible at to have it just save to an excel file? i have not tried it yet but plan to.)
otherwise, it looks like things are falling iinto place. thanks for your help so far!
07-15-2009 12:17 PM
07-15-2009 12:47 PM
I added an Event Structure to your code so that you can easily handle the buttons on the front panel.
The "six readings" stuff arent clear to me. Do you trigger them manually or should they be taken at constant time interval?
Why do you write to a bin file? Since it's all text why don't you use the "Write to Text file" vi?
Now you write each measurement to the file, you could build your string with 6 readings and write them at once to the file. Don't need an array to do that, just concatenate the succecive results. There's still work to do regarding your string since it's not clear to me what you programmed in the first place 😞
07-15-2009 12:58 PM - edited 07-15-2009 01:02 PM
As I said, set your switches for Latch When Released action rather than Switch action. This way they only are read one time in the true position. They will automatically jump back to false until you press the button again.
There is a Write to Spreadsheet file function. Note, this does NOT make an Excel file. It creates a text file where data is separator with delimiters. And rows of data are separated by end of line characters. This works better for 2-D data. In your case, you are sending a value at a time. The question is what do you want the delimiter to be? (It looks like you have a space separating data now). Perhaps a comma or tab character. Depending on what separator you use, and how you open it in Excel or import it into Excel determines whether the data shows up in separate columns or all mammed into one column. At some point, do you want the data to stop going into one row and start a new row (essentially becoming 2-D). If so, you will need to determine how many points per row you want and how to determine when to start a new row.
EDIT: Alain, good catch on the binary file. I missed that. But when writing strings, as long as preprend array or string size is turn off (which it is), I don't think it matters.
07-15-2009 01:01 PM
I think I understand about the six readings based on the earlier post. Basically, he wants to take six readings at a time, but he needs to move a mechanical switch to go to the next sensor. When he moves the switch he wants to take the next reading. Once he's got six, that's the whole lot, and it should be written to file.
Given the on-demand reading requirement I was also going to suggest using an event structure, assuming that the user doesn't have LabVIEW Base, which doesn't have event structures. As far as the code with the event structure: