Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

How to save data from a serial port to a file with time stamps

HI

 

I try to modify the example "Basic serial write and read.vi" to have timestamp with the data string and save them to a file.

Could anyone help me to do that.  I am a beginner in LV.  Thanks

Message Edited by Hara on 05-08-2009 02:53 PM
0 Kudos
Message 1 of 6
(4,058 Views)

use the "Get Date/Time in seconds" and remeber the first measurements.

the subtract this value from either measurement and you have a relative time value in seconds with ms resolution

greetings from the Netherlands
0 Kudos
Message 2 of 6
(4,041 Views)

As mentioned you can use the Get Date/Time in Seconds VI to get the time, and use Write to Text File or Write to Spreadsheet File VI's (from the File I/O palette) to write this information to a file.

 

Regards,

 

---

Peter Flores
Applications Engineer
0 Kudos
Message 3 of 6
(4,014 Views)

Thanks a lot.

I add these 2 sub-VIs and it works.

However, numbers (measurands from the serial port) are sometimes unreadable

and sometimes there are 2 (or more than 2) numbers recorded at a certain time stamp.

 

Could anyone help me to figure the problems out?

 

Thanks a lot

 

Hara

 

 

Download All
0 Kudos
Message 4 of 6
(3,994 Views)

You've got at least one major problem. The example you used should never be used in a loop. What you want to do is place the VISA Configure Serial Port and the VISA Close outside the loop. You are reinitializing the serial port with every iteration. Also, the basic example is, well, pretty basic. The way you have it, you are writing to the file with every iteration - even if the byte count is 0. It would make more sense to place a case statement around the VISA Read and execute that if the count is greater than 0. You could also place all of the file write code inside the same case statement so you only write when you have data.

 

If the data from the instrument is a known and fixed byte count, you could also use that as a constant instead of reading available bytes.

0 Kudos
Message 5 of 6
(3,981 Views)

Thanks

 I have checked the instument and found that the byte count is not fixed.

How can I just record one at a time?

 

Thanks a lot!

 

Hara

0 Kudos
Message 6 of 6
(3,960 Views)