Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Asynchronously Writing Digital ports

I am using PCI-6221 and DAQmx 8.7.2 and C# for programming

 

I want to write digital ports first, and after it completes, it will get a single sample analog input.

 

Here is my program. 

 

Can anyone point out the problem ? Because I used step-by-step debug, the AnalogSingleSampleRead() is not executed.

 

/////////////////////////////////////////////////////////////////// 

namespace NItest

{

 

public partial class Form1 : Form

{

//global variables

private double data;

private Task digitalWriteTask = new Task();

private Task AnalogTask = new Task(); private DigitalMultiChannelWriter ThreePortsWriter;

private AnalogSingleChannelReader myAnalogReader;

byte[,] DOutputss = new byte[3, 8];

 

public Form1()

{

   InitializeComponent();

   initNI();

}

   

private void initNI()

{

digitalWriteTask.DOChannels.CreateChannel(Port0, "", ChannelLineGrouping.OneChannelForAllLines);  

digitalWriteTask.DOChannels.CreateChannel(Port1,
"", ChannelLineGrouping.OneChannelForAllLines);

digitalWriteTask.DOChannels.CreateChannel(Port2, "", ChannelLineGrouping.OneChannelForAllLines);  

digitalWriteTask.Control(TaskAction.Verify);  

ThreePortsWriter = new DigitalMultiChannelWriter(digitalWriteTask.Stream);

digitalWriteTask.Start();

 

AnalogTask.AIChannels.CreateVoltageChannel("Dev1/ai0", "", AITerminalConfiguration.Rse, 0, 5, AIVoltageUnits.Volts);

AnalogTask.Control(TaskAction.Verify);   

myAnalogReader =
new AnalogSingleChannelReader(AnalogTask.Stream);

AnalogTask.Start();

ThreePortsWriter.SynchronizeCallbacks =
true;

}//end of iniNI

 

 private void DAQmxAsyncWrite()

{

   //[give some value to DOutputss]

 

   IAsyncResult handle=ThreePortsWriter.BeginWriteMultiSamplePort(false, DOutputss, new AsyncCallback(myCallback), null);

}

 

private void myCallback(IAsyncResult ar)

{

    ThreePortsWriter.EndWrite(ar);

    data = myAnalogReader.ReadSingleSample();

}

 

}

}

//////////////////////////////////////////////////////////////////// 

 

When I call DAQmxAsyncWrite(), the program never execute myCallback().

 

Why please?

 

Thank you all.

 

 

Message Edited by timinmanchester on 11-29-2008 08:48 AM
Message Edited by timinmanchester on 11-29-2008 08:49 AM
Message Edited by timinmanchester on 11-29-2008 08:51 AM
0 Kudos
Message 1 of 2
(6,280 Views)
duplicate post
Message Edited by Hillman on 12-05-2008 01:56 PM
Kind Regards
James Hillman
Applications Engineer 2008 to 2009 National Instruments UK & Ireland
Loughborough University UK - 2006 to 2011
Remember Kudos those who help! 😉
0 Kudos
Message 2 of 2
(6,231 Views)