From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read data from file to array in Labwindows/CVI

Hello,

 

I have some Hex datas( starting from 0x63C, 0x199, 0x21F, 0x19F etc) with space in between, and want to import these datas into the array( int Data[512] ) I created.

I was using

FileToArray (LoadFilePath, Data, VAL_SHORT_INTEGER, 512, 1, VAL_GROUPS_TOGETHER, VAL_GROUPS_AS_COLUMNS, VAL_BINARY);

But the data I am getting in Data[] is Data[0] = 0x3336, Data[1] = 0x2C43, Data[2] = 0x0A0D, Data[3] = 0x3931.

Is it because I didn't use the Function in the right way?

 

 

Thanks,

 

 

0 Kudos
Message 1 of 4
(5,143 Views)

It seems to me that your data is not stored in binary format but as a string with comma+CR+LF separators instead. You may have looked at the data with an editor that renders CRLF with a space, and possibly adds 0x' characters which are not present in output data.

 

The value resulting from FileToArray function are the result of this organization:

36: hex code for character '6'

33: the same for '3'

43: the same for 'C'

2C: hex code for comma

0D0A: CRLF separator

39: character '9'

31: character '1'

 

A binary file would not have separators inside: numbers are simply stored consecutively each occupying the exact number of bytes given from variable type (2 bytes for shorts, 4 bytes for 32bit integers...)

 

If my assumption is correct, FileToArray is not the best option to read data back: sscanf () or Scan () appear a better solution.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 4
(5,130 Views)

How read data file excel and show result in table under labwindows??????

 

0 Kudos
Message 3 of 4
(4,907 Views)

Duplicated post: see here



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 4
(4,893 Views)