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 a binary file LabWindow

Solved!
Go to solution

 

I opened a file and specify the file format as binary using VAL_BINARY. Somehow I can not find a function that can be used to read.

           OpenFile( inputFile, VAL_READ_ONLY, VAL_OPEN_AS_IS , VAL_BINARY );

 

I tried to use read, it complaints C99 does not support this.

 

Well, all I want to do is read in a binary file byte by byte.

 

Thank you.

0 Kudos
Message 1 of 5
(2,285 Views)
Solution
Accepted by topic author qing22

ReadFile () is the function you need to use: you can pass a unsigned char variable to retrieve the file content and either read the file one byte at a time (highly inefficient) or read it in blocks and scan the output buffer to decode it (better).

 

These are general rules, there may be different ways to read a binary file, e.g. using a struct variable to automatically decode the file if you already know its structure.



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 5
(2,237 Views)

Use the standard ANSI C file input/output functions fopen, fread, and fclose.

 

http://www.cplusplus.com/reference/cstdio/fopen/

0 Kudos
Message 3 of 5
(2,224 Views)

Thank you. ReadFile works for me:

- the LabWindows complaints warning of using unsigned char* , instead of char*

- It seems like have to read byte by byte, instead of read a block.

 

0 Kudos
Message 4 of 5
(2,218 Views)

@qing22  ha scritto:

- It seems like have to read byte by byte, instead of read a block.

 

You're right about the type of the variable, sorry for that.

ReadFile (fileHandle, buffer, nBytes); should permit you to read nBytes out from the file.



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 5 of 5
(2,212 Views)