LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

read a structure written in VC

I have written a structure in VC and saved to a file, I want to read the file in LV8.0 but I cann't get the right result, the structure is  below:
struct Save_Data {
  int  A1;
  int  A2; 
  double A3; 
  double A4;
  double A5;
  double A6;
  double A7;
  int  A8;
  int  A9;    
  double A10;    
  int  A11;
  int  A12;   
  double A13;     
  bool A14;
  bool A15;
  bool A16;
  double A17;
  double A18;
  double A19;
  double A20;
  double A21;
  char A22[6];
  char A23[6];
  char A24[6];
 }SaveData;
 
In the VC6.0 I found the structure saved in the file are bigger than the size of the structure described in VC, I don't know why.
I write a vi to read the file, but I cann't get the the three char array, The vi and file ared attached.
Download All
0 Kudos
Message 1 of 2
(2,468 Views)

In C, a string is an array of chars ended by a null char. In LV, it's represented differently. Normally, to get a string from an external function you would either configure the CLF node to return a null-terminated string or you would preinitialize a U8 array of the appropriate size and pass that to the function as an input. LV allocates the memory properly and fills your array and then you can use the Byte Array to String function to get your string.

I'm not sure how such a method would work on a file, but I would try to make the last three elements of the cluster 1D U8 arrays of the appropriate size and see if that works. I didn't see any null characters in the file, but it might work. Another option is to simply read the file and convert it yourself. Yet a third option would probably be to save the structure as plain ASCII and not as a C struct.


___________________
Try to take over the world!
0 Kudos
Message 2 of 2
(2,453 Views)