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 2 commits into
base: main
Choose a base branch
from

Conversation

Shalini-Subramanian
Copy link
Collaborator

@Shalini-Subramanian Shalini-Subramanian commented Dec 24, 2024

What does this Pull Request accomplish?

This PR contains the implementation for updating the channels to be read with the filtered channel list, where the task contains channels for multiple sites for one pin and on applying FilterBySite while we get the measurements.

Why should this Pull Request be merged?

Previously, while getting the measurements for the Daqmx tasks, the channels to be read was not updated with the filtered channel list.

We are updating this logic to read/write channels for the filtered list alone.

What testing has been done?

  • Manual Testing
    Read measurements for all sites
    image
    Read measurements for filtered sites
    image

@Shalini-Subramanian
Copy link
Collaborator Author

@lornazh For other drivers, this is already implemented.
Adding reference for example
image

@@ -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.

@lornazh
Copy link
Collaborator

lornazh commented Dec 25, 2024

Please add unit tests in Analog/DigitalInputTests to verify behavior.

@Shalini-Subramanian Shalini-Subramanian changed the title Fix for DAQmx input and output tasks Fix for DAQmx input tasks Dec 26, 2024
@Shalini-Subramanian
Copy link
Collaborator Author

Please add unit tests in Analog/DigitalInputTests to verify behavior.

@lornazh I have updated the unit tests based on comparing the simulated values. Hope it is fine.

{
var sessionManager = Initialize("DAQmxMultiChannelTests.pinmap");
var tasksBundle = sessionManager.DAQmx(pinName);
var filteredResult = tasksBundle.FilterBySite(new int[] { 1, 3 }).ReadAnalogMultiSample(100);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we read 100 samples?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To visualize better using WDV, I have the samples as 100. I'll update it based on your comments on this.

@@ -56,6 +57,21 @@ public void ReadFiveAnalogSamplesFromTwoChannels_ResultsContainExpectedData()
Assert.Equal(5, results.ExtractSite(1)["VCC2"].Length);
}

[Theory]
[InlineData("AIPin")]
public void ReadTwoAnalogSamples_ChannelForMultipleSitesPerPinInstrument_ResultsContainExpectedData(string pinName)
Copy link
Collaborator

@lornazh lornazh Jan 2, 2025

Choose a reason for hiding this comment

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

Method name does not match method logic.

Suggest to rename to "ReadAnalogSamplesFromTwoFilteredChannels_ResultsContainExpectedData".

Please update all tests accordingly.

Assert.Equal(sites.Length, results.SiteNumbers.Length);
}

private void Initialize(string pinMapFileName = "DAQmxSingleChannelTests.pinmap")
Copy link
Collaborator

Choose a reason for hiding this comment

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

To be consistent, please change it to public and move it to the beginning of the test class.

@lornazh
Copy link
Collaborator

lornazh commented Jan 2, 2025

I think we need to add tests to confirm channels to read is not affected after executing these read extension methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants