Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for DAQmx input tasks #185

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static PinSiteData<double[]> ReadAnalogMultiSample(this DAQmxTasksBundle
return tasksBundle.DoAndReturnPerSitePerPinResults(taskInfo =>
{
taskInfo.VerifyTaskType(DAQmxTaskType.AnalogInput);
taskInfo.Task.Stream.ChannelsToRead = taskInfo.ChannelList;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to restore original channels after the read operation, otherwise subsequent reads using direct driver calls will be affected.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lornazh Updated as such, I have introduced new variable to store the All channels information.

As strings are immutable I've taken this approach. Since the type Tasks are of type mutable, it is taking shallow copy of the value that is taken.

Please let me know if there are any concerns.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused, if you directly write the following, are you seeing value of availableChannels changing after the second line of code is executed?

string availableChannels = taskInfo.Task.Stream.ChannelsToRead;
taskInfo.Task.Stream.ChannelsToRead = taskInfo.ChannelList;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that' right. That's why I have taken a deep copy and updated accordingly.

if (taskInfo.Task.AIChannels.HasSingleChannel())
{
var reader = new AnalogSingleChannelReader(taskInfo.Task.Stream);
Expand All @@ -47,6 +48,7 @@ public static PinSiteData<AnalogWaveform<double>> ReadAnalogWaveform(this DAQmxT
return tasksBundle.DoAndReturnPerSitePerPinResults(taskInfo =>
{
taskInfo.VerifyTaskType(DAQmxTaskType.AnalogInput);
taskInfo.Task.Stream.ChannelsToRead = taskInfo.ChannelList;
if (taskInfo.Task.AIChannels.HasSingleChannel())
{
var reader = new AnalogSingleChannelReader(taskInfo.Task.Stream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static void WriteAnalogSingleSample(this DAQmxTasksBundle tasksBundle, do
{
tasksBundle.Do(taskInfo =>
{
taskInfo.Task.Stream.ChannelsToRead = taskInfo.ChannelList;
Shalini-Subramanian marked this conversation as resolved.
Show resolved Hide resolved
var writer = new AnalogMultiChannelWriter(taskInfo.Task.Stream);
SampleValuesCacher<double>.Instance.TryWriteAndRecoverCacheOnFailure(taskInfo, staticState, data => writer.WriteSingleSample(autoStart, data));
});
Expand All @@ -34,6 +35,7 @@ public static void WriteAnalogSingleSample(this DAQmxTasksBundle tasksBundle, Si
{
tasksBundle.Do(taskInfo =>
{
taskInfo.Task.Stream.ChannelsToRead = taskInfo.ChannelList;
var writer = new AnalogMultiChannelWriter(taskInfo.Task.Stream);
SampleValuesCacher<double>.Instance.TryWriteAndRecoverCacheOnFailure(taskInfo, siteData, data => writer.WriteSingleSample(autoStart, data));
});
Expand All @@ -49,6 +51,7 @@ public static void WriteAnalogSingleSample(this DAQmxTasksBundle tasksBundle, Pi
{
tasksBundle.Do(taskInfo =>
{
taskInfo.Task.Stream.ChannelsToRead = taskInfo.ChannelList;
var writer = new AnalogMultiChannelWriter(taskInfo.Task.Stream);
SampleValuesCacher<double>.Instance.TryWriteAndRecoverCacheOnFailure(taskInfo, pinSiteData, data => writer.WriteSingleSample(autoStart, data));
});
Expand All @@ -64,6 +67,7 @@ public static void WriteAnalogWaveform(this DAQmxTasksBundle tasksBundle, Analog
{
tasksBundle.Do(taskInfo =>
{
taskInfo.Task.Stream.ChannelsToRead = taskInfo.ChannelList;
var writer = new AnalogMultiChannelWriter(taskInfo.Task.Stream);
SampleValuesCacher<AnalogWaveform<double>>.Instance.TryWriteAndRecoverCacheOnFailure(taskInfo, waveform, data => writer.WriteWaveform(autoStart, data));
});
Expand All @@ -79,6 +83,7 @@ public static void WriteAnalogWaveform(this DAQmxTasksBundle tasksBundle, SiteDa
{
tasksBundle.Do(taskInfo =>
{
taskInfo.Task.Stream.ChannelsToRead = taskInfo.ChannelList;
var writer = new AnalogMultiChannelWriter(taskInfo.Task.Stream);
SampleValuesCacher<AnalogWaveform<double>>.Instance.TryWriteAndRecoverCacheOnFailure(taskInfo, siteData, data => writer.WriteWaveform(autoStart, data));
});
Expand All @@ -94,6 +99,7 @@ public static void WriteAnalogWaveform(this DAQmxTasksBundle tasksBundle, PinSit
{
tasksBundle.Do(taskInfo =>
{
taskInfo.Task.Stream.ChannelsToRead = taskInfo.ChannelList;
var writer = new AnalogMultiChannelWriter(taskInfo.Task.Stream);
SampleValuesCacher<AnalogWaveform<double>>.Instance.TryWriteAndRecoverCacheOnFailure(taskInfo, pinSiteData, data => writer.WriteWaveform(autoStart, data));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static PinSiteData<bool> ReadDigitalSingleSample(this DAQmxTasksBundle ta
return tasksBundle.DoAndReturnPerSitePerPinResults(taskInfo =>
{
taskInfo.VerifyTaskType(DAQmxTaskType.DigitalInput);
taskInfo.Task.Stream.ChannelsToRead = taskInfo.ChannelList;
if (taskInfo.Task.DIChannels.HasSingleChannel())
{
var reader = new DigitalSingleChannelReader(taskInfo.Task.Stream);
Expand All @@ -45,6 +46,7 @@ public static PinSiteData<DigitalWaveform> ReadDigitalWaveform(this DAQmxTasksBu
return tasksBundle.DoAndReturnPerSitePerPinResults(taskInfo =>
{
taskInfo.VerifyTaskType(DAQmxTaskType.DigitalInput);
taskInfo.Task.Stream.ChannelsToRead = taskInfo.ChannelList;
if (taskInfo.Task.DIChannels.HasSingleChannel())
{
var reader = new DigitalSingleChannelReader(taskInfo.Task.Stream);
Expand All @@ -69,6 +71,7 @@ public static PinSiteData<uint[]> ReadDigitalMultiSampleU32(this DAQmxTasksBundl
return tasksBundle.DoAndReturnPerSitePerPinResults(taskInfo =>
{
taskInfo.VerifyTaskType(DAQmxTaskType.DigitalInput);
taskInfo.Task.Stream.ChannelsToRead = taskInfo.ChannelList;
if (taskInfo.Task.DIChannels.HasSingleChannel())
{
var reader = new DigitalSingleChannelReader(taskInfo.Task.Stream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static void WriteDigital(this DAQmxTasksBundle tasksBundle, bool staticSt
{
tasksBundle.Do(taskInfo =>
{
taskInfo.Task.Stream.ChannelsToRead = taskInfo.ChannelList;
var writer = new DigitalMultiChannelWriter(taskInfo.Task.Stream);
SampleValuesCacher<bool>.Instance.TryWriteAndRecoverCacheOnFailure(taskInfo, staticState, data => writer.WriteSingleSampleSingleLine(autoStart, data));
});
Expand All @@ -34,6 +35,7 @@ public static void WriteDigital(this DAQmxTasksBundle tasksBundle, SiteData<bool
{
tasksBundle.Do(taskInfo =>
{
taskInfo.Task.Stream.ChannelsToRead = taskInfo.ChannelList;
var writer = new DigitalMultiChannelWriter(taskInfo.Task.Stream);
SampleValuesCacher<bool>.Instance.TryWriteAndRecoverCacheOnFailure(taskInfo, siteData, data => writer.WriteSingleSampleSingleLine(autoStart, data));
});
Expand All @@ -49,6 +51,7 @@ public static void WriteDigital(this DAQmxTasksBundle tasksBundle, PinSiteData<b
{
tasksBundle.Do(taskInfo =>
{
taskInfo.Task.Stream.ChannelsToRead = taskInfo.ChannelList;
var writer = new DigitalMultiChannelWriter(taskInfo.Task.Stream);
SampleValuesCacher<bool>.Instance.TryWriteAndRecoverCacheOnFailure(taskInfo, pinSiteData, data => writer.WriteSingleSampleSingleLine(autoStart, data));
});
Expand All @@ -64,6 +67,7 @@ public static void WriteDigitalWaveform(this DAQmxTasksBundle tasksBundle, Digit
{
tasksBundle.Do(taskInfo =>
{
taskInfo.Task.Stream.ChannelsToRead = taskInfo.ChannelList;
var writer = new DigitalMultiChannelWriter(taskInfo.Task.Stream);
SampleValuesCacher<DigitalWaveform>.Instance.TryWriteAndRecoverCacheOnFailure(taskInfo, waveform, data => writer.WriteWaveform(autoStart, data));
});
Expand All @@ -79,6 +83,7 @@ public static void WriteDigitalWaveform(this DAQmxTasksBundle tasksBundle, SiteD
{
tasksBundle.Do(taskInfo =>
{
taskInfo.Task.Stream.ChannelsToRead = taskInfo.ChannelList;
var writer = new DigitalMultiChannelWriter(taskInfo.Task.Stream);
SampleValuesCacher<DigitalWaveform>.Instance.TryWriteAndRecoverCacheOnFailure(taskInfo, siteData, data => writer.WriteWaveform(autoStart, data));
});
Expand All @@ -94,6 +99,7 @@ public static void WriteDigitalWaveform(this DAQmxTasksBundle tasksBundle, PinSi
{
tasksBundle.Do(taskInfo =>
{
taskInfo.Task.Stream.ChannelsToRead = taskInfo.ChannelList;
var writer = new DigitalMultiChannelWriter(taskInfo.Task.Stream);
SampleValuesCacher<DigitalWaveform>.Instance.TryWriteAndRecoverCacheOnFailure(taskInfo, pinSiteData, data => writer.WriteWaveform(autoStart, data));
});
Expand Down