11-19-2017 06:25 AM
Hello,
I use the example for measurement studion "ReadDigChan_ChangeDetection", If I add a simulation device of PCI-6515 in MAX, it works and when I start the program, I can ready the value of each line. But when it works in a real PCI6515, it will not show any signal of the board and give me an error like timeout.
My question is. even the signal is not always changing as the simulation, but why it doesn't show the first time value? and when the first time value I can see, how can I keep monitor the signal? Put the time out=-1? I tried it, looks the program no response.
if I run single reading, It works ok.
I don't want to use timer to read value.
I use visual studio 2010 and Measurement studio 2015, Max 2014.
Thanks in advance
private void startButton_Click(object sender, System.EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
try
{
//Create a task such that it will be disposed after
//we are done using it.
myTask = new Task();
//Create channel
myTask.DIChannels.CreateChannel(physicalChannelComboBox.Text,"myChannel",
ChannelLineGrouping.OneChannelForAllLines);
myTask.Timing.ConfigureChangeDetection(
risingEdgeLinesComboBox.Text,
fallingEdgeLinesComboBox.Text,
SampleQuantityMode.ContinuousSamples, 1000);
myDigitalReader= new DigitalSingleChannelReader(myTask.Stream);
// Use SynchronizeCallbacks to specify that the object
// marshals callbacks across threads appropriately.
myDigitalReader.SynchronizeCallbacks = true;
runningTask = myTask;
myDigitalReader.BeginReadSingleSampleMultiLine(
new AsyncCallback(OnDataReady),
myTask);
startButton.Enabled = false;
stopButton.Enabled = true;
physicalChannelComboBox.Enabled = false;
risingEdgeLinesComboBox.Enabled = false;
fallingEdgeLinesComboBox.Enabled = false;
}
catch(DaqException exception)
{
MessageBox.Show(exception.Message);
//dispose task
if(myTask != null)
myTask.Dispose();
}
Cursor.Current = Cursors.Default;
}
private void OnDataReady(IAsyncResult result)
{
try
{
if (runningTask != null && runningTask == result.AsyncState)
{
bool[] data = myDigitalReader.EndReadSingleSampleMultiLine(result);
DisplayData(data);
myDigitalReader.BeginReadSingleSampleMultiLine(
new AsyncCallback(OnDataReady),
myTask);
}
}
catch(DaqException ex)
{
runningTask = null;
MessageBox.Show(ex.Message);
myDigitalReader = null;
myTask.Dispose();
startButton.Enabled = true;
stopButton.Enabled = false;
physicalChannelComboBox.Enabled = true;
risingEdgeLinesComboBox.Enabled = true;
fallingEdgeLinesComboBox.Enabled = true;
}
}