We are currently saving a certain file type as a BINBLOCK in VEE.
It is read out by writing a real32 BINBLOCK directly out to a text file.
My problem is that I need to parse this data in C# to an array. I need to know how the BINBLOCK file is constructed.
From what I gather, the first digit is an ascii "#" and the second digit is an ascii number (x) which is to read the next x ascii digits which correspond to a number in some format that I do not know, either what it represents or what format (int32...etc...).
The files are then read in by reading each 4 bytes ( corresponding to a float, since it is a real32 format) and converting them to a float.
Could anybody shed some light as to what is going on with the BINBLOCK format? Any information above and beyond what the VEE help file says will be appreciated.
It is read out by writing a real32 BINBLOCK directly out to a text file.
My problem is that I need to parse this data in C# to an array. I need to know how the BINBLOCK file is constructed.
From what I gather, the first digit is an ascii "#" and the second digit is an ascii number (x) which is to read the next x ascii digits which correspond to a number in some format that I do not know, either what it represents or what format (int32...etc...).
The files are then read in by reading each 4 bytes ( corresponding to a float, since it is a real32 format) and converting them to a float.
Could anybody shed some light as to what is going on with the BINBLOCK format? Any information above and beyond what the VEE help file says will be appreciated.
1. Strip off # character
2. Get length of ASCII string that represents the length of the data (1 character)
3. Read the size of the data block by reading back the number of ASCII characters obtained in step 2
4. Read back the data in chunks that corresponds to the data type in the file.
Note: be sure that you open the file for binary read. Using the BinaryReader class to read binary data from a file opened via a FileStream instance might be one way implement this.
public static float[] getBinaryList(string File_)
{
//Declares
List<float> toReturn = new List<float>();
if(File.Exists(File_)) //Check for file existence
{
BinaryReader binReader = //Open new BINARY READER
new BinaryReader(File.Open(File_, FileMode.Open));
try
{
//Strip Leading "#"
binReader.ReadChar();
//Read first digit to get size of rest
char[] sz = binReader.ReadChars(1);
string s = new string(sz);
int size = Int32.Parse(s);
//Read next digits to get size of string
char[] len = binReader.ReadChars(size);
s = new string(len);
int length = Int32.Parse(s)/4;
//Convert rest of file to a REAL32 number
//Using a FLOAT variable
for (int x = 0; x < length; x++)
{toReturn.Add(binReader.ReadSingle());}
}
catch(Exception ex) //Catch Any Thrown Exceptions
{Console.WriteLine(ex.ToString());}
finally //Close Stream
{binReader.Close();}
//Return array of float
return toReturn.ToArray();
}//End if File Exists
return null; //If error, return null
}//End Function
viPrintf(vi, ":MMEM:STOR:IMAG \"D:/Image01.bmp\"\n");
then, catch data by:
viPrintf(vi, "%s\n", ":MMEM:TRAN? \"D:/Image01.bmp\"");
in the manual, i know that ":MMEM:TRAN? <filename>" will return a binary data block, but i didn't know how to write viScanf argument?
i had read some example in VEE and VB, but i don't know how to deal with it in VC++
can anybody help me?
thank you!
Merry Christmas!
and, i have a try viScanf like this:
viPrintf(vi, "%s\n", ":MMEM:STOR:IMAG \"D:/Image01.bmp\"");
viPrintf(vi, "%s\n", ":MMEM:TRAN? \"D:/Image01.bmp\"");
unsigned char c;
// Read back '#'
viScanf(vi, "%c", &c);
// Read back size of data length
viScanf(vi, "%c", &c);
// Convert chat to int
int cnt = c-'0';
// Read back length of data
long num = 0;
for( int i = 0; i < cnt; i++)
{
viScanf(vi, "%c", &c);
int temp = c - '0';
num = num*10 + temp;
}
//Allocate data size based on length
unsigned char *ime = new unsigned char[num];
// Read back data
for(long i = 0; i < num; i++)
{
viScanf(vi, "%c", &c);
ime[i] = c;
}
// Save data to file
CFile im("ddot.bmp", CFile::modeCreate | CFile::modeReadWrite );
im.Write(ime, num);
im.Close();
it can work also, but very slowly. Is there any way to catch data in one time by viScanf?
if i read back trace data in real, i can write viScanf as: viScanf( vi, "%#zb", &rtncnt, floatArray ), how can i catch file( image, snp and so on) in this format( viScanf)? i mean that which modifier and format code i can use? the second argument is a float array pointer?
thank you & best wishes!
It just need to deal with array size, it also work very well that i change array type from ViPBuf to float. I think the key is modifier and format code which i didn't very understand
Thank you & Best wishes!