LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

covert from double to I16

 HI,

 

I am using LabWindows CVI 9.0 version and USB-6009 DAQ device.

 

I am able to acquire the analog voltage from USB-6009 board and read them in float64 values. I store thse acquired data in TDMS file. As it is known, storing the double values takes 8 Bytes each value increases the file size. Instead, I want to read the acquired values in Banary I16 format and store them in TDMS file to reduce the file size by 4 times.

 

I searched the examples and found an example to convert the I16 Binary values to float64 values using the coefficients of the DAQ device. NOw, I want the otherway round that to convert the float64 value to I16 Binary value. Is there any function in LabWindows CVI 9.0 to do that?

 

Any inputs are higly appreciated.

 

Regards,

Shanmukha

 

 

0 Kudos
Message 1 of 4
(3,272 Views)

You can approach this problem in two moments: if you need to acquire in doubles because you want to perform some data processing on engineering values during acquisition, you can use round () function to rount your daoubles to nearest integer values, copy them to an integer array and then save this to the file. This way you are doubling the conversion work: the first time from integer to double inside DAQmx driver, the second time from double to integer in your program.

Alternatively, DAQmx can return values directly as integers if you use DAQmxReadBinary function; if you need to obtain some value in engineering units (e.g. to display some data point on the screen during the acquisition process) you need to operate the appropriate conversions on the integer values.



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 2 of 4
(3,266 Views)

Hi,

 

I agree reading binary using DAQmxReadBinaryI16( ) gives me the integer value of the data and using DAQmxReadAnalogF64( ) gives the direct engineering (Voltage) value of the data.

 

You Wrote

Alternatively, DAQmx can return values directly as integers if you use DAQmxReadBinary function; if you need to obtain some value in engineering units (e.g. to display some data point on the screen during the acquisition process) you need to operate the appropriate conversions on the integer values.

 

This is partially what I need. I understand conversion from bainary integer values to engineering double values using the coefficients of the DAQ device etc.

 

Let me explain my problem in detail.

 

For example, I graph the acquired values on a strip chart after down sampling the data. On the same strip chart, I have to draw another trace, which indicates certain threshold like 50% of the y-axis for example. The user will specify this threshold from a dialog box in Engineering units. This value will be stored in TDMS file as an attribute. As I am planning to store the data in TDMS file in Binary Integer format, I need to convert this engineering values (Voltage) to equivalent binary integer (I16).

 

I know, TDMS library can directly log the values in Binary format with scaling information, but as I will do some processing like downsampling the data, I can't use DAQmxConfigureLogging function, which directly logs to the file.

 

To simply put, How to convert engineering (Voltage) values to equivalent Binary I16 for the DAQ device being used?

 

Thanks for your response

 

Regards,

Shanmukha

0 Kudos
Message 3 of 4
(3,261 Views)

That is: you want to retrieve data in DAQmx in engineering units and them save then in binary together with appropriate scaling factor.

 

Since your goal is simply to save disk space there is no need to retrieve actual scaling type for every channel; instead you can:

 

  1. Scale data with QScale1D: this gives you an array of doubles in the range 0÷1 together with a scaling factor
  2. Use Mul1D to multiply by 2^16 = 65535
  3. Transform the array to short integers with ConvertArrayType and save to TDMS together with the scaling factor obtained in step 1

 This will introduce some errors due to calculations and scaling. That is: data retrieved from TDMS file and recalculated to engineering units can be somewhat different from original data.

 

If you want to have the same exact value from both initial processing and further retrieval, your only option in my opinion is to read data in binary and apply the same exact processing in both cases.



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 4 of 4
(3,256 Views)