01-04-2010 02:14 PM
Hello All,
I have a PXI chassis with 3 NI-6723 AO cards and 1 NI-6250 AI card, which has its inputs multiplexed with two SCX-1104C AI MUX modules. The C# program I have is supposed to constantly poll the input channels at 1 kHz, perfoms some logic, and then write constant voltages to the output channels, but there is a seemingly random delay of about 1-20ms between the time it reads and writes; in other words, the response time of the system isn't constant. What could be causing this variable response time?
I'm new at this and I didn't write the original code, but I'll try to discover any details that are needed to help diagnose this problem. The code is quite convoluted, but here are some code snippits that might be relevant (or not):
switch (_type)
{
case ChannelType.AnalogueIn:
_task.AIChannels.CreateVoltageChannel(channel.Host + channel.Device + channel.Name, string.Empty, channel.Termination, channel.Minimum, channel.Maximum, channel.InputVoltageUnits);
_activeChannelMap.Add(_mapCounter);
break;
case ChannelType.AnalogueOut:
_task.AOChannels.CreateVoltageChannel(channel.Host + channel.Device + channel.Name, string.Empty, channel.Minimum, channel.Maximum, channel.OutputVoltageUnits);
_activeChannelMap.Add(_mapCounter);
channel.Bind(this);
break;
default:
OnNotification(new Notification(NotificationType.Debug, "Invalid channel type detected during task initialization", "name=" + _name, "expected=" + _type.ToString(), channel.ToString()));
break;
}
#region Configure Streams and callbacks
switch (_type)
{
case ChannelType.AnalogueIn:
_reader = new AnalogMultiChannelReader(_task.Stream);
_readerCallback = new AsyncCallback(ReaderCallback);
_reader.SynchronizeCallbacks = true;
break;
case ChannelType.AnalogueOut:
_writer = new AnalogMultiChannelWriter(_task.Stream);
_writerCallback = new AsyncCallback(WriterCallback);
_writer.SynchronizeCallbacks = true;
break;
}
#endregion
internal void Execute()
{
for (int i = 0; i < _activeChannelMap.Count; i++)
{
for (int j = 0; j < Instance.GetInstance().Configuration.SampleCount; j++)
{
_values[i, j] = _channels[_activeChannelMap[i]].Data.Values[j];
}
_channels[_activeChannelMap[i]].OnChannelCommitted();
}
_writer.BeginWriteMultiSample(true, _values, _writerCallback, _task);
}
private void ReaderCallback(IAsyncResult result)
{
try
{
if (_state == TaskState.Executing)
{
// Get last sample results.
_values = _reader.EndReadMultiSample(result);
if (_run)
{
// Start the next sample.
_reader.BeginReadMultiSample(Instance.GetInstance().Configuration.SampleCount, _readerCallback, _task);
// Get the new data.
for (int i = 0; i < _values.GetLength(0); i++)
{
double[] sample = new double[Instance.GetInstance().Configuration.SampleCount];
for (int j = 0; j < _values.GetLength(1); j++)
{
sample[j] = _values[i, j];
}
_channels[_activeChannelMap[i]].Update(sample);
}
// Raise the time source tick event (Don't do this for inputs).
OnTimeSourceTick();
}
else
{
_task.Stop();
_state = TaskState.Ready;
}
}
}
catch (DaqException daqx)
{
OnNotification(new Notification(NotificationType.Error, "An error occured while retrieving sample data.", _context, _name, daqx.ToString()));
_task.Dispose();
_state = TaskState.Aborted;
OnStateChanged();
}
if (_state == TaskState.Executing)
{
// Generate the event so subscribers can update.
OnSample();
}
}
Thanks, everyone.
01-05-2010 06:06 PM
Hello mah115,
I haven't gone through the code, but from your description it sounds like you're trying to achieve some type of feedback control. Your output will vary to the input it receives. If that is that case, I highly suspect the variant delays to be sourced from running on a Windows OS. The resolution of any action on Windows will vary in milliseconds. Is your PC running any other application alongside the one in question.