Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting doubles to raw sample values

Hi,
 
I'm writing a lot of acquired data to file, and am currently doing so by writing each 8-byte double sample to a binary file.  But since my card (PCI-6259) only has a 16-bit precision, I'd like to only write the raw 2-byte short version of the sample to save space.  However, I can't find anyway to get that information (the raw sample) from AnalogMultiChannelReader.  I've tried dividing each double value by the channel's range (e.g., 4 volts) over the precision---more precisely, Value / (Range / (2^16-1))---but this doesn't yield integer values (like it should!).
 
I'm a big fan of the asynchronous reading functionality provided by AnalogMultiChannelReader, and would like to keep that.  But I'd also like to reduce my file sizes from 8 GB to 2 GB, if possible.
 
Any ideas?
0 Kudos
Message 1 of 4
(4,249 Views)
Hi,

Thank you for brinign this issue to the NI discussion forumns.  You mention the AnalogMultiChannelReader, and write it as a function.  I am not familiear with that function, but have used the NI-DAQmx driver to write the raw versions of data before.  In your case with a 16 bit precision card I would look at using the NI-DAQmx ReadBinary I16.

This information is available in the NI-DAQmx C reference help, but here is the function call and a description of its uses.

int32 DAQmxReadBinaryI16 (TaskHandle taskHandle, int32 numSampsPerChan, float64 timeout, bool32 fillMode, int16 readArray[], uInt32 arraySizeInSamps, int32 *sampsPerChanRead, bool32 *reserved);

Reads multiple unscaled, signed 16-bit integer samples from a task that contains one or more analog input channels.

Using this function will give you the behavior you want, but let me know if you are still having trouble with this in any way.

Have a great day,

Michael D
Applications Engineering
National Instruments





























0 Kudos
Message 2 of 4
(4,229 Views)

Hi jrolston,

Since you are using .NET with NI-DAQmx, then you want to definitely stick to the .NET classes and not mess with the C API.

I'm not too sure of what exactly might be the best method for you but I will provide you with both options. The NI-DAQmx API provides both "raw" and "unscaled" analog read functions. 

Unscaled read returns data in the native format of the device, read directly from the device or buffer without any scaling. In .NET, if this is what you were wanting, then you would need to use the
AnalogUnscaledReader class instead of the AnalogMultiChannelReader class.   Check out this forum post as well.

Raw reads return data in both the native format and organization of the device, read directly from the device or buffer without either scaling or reorder. In .NET, if you want to perform raw I/O, you need to call the raw I/O methods on the DaqStream class directly rather than using a reader or writer class.

Refer to the Reading and Writing with the NI-DAQmx .NET Library help topic in the NI-DAQmx .NET Documentation (Start >> All Programs >> National Instruments >> NI-DAQ >> NI-DAQmx .NET Framework 2.0 Help; Then navigate to NI Measurement Studio >> NI Measurement Studio .NET Class Library >> Using the Measurement Studio .NET Class Libraries >> Using the Measurement Studio DAQmx .NET Library)

Best Regards,

Jonathan N.
National Instruments
0 Kudos
Message 3 of 4
(4,213 Views)

Hi and thanks for the responses.  I stumbled across AnalogUnscaledReader and started using that.  I also found this post, which talks about how to convert these raw values to scaled voltages (turns out it's not, like I though, a linear encoding).  That post discusses LabView, but in C# you call the DeviceScalingCoefficients property of an AIChannel, which returns (with a PCI-6259) a 4-element array of doubles, one for each scaling coefficient.  I also noted that these vary greatly between cards (I have four PCI-6259s, all with different coefficients).  I guess the coefficients are changed during calibration of the card.

In any case, writing the 16-bit values to disk (vs. the 64-bit double values) saves a lot of time and space.

0 Kudos
Message 4 of 4
(4,207 Views)