Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Change detection doesn't work in Visual studio 2010 test project.

Hello guys!

 

Is there anybody here who tried to run a DigitalInput DigitalChangeDetection reading based mechanism using a VisualStudio 2010 Test project?

 

I spent 2 days on this trying to figure out what was the problem. Every clues I have point to a problem between a VisualStudio 2010 test projects and the Nidaq driver on change detection.

 

The easiest way to reproduce the problem is to take the code sample from ReadDigChan_ChangeDetection_Events.2010 and put that into a new class with a public method like Start in it, which would then start the listening on your digital card. It takes ~15minutes to do this setup.

 

Do the same using the Digital Output sample.

 

From here, you have your DI and DO class.

 

Now Start a new Test project (I mean a REAL test project, not a class libary, console application or windows form, just to make sure!), and try to send a new value to a DO line connected to a DI line. On my side, I do a System.Threading.Thread.Sleep(1000) just after the DO sending to make sure the DI has time to get the message but what happens after the Sleep is : The agent process was stopped while the test was running.    and the test stop.

 

I've never been able to reach the callback.

 

However, if I do a sample project using (for example) a Windows Form project and substitude my Asserts with my own test mechanism, still using the DI and DO class created earlier, it works fine.

 

I tried to use the NI DI ReadDigChan_ChangeDetection_Events.2010 application to get the reading from my tests and it works fine (when I substitude the DI part of my test).

I tried to use Measurement and Automation Explorer to generate the DO through my test and it makes the agent disconnect too, no event launched, test failed.

 

 

The real VS test project however works PERFECTLY when I use a software timer in combination with ReadSingleSampleMultiLine. Only the change detection work fine.

 

I currently have >2000 test lines for each of my classes (One using a software timer, the other Change detection). It would really help me not to have to rewrite those 2000 lines into a non-VS2010 test project. (My application will select the most efficient class supported by the selected card. ChangeDetection being the most efficient and if not supported, software timer reading.)

 

 

FYI, I tried using to 6321 cards linked together, tried with a 6514, 6518... all the same result. They all fail to work using ChangeDetection INTO a VS2010 test project.

 

I can send you the little test setup described above if you want.

 

Let me know if I'm not clear enough, need more infos...

 

Would be great to see that I'm wrong but from now I have some big doubts!

 

Thanks in advance for your time,

 

0 Kudos
Message 1 of 13
(6,079 Views)

plg,

 

I am having trouble trying to understand what the problem is with the code. Is the issue that the DI does not work or that the DO does not work with change detection. I ask this because at the top you stated that you have spent 2 days trying to figure out the problem with the DigitalInput Digital Change Detection. However you then later state that " I tried to use the NI DI ReadDigChan_ChangeDetection_Events.2010 application to get the reading from my tests and it works fine (when I substitute the DI part of my test)". Is it a certain version of Visual Studio (ie VS 2010 vs. VS 2008) that is not working with your code? Is it DI or DO that has a problem with the Digital Change Detection setting? Are you receiving an error? This will help us to troubleshoot the issue. Thanks! 

Frank,
National Instruments
Software Group Manager
0 Kudos
Message 2 of 13
(6,049 Views)

Hello Frank!

 

I'm working with VS2010 Pro, no 2008 involved.

 

Yeah I thought I wasn't clear. Sorry, I'm not english native 🙂

 

What I really mean is that everything work fine OUTSIDE of a VisualStudio 2010 TEST project.

When I try to do my UNIT TESTS from VisualStudio, the DigitalChangeDetection event is NEVER fired.

 

What I meant with the "I tried to use the NI DI ReadDigChan_ChangeDetection_Events.2010 application to get the reading from my tests and it works fine (when I substitute the DI part of my test)" is that I used outside applications to simulate output or read input TO/FROM my own application. To isolate the problem...

 

The test run abord without any error other that the agent get disconnected from the test run, which is an almost useless error message when debugging.

 

 

As I said, the best thing to do is to take the NI DI ChangeDetection application & a NI DO application, strip off the windows form stuff, put the stuff into classes and try to do a simple UNIT TEST using DigitalChangeDetection.

 

Write something on a DO line, do a System.Threading.Thread.Sleep(1000) to make sure the Change gets detected from the DI part and then check if you ever get to the DigitalChangeDetection event.

 

As soon as I Sleep, I get disconnected from the test run, even in step by step debug. So it crashes but without any error.

 

I hope it's clearer now but if it isn't, I'll send you a sample test project reproducing what I mean.

 

Thanks in advance!

 

PL

0 Kudos
Message 3 of 13
(6,022 Views)

PL,

 

Are we sure that the unit test which fires the event is actually being executed? As this would prevent you from seeing this information. What do you mean by "As soon as I sleep" do you mean turn the computer to sleep mode? Also using breakpoints in your code will allow you to be able to debug you code a little better to see the inherent problem. Thanks!

Frank,
National Instruments
Software Group Manager
0 Kudos
Message 4 of 13
(5,997 Views)

Hello Frank!

 

Thanks again for the quick update. Sorry for the answering delay!

 

For sure it is being executed. When I mean sleep, I mean using the call to the .NET API System.Threading.Thread.Sleep(int).

 

