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.
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.
12-23-2020 03:37 PM
In the attached ZIP file is the .DAT file "C105_105PFC_R00001_T001_20181126_131205.DAT" containing FLOAT as well as CHAR data that I try to read via LabVIEW 2018 SP1 "TDACS_TDMS_File_Viewer_for_reading_FLOAT_DAT_file.vi" and "TDACS_TDMS_File_Viewer_for_reading_CHAR_DAT_file.vi", respectively.
However, I am able to read FLOAT data only, getting an error on CHAR data. LabVIEW VI's are coded based on the following C++ programming:
FILE *stream_1hz;
int nCharsread_1hz;
int iBuffersize1hz;
char cFilename[255];
int iNum1hzchannels;
int MAX_1HZ_CHANS
MAX_1HZ_CHANS = 2;
iNum1hzchannels = 2;
stream_1hz = fopen("C105_105PFC_R00001_T001_20181126_131205.txt", "rb");
union UNKNOWN1
{
float rdata[MAX_1HZ_CHANS];
char cdata[MAX_1HZ_CHANS * 4];
} u1hz;
iBuffersize1hz = 4 * iNum1hzchannels;
nCharsread_1hz = fread(u1hz.cdata,1,iBuffersize1hz,stream_1hz)
fclose(stream_1hz)
Solved! Go to Solution.
12-23-2020 11:22 PM - edited 12-23-2020 11:36 PM
cha,
The reference C/C++ you included seems to imply that the file is simply a serialized array of single-precision floats. I think you may be confused by the UNION in the example code. It only means that the array of floats is mapped to the same memory as the character data for the convenience of calling fread()/frwrite() with the address of the char array. My C is rusty enough that I can't really even tell you if that's considered a good coding practice.
But as far as reading the example .dat file in LabVIEW, you should realize that you're not reading anything that has significance as character data - it's not a human-readable string, it's just an array of floating-point numeric. I've declined to comment on your attached VIs (apart from noting that the sequence structures are superfluous), but a very simple routine is attached here as a VI snippet. Hope this helps.
Dave
12-24-2020 08:17 AM
Thanks, Dave, for pointing out the binary .DAT file containing only numerical data.
I am even rustier in C/C++ than you. The C/C++ code was written in the 80's by someone who is now deceased! Each numerical data is associated with a channel name. I have to re-examine the code to see where the channel names arranged in alphabetical order are loaded.
For the binary .DAT file, your snippet shows there are 4 data channels (sgl values) sampled at 0 and 1 Hz. The 4 channel names are among E00005, E00006, E00007, ..., E00012 (see attached screenshot). I have to find out which ones?
Regards,
Mr. Chi Ha
12-27-2020 11:59 AM
Chi Ha,
I only saw the one sample .DAT file (you provided in the zip archive) which I assumed only contains floating point numbers. Is there a different file format which encodes textual data? If so, provide it here and perhaps I can help you properly read its content too.
Best regards,
Dave
12-28-2020 09:04 AM
Thanks Dave,
All binary .DAT files I believe contain numerical data. Since I am very rusty with C/C++, I'm not sure how the channel names in alphabetical order are loaded in. If you are willing, I will provide the C/C++ code.
Chi
12-28-2020 09:53 AM
I don't think I can provide you with additional help, based on the sample file you provided - it was just 32 bytes in total length, and pretty clearly had no textual content - only (I assumed) a few single-precision floats, corresponding to your C code posted. Your channel names and descriptors - like sample rates, etc - are someplace else in this system. You'll need to find them.
Best of luck! Based on your posted LabVIEW code, I really suggest you spend more time with the tutorials, both provided in the development environment, and available online. When you get stuck, ask specific questions on this forum, and show what LV code you've tried, it really makes it easier for others to offer assistance.
Dave