Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert SGL to ASCII

Hello,
 
I am using a VISA control to read data out of the buffer on our picoammeter through a GPIB-USB2 cable. This works very well when the data is sent from the picoammeter in ASCII characters. However, this limits the data rate, so we would like to send the data in binary to achieve faster rates.
 
The picoammeter can record the data in the buffer as IEEE-754 single-precision floating point binary. However, when I record the buffer string from the output of the VISA Read VI in LabView, the data is interpreted as ASCII characters.
 
From what I have read on the message boards, I could probably use the Read from SGL File VI to get at the data, but I haven't been able to find it in the version 8.2 palette or in the help.
 
I have tried opening the data in Excel and using the CODE command to interpret the numbers, however this does not seem to work well, perhaps because I am not parsing the data in the right way.
 
I have also tried writing the data to a binary file using the Write to Binary File VI and then reading it back with the Read from Binary File VI, but I have not gotten this work. I get an error message of "Error 4. LabView: End of File Reached."
 
Any suggestions would be much appreciated.
 
Thanks!
Michelle
0 Kudos
Message 1 of 28
(5,008 Views)

I'm not sure I understand why you want you use all of these different file i/o functions. If you just want to convert a string to SGL, then the type cast should be all that you need. Be sure to use a SGL constant datatype as the value that you wire into the type input.

Message Edited by Dennis Knutson on 11-20-2006 12:43 PM

0 Kudos
Message 2 of 28
(4,986 Views)

Hi --

I found the type cast function, but I still am not sure how to go about recording the SGL output in a form that I can manipulate in Excel or Origin. I'd like to save the data out as a text file or in a spreadsheet which is why I had tried various File I/O VIs.

Thanks,

Michelle

0 Kudos
Message 3 of 28
(4,974 Views)
After doing the type cast, then convert it to a string. There is the built-in Write to Spreadsheet File that will do it for you. There are other file i/o functions such as Write to Measurement File. You could also format it yourself and just use Write File.
0 Kudos
Message 4 of 28
(4,970 Views)

Thanks for your patience. I think I am very close to getting this to work, but now it is only recording the first data point. I wired the output of the type cast VI to the Write to Spreadsheet VI through the Build Array VI. It records the output to the specified file, but only the very first value.

Michelle

0 Kudos
Message 5 of 28
(4,967 Views)

Well, you are wiring only a single value into the build array function. In order to write more than one value, you will have to acquire more than one before you write it. Or, everytime you run your VI, you append new data to the existing file. If you have your instrument i/o inside of a while loop, you can wire the SGL to the edge of the loop, right click on the exit tunnel and select Enable Indexing. then your Write to Spreadsheet would be outside the loop and you would do a single save.

0 Kudos
Message 6 of 28
(4,966 Views)

Thank you for that suggestion, it worked very well. However, for some reason, the VI is now recording the number zero over and over, instead of the data. Recording the data in ASCII format (example attached) still works, so I think things are ok on the picoammeter side.

There is a 2 byte header (#0) in front of each reading, perhaps this is causing problems with the conversion to SGL?

I've attached a copy of the current version of the VI, in case that might shed light on things.

Michelle

Download All
0 Kudos
Message 7 of 28
(4,963 Views)

I don't have 8.2 so I can't view the VI. Can you post an image of the diagram? Post it as a png or jpg please.

And yes, the header could be a problem. If you know the length is always 2 bytes, you could simply use String Subset to get the remainder. I suggest you create a numerical indicator on the front panel to check the conversion to SgL before you save to file. It will just make it easier to debug.

0 Kudos
Message 8 of 28
(4,961 Views)

Hi,

Attached is a PNG image of the block diagram so far. I've added an indicator to the front panel so that I can see the SGL conversion as it is done. I've also tried to cut out the two byte header before each data value using the String Subset function, but I am still not getting reasonable data. It reads out about 9x10^-10 A for the data when the picoammeter is reading 5 microA. Am I wrong in thinking that setting the offset to 2 should remove the first two characters? (The header is #0 in ASCII characters).

Currently the program is set to read out the current value and the timestamp from the picoammeter. I thought that might be a problem, so I tried just retrieving the current value, but I got the same incorrect data values after the SGL conversion.

Michelle

0 Kudos
Message 9 of 28
(4,946 Views)
Can you post an example with the raw string from the Visa read, and what the value is supposed to be?  I think that the type cast is causing your problems.  It can be a dangerous thing to use when looking at numbers.
0 Kudos
Message 10 of 28
(4,940 Views)