LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

scan to convert hex to Single Precision floating point number

I have some lengthy LabWindows/CVI software that controls various bits of hardware but I am having difficulty with an array from a VNA. There are 3 data transfer modes, I was using the ASCII mode but want to speed things up and go to Single Precision or 32 bit binary data transfer. The binary array is attached as a text file. The array starts with a #3452, then the Single precision data. the 3 after the # signals that there are 3 more digits to follow and then these 3 digits flag how many bytes are in the array (not counting 0A at the end). I cannot get the scan line correct to strip off the #3452, and then read the floating point numbers in correctly. I have looked at the help and while I know I am on the right track, just don't get it right. Any help would be greatly appreciated.

Scan(BufferRd, "%s>#%i[w5]%f[b4]", dummy, BufferB)  is one attempt.

When I was using the ascii I used
Scan(BufferRd, "%s>#%i[w5]%s", dummy, BufferB)  which worked fine.
0 Kudos
Message 1 of 3
(4,074 Views)
Hi,

first of all, I think that when you specify %f[b4], you only want a float number. That's not what you want : a float array.
You should use a for loop using the number of bit info you've retrived first.

Another simple solution would be :

-Retrieve length information as you've already done  : Scan(BufferRd, "%s>#%i[w5], dummy);
- Then use SetFilePointer() function to indicate the beginning of the binary data
- Then use FileToArray() function to retrieve a float array (specifying the data type you want)

Hope it helps.


0 Kudos
Message 2 of 3
(4,057 Views)
The variable BufferRd is an array of char and BufferB is an array of float. I thought the one line would do the array, it did for the ascii version.
0 Kudos
Message 3 of 3
(4,028 Views)