I'm also aware about the break point thing. I'm a professional software developper. 🙂

 

The thing is using break point/step by step execution, I get to the point where I send a new line value using my DigitalOutput class, I sleep for some milliseconds to make sure everything is processed before trying to read back from the DigitalInput class. So I pass the Output part, get to the sleep line and then as soon as I step up to the next code line, the debugger detach and I can't continue to debug. So it crashes but without any special error. There's no exception being thrown in my code or anything.

 

As said, it ONLY does that in a Unit Test project, not a regular windows form project.

 

Can you try to reproduce that? I gived you the easy steps to reproduce the problem. I can also send you the VS2010 solution if you want to test it.

0 Kudos
Message 5 of 13
(5,945 Views)

What version of DAQmx are you using? Have you tried updating to the latest DAQmx driver (9.2.3) as this is the only version that supports Visual Studio 2010 and this could be the cause of the problem. If you want to attach the file below I could take a look at it for you.

Frank,
National Instruments
Software Group Manager
0 Kudos
Message 6 of 13
(5,925 Views)

Hello Frank,

 

As I am using VS2010 & targetting .NET framework 4.0, I took the 9.2.3.


NI-DAQmx Device Driver                         9.2.3f1
NI-DAQmx ADE Support                           9.2.3
NI-DAQmx MAX Configuration                     9.2.3

 

 

Open up the solution and take a look at TestProject2 project.

 

Configure the const, which are pretty self describing:

DIO\DO.cs
        private readonly string CONST_OUT_LINE_ADDRESS = "Dev4/Line32";

DIO.DI.cs

        private readonly string CONST_IN_LINE_ADDRESS = "Dev5/Line0";

 

In that case, my DO card is a NI6514. I set the output line to use to be Dev4/Line32.

My DI card is a NI6518. I set the input line to be Line0. Both are linked together and it works fine using Measurement Automation Explorer.

 

Go to UnitTest1.cs, TestMethod1(). Right click on TestMethod1 name and select Run test. You should get the following error message :

Error    TestMethod1    TestProject2    The agent process was stopped while the test was running.

 

If you run it in debug mode (CTRL + R,T), it NEVER step into the DigitalChangeDetection event. It even stop running after the call to Sleep without any particular message. (Debugger gets detached)

 

The event should be fired after myDO.Write() has been called. I putted breakpoint in : DIO\DI\myTask_DigitalChangeDetection. It never get fired. That's the problem.


 

OTHERWISE, in the same solution, take a look at WindowsFormsApplication2 project.

It's the same exact code, only put in a different project type.

 

Configure the const, which are pretty self describing:

Form1.cs
        private readonly string CONST_OUT_LINE_ADDRESS = "Dev4/Line32";

DI.cs

        private readonly string CONST_IN_LINE_ADDRESS = "Dev5/Line0";

 

In that case, my DO card is a NI6514. I set the output line to use to be Dev4/Line32.

My DI card is a NI6518. I set the input line to be Line0. Both are linked together and it works fine using Measurement Automation Explorer.

 

If you run the application, click START IN (which start the DI task) and then click Start OUT (which start the DO task and write a change to trigger DI DigitalChangeDetection event).

This works fine.

 

They are both made from the sample applications provided by NI, which work fine. They only difference is that one is being used in a UNIT TEST project, the other on a regular Windows form project.

All my other unit tests works fine, using Analog Input, Output and even DigitalInput and Output when using a software timer to check for change. The ONLY problem is when using DigitalChangeDetection.

 

Let me know if you need more explanation. I'm guessing it has to do with some background thread running on the driver side.

0 Kudos
Message 7 of 13
(5,914 Views)

Anyone had a chance to reproduce this problem?

 

I'm getting some pressure to solve this issue so I'm thinking about replacing Unit Test for this specific part of my project by standard console based testing.

 

It would be better than nothing.

 

Thank you!

0 Kudos
Message 8 of 13
(5,732 Views)

Following through your steps I could not initially run the tests as it needed a particular dll. I then set up debug mode then I right clicked TestMethod1 again and was able to run the test, and according to the Test Results sections, the test passed properly. After I stopped debugging I tried to re run the test, and the test passed correctly with debug mode off. Perhaps on your end there is something incorrectly installed, as to run this test I did fresh installs of Visual Studio 2010, and DAQmx 9.2.3 as I previously had 2008 and DAQmx 9.2.2 .  

Frank,
National Instruments
Software Group Manager
0 Kudos
Message 9 of 13
(5,709 Views)

Thank you for your time Frank.

 

I just want to make sure the test setup was as expected.

 

Can I ask you which cards were you using?

Where they linked together (through GPIOs) in a way that if you send on a specific line, the other card would receive the digital signal on it's own line? You validated it is working in Measurement & Automation Explorer?

Did you configure the CONST_OUT_LINE_ADDRESS and CONST_IN_LINE_ADDRESS (according to the previous question)?

 

If all of the above is correctly set, the test pass and when you set a breakpoint in the ChangeDetection event, the application stop on it?

 

 

I can get it to pass the test too if the cards aren't properly linked together, as it wouldn't trigger ChangeDetection.

 

Many thanks in advance!

0 Kudos
Message 10 of 13
(5,704 Views)