how to use measurement studio to interface usb port

189 Views Asked by At

Can i use Measurement studio C# in visual studio to take a digital signal from a usb port (from a data aquisation system) and plot it and how can i do that??. I only tried to use it to plot a noise signal but i couldn't use it to take signal from a port.

         // Declare and initialize an instance of WhiteNoiseSignal.
        WhiteNoiseSignal whiteNoise = new WhiteNoiseSignal();
        // Store the generated data in a double array named data.
        double[] data = whiteNoise.Generate(1000.0, 256);
        // Use the PlotY method to plot the data.
        plot.PlotY(data);

this is the code I use.

1

There are 1 best solutions below

0
On

Liza, Depending on what device you have you need to configure a digital or analog input channel. You then create a task to monitor the ports you are interested in, and wait for this to callback when acquisition has finished. Something like this:

public void CreateAnalogInputTask()
{
try
{
    // create a new task
    myAITask = new Task();

    // create a new virtual channel
    myAITask.AIChannels.CreateVoltageChannel("Dev1/ai0, "", AITerminalConfiguration.Differential, -10, 10, AIVoltageUnits.Volts);

    // configure the timing
    myAITask.Timing.ConfigureSampleClock("",
        AISampleRate,
        SampleClockActiveEdge.Rising,
        SampleQuantityMode.ContinuousSamples,
        numberOfAISamples);
    myAITask.Stream.Buffer.InputBufferSize = 10000000;

    // verify the task
    myAITask.Control(TaskAction.Verify);

    // create the analogReader object
    analogInReader = new AnalogMultiChannelReader(myAITask.Stream);
    analogInReader.SynchronizeCallbacks = false;
    arAnalogInReader = analogInReader.BeginReadWaveform(numberOfAISamples, AnalogInputRead, myAITask);
}
catch (Exception ex)
{
    log.Error("", ex);

    if (myAITask != null)
        myAITask.Dispose();
}
}

And then read the data when this callback is invoked:

public void AnalogInputRead(IAsyncResult ar)
{

    try
    {
        try
        {
            myAIdata = analogInReader.EndReadWaveform(ar);
        }
        catch (DaqException ex)
        {
            if (ex.Error != 88710)
                throw;
            else
                log.Debug("DaqException 88710 ignored", ex);
        }

        for (int i = 0; i < numberOfAISamples; i++)
        {           
            myData[i] = myAIdata[0].Samples[i].Value;
        }
    }
    catch (Exception ex)
    {
        log.Error("", ex);
    }
}