06-20-2011 05:45 PM
hello everyone,
can anyone please tell me how to save COM port data to file? I am transferring 1 byte from serial port... attached is the image of the vi... very basic.
I would like to save the data in a tabular format... i mean, 1st data --> tab 2nd data--> tab 3rd data --> tab
and so on... can anyone help?
Solved! Go to Solution.
06-20-2011 08:29 PM
Basically what you are doing now, except you aren't reading one byte at a time, but however many bytes happen to be at the serial port. Just read one byte at a time and concatenate a tab character to it then send it to the File Write.
06-20-2011 08:44 PM
First you must create a reference for your file by using the open/create/replace function in the files palette before you can write data to it. Next, why so high a baud rate on your Com port. Will your Com port handle that speed? Just curious. I haven't seen any that will go beyond 115K unless you use a USB converter. You might get 230K out of it in that case, but not reliably. Double check your settings.
Your usage of file functions is completely off. You are trying to write the report headers to a text file, which is fine, but then you are writing the data to a binary file, using the same reference no less. Pick one or the other. Do you want to be able to view the file with an editor of some sort? If yes, use a text file, but don't mix and match. Text files are OK for data collection and raw data, but you may want to use ms excel for generating proper reports if this is your aim. Refer to the Report Generation Toolkit (I don't know if LV 8.0 has these features or not. I doubt it).
As far as the organization of your data, that will depend on the format of the data coming from the Com port.
06-20-2011 08:52 PM
MoReese,
Writing to a binary file with string data is the same thing as writing to a text file with string data. Try it.
06-20-2011 09:50 PM
Raven's Fan, I shall definately try out that... Another thing, I would like to pass on system time to the microcontroller unit .. i tried using Get Time/Date String.vi; sent data to uC and
received data back to the LABVIEW vi, and I observed that the uC does pass the date time string correctly...
but, i cannot understand how to save the data on the uC. Do I have to give a time format string (%c) in the Get Time/Date String.vi and check the same in uC code/??
@MoReese, yes i am using a UART-USB converter, hence data transfer at such a high speed.
06-20-2011 09:53 PM
I don't understand your question. What does saving a date/time on a microcontroller have to do with saving data to a file using LabVIEW?
06-20-2011 10:00 PM
I know, saving to file has nothing to do with date time string transfer...
Its a new question, just wanted to ask..
06-21-2011 02:28 AM
Have you created a program on the µC, like in assembler or C, that can handle the rs-232 data transfer? If you have, then it's just a matter of writing to serialport instead of reading from serial port in LabVIEW.
06-21-2011 07:27 AM
Ravens Fan,
"Writing to a binary file with string data is the same thing as writing to a text file with string data. Try it."
I did try it and it works as you say; with the exception of a control character added to the binary string, it's readable. I have little experience with binary files in LabView and did not realize it excepts variant data. Thanks for the lesson.
06-21-2011 08:28 AM
There is an input at the top called "Prepend array or string size" which by default is true. If you wire a false constant to that like in CrackJack's image, you won't get those extra characters.