11-29-2008 08:45 AM - edited 11-29-2008 08:51 AM
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.
12-05-2008 07:56 AM - edited 12-05-2008 07:56 AM