LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

serial read to file

I am attempting to write to a serial device, read the data, and then write the data to a file.  I have successfully sent the commands in hex and received the data displayed in hex in the front panel, but the data is not being written to a file.  I would like to keep the data in hex format so that I can read specific bytes, but its not that important.  Could someone lookat my vi and see what I'm doing wrong.
0 Kudos
Message 1 of 11
(4,424 Views)
Nothing is being written to a file because there is nothing read. You've already gotten the bytes from the serial port with your first VISA Read. That clears the buffer. If you want to save the data, take the string from the VISA Read and use one of the file write functions.
0 Kudos
Message 2 of 11
(4,420 Views)
Your VI has no capability to write to file. The VISA Read to File does nothing other than perhaps tell us that you are a Republican.
 
Experiement with Write Text To File after the serial read.
 
 
Richard






0 Kudos
Message 3 of 11
(4,417 Views)
You beat me by three minutes Dennis! Smiley Happy
Richard






0 Kudos
Message 4 of 11
(4,415 Views)
The vi that you are using to write to a file is actually reading directly from the serial port. Beings you read the port just prior to that, there is nothing there to read. If you want to save the information and display it, I suggest opening a file using the file vi's then using the write binary file vi to save your data. Be sure to close the file when you are done.
 
I have edited what you submitted to show you what I mean. There are some notes in there to help if you have never used the file vi's.
 
Hope this helps..
CyberTazer
Software Systems Engineer
0 Kudos
Message 5 of 11
(4,412 Views)

cybertazer,

Thanks, the vi collects data now, but the data doesn't make any sense to me.  If I open the attached file in notepad I get some characters that I do not recognize, whereas I thought it would just be ones and zeros.  Is there a way to read this file with another program so I can make sense of it?

0 Kudos
Message 6 of 11
(4,368 Views)

Since you are getting hexadecimal numbers, that is what is being saved to the file.  What you are seeing is the ASCII character for the stored Hex number.  Many ASCII characters are unprintable or are crazy looking characters.

You'll have to determine how you want to save the data and what kinds of programs are going to open the file to read the data.  Is it going to be another LV program?

You can use the hexadecimal string to byte array function to convert the string characters to their U8 value.  If you want to store the values with commas in between, you can use the array to spreadsheet string or Write spreadsheet file with the appropriate format specifier to put the data out to a text file so that the numbers are human readable.



Message Edited by Ravens Fan on 04-07-2008 04:53 PM
0 Kudos
Message 7 of 11
(4,359 Views)
Notepad does not have the ability to display hex or binary. It's trying to interpret the data as ASCII characters. I'm sure there are a large number of hex editors available if you would google that. You could also just write a LabVIEW program to read the file and display the data. If you use Read From Text File, create a string indicator and then right click on it and select 'Hex Display'.
0 Kudos
Message 8 of 11
(4,357 Views)

I use a program called Hexedit, which I think I got from www.download.com. If you need the actual hex characters in your file, after the string to U8 conversion, put a Number to Hexidecimal String conversion. Then change the Write Binary File to Write Text File.

One note on this... Doing it this way is a true representation of what came from the serial port... BUT it is not an exact representation. If you need to use this for any large amount of data, it will greatly slow down your program because it has to change from text to its native, binary form. If you are doing this just so you can see that everything is working ok, I suggest writing it as you do now... and ALSO writing it as I stated above as a text file. This way you can see in plain text exactly what is being written out. Use the binary file for your actual data manipulation. Then, when you are done testing, or you ramp up your code for higher speed, comment out the text portion.

 

Good luck...

CyberTazer
Software Systems Engineer
0 Kudos
Message 9 of 11
(4,338 Views)
I want to save the data for later analysis by another program such as MATLAB.  I'm not familiar with how Labview creates reports or how useful it is for data analysis, so I'll probably use MATLAB.  I don't need to be able to check the data, but rather store a minute or so of data from a pulse-ox for graphical display.  Would the technique you(cybertazer) described work in this way?
0 Kudos
Message 10 of 11
(4,321 Views)