Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I read AI data with integer format not double?

It is my code.
 
In this code,
data = analogInReader.EndReadMultiSample(ar);
 
data is a 2-d double array but I would like to get data with integer format;
 
Surely, I can convert it using mathmatical equations.
I prefer doing it with NI functions.
 
Anyone who has a example code to get the data with integer?
 
Thank you.
 
Kind Regards
 
James Choi
 
 
-------------------------------------------------------------------------------------------------------------
 
private double[,] data;
 
//Create a virtual channel
myTask.AIChannels.CreateVoltageChannel(physicalChannelTextBox.Text, "aiChannel", AITerminalConfiguration.Differential,
                        Convert.ToDouble(minimumTextBox.Text), Convert.ToDouble(maximumTextBox.Text), AIVoltageUnits.Volts);
 
 
        private void AnalogInCallback(IAsyncResult ar)
        {
            try
            {
                if(taskRunning)
                {
                    //Read the available data from the channels
                    data = analogInReader.EndReadMultiSample(ar);
                    analogInReader.BeginReadMultiSample(Convert.ToInt32(samplesTextBox.Text), analogCallback, null);
                }
            }
        }
0 Kudos
Message 1 of 7
(5,070 Views)

Hi James,

If you go to the NI-DAQmx C Reference Help (Start > All Programs > National Instruments > NI-DAQ) you can go to the Index view and type in "daqmxread" to find all of the different ways that you can read your values.

Here are the possibilities for an Analog Input operation:
DAQmxReadAnalogF64
DAQmxReadAnalogScalarF64
DAQmxReadBinaryI16
DAQmxReadBinaryI32
DAQmxReadBinaryU16
DAQmxReadBinaryU32
DAQmxReadRaw

It sounds like you will want to use DAQmxReadBinaryI32 so that the data is returned as an integer value.  Keep in mind that this will return the data as unscaled data, so you will have to perform the scaling yourself. 

Chances are that you would simply be best off truncated the data that you are currently getting and/or formatting it into an integer on your own, because scaling by hand would probably end up taking more effort than it's really worth.

Regards,

0 Kudos
Message 2 of 7
(5,065 Views)
Thank you Otis.
 
I am trying to do my works with C#.
 
I can not use these functions in C#.
 
DAQmxReadAnalogF64,DAQmxReadAnalogScalarF64,DAQmxReadBinaryI16,DAQmxReadBinaryI32
DAQmxReadBinaryU16,DAQmxReadBinaryU32,DAQmxReadRaw
 
Is there any other method in C#?
 
Thank you.
 
Regards,
 
James Choi
0 Kudos
Message 3 of 7
(5,012 Views)
James,

One thing I found that based on your cards bit accuracy you can decide which data type to use.

Lets say your card is 16 bit card so the max value digital output will be 2^16 = 65536 and min would be 0

If you noticed this is also max range a "unsigned short" data type can represent which has 2 bytes.

So by using interger which is 4 bytes you are basically wasting 2 bytes of data ( I dont know how much pressed you are on memory).

I guess you can make "data" with unsigned short datatype instead of using NI's standard data types.

BTW NI's data types are present in NiScalarVector.h if you want to make use of their data types.

All NI's examples use CNiReal64Vector as its datatype for data read by card which I guess is a waste of space. Any comments?

THanks.


0 Kudos
Message 4 of 7
(5,004 Views)
Howdy James

The methods you are looking for are in the AnalogUnscaledReader class. You will need to do the data scaling yourself, you can find out more about this in the shipping documentation.

I hope this helps.

Message Edited by bilalD on 01-06-2006 09:22 AM

Bilal Durrani
NI
Message 5 of 7
(5,006 Views)

 Thank you Anirudha and bilalD.

The article of bilaID is more helpful to me.

I read the shipping documentation about AnlogUnscaledReader class.

The multichannel reader is also needed in my application, but I think I can not do multichannel read with just only AnalogUnscaledReader class.

Is it right?

If it is, How can I do that?

Thank you for many vetarans' kind help.

 

Regards,

James

0 Kudos
Message 6 of 7
(4,985 Views)
Begins an asynchronous read of one or more unscaled 16-bit integer samples from one or more AIChannel objects in a task.
 
 
Originally, it is possible to do multichannel read!
 
I should have read the documents more carefully.
 
Thank you for all kind comments.
 
Regards,
 
James
0 Kudos
Message 7 of 7
(4,981 Views)