Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

USB-6525 NiDaqmx how to detect when device stops communicating

Solved!
Go to solution

This could be considered a more generic question for NiDaqmx, but I am writing a custom control for internal use with the USB-6525 and eventually other I/O devices using C#.  I'm using DigitalChangeDetectionEvent to notify me when an input has changed and everything seems to work very well.  In an effort to be thorough, I decided to disconnect the USB cable to see the result and found that no error was detected until I attempted an output write.  This isn't acceptable because under normal circumstanced the input starts a process which will change outputs - since the input never happens the system is basically hung.

 

I attempted many things, and have spent more time on this than I want to admit so I would like to hear suggestions on how to approach this problem.  Here are my attempts that I'm not happy with:

 

1) periodically toggling an output (heartbeat) which will detect the problem, but I may not have an output available so this isn't a good situation.

2) periodically trying to read the input byte with the same input task stream, this doesn't work because I believe the other reader is always active to handle the DigitalChangeDetectionEvent.

3) attempted to capture the Windows message for hardware change, but seems too complex.

4) I've read about the watchdog, but am not sure it is available on the USB-6525.  So before I start with this I'd rather hear suggestions from others with more experience.

 

Any suggestions please?

 

Thx, Ed

0 Kudos
Message 1 of 10
(5,644 Views)
Solution
Accepted by topic author IntegroEd

Hi IntegroEd,

 

Those are all very innovate means of potentially addressing the problem, and I'm sorry you haven't seen success with them.  Fortunately, the typical means of capturing a disconnect between a DAQ device and the monitoring system is indeed a watchdog timer, and the 6525 does have the innate ability to utilize the functionality, as seen on page 5 of the user manual.  I'd suggest going down that path if another user doesn't post an outlying solution specific to your case.  Here's some documentation on implementing the watchdog--

 

http://www.ni.com/product-documentation/14616/en/

Andy G
Applications Engineering
National Instruments
0 Kudos
Message 2 of 10
(5,614 Views)

Andy G, thank you for the response and I will plan to implement the Watchdog.  In the article, all of the examples are in Labview - can anyone point me to examples using VB.Net or C# please?  I don't find any in the examples that were loaded from the DVD.

 

Thx, Ed

0 Kudos
Message 3 of 10
(5,610 Views)

Hi Ed,

 

There's an example that installs with DAQmx

 

C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples\DotNET4.0\Digital\Generate Values\WriteDigChan_WatchdogTimer

 

Curt

Message 4 of 10
(5,603 Views)

Thank you Curt, I have found it and am testing now.  Something about this is bothering me though and maybe someone can shed light on it for me. 

 

In the comments section I see the information I've included below about asynchronous callback, but in reality it doesn't appear to be async.  The UI response is very poor just running the example as provided, but if I increase the Write Interval from 0.05 to .25 (for example) it clearly makes it unusable.  That value is used in a Thread.Sleep in the callback which indicates to me that it is not async and it blocking the UI thread - am I missing something here?  I've tried this update but it doesn't seem to affect anything: outputTask.SynchronizeCallbacks = false;

 

* 4. Write the digital boolean array data. This write method writes a single

* sample of digital data on demand, so no timeout is necessary. This

* example uses an asynchronous write method and installs a callback.

 

 

* Note: This example sets SynchronizeCallback to true. If SynchronizeCallback

* is set to false, then you must give special consideration to safely dispose

* the task and to update the UI from the callback. If SynchronizeCallback is

 

0 Kudos
Message 5 of 10
(5,557 Views)

Hi IntegroEd

 

It is curious that a shipping example would come with poor UI behavior out of the box.  Have you made any modifications to the code?  And for clarity, the UI is the interface inherent to the program, rather than an external UI, correct?  I'd suggest experimenting wiht the WriteInterval value, and even removing the Thread.Sleep piece of code.  

Andy G
Applications Engineering
National Instruments
0 Kudos
Message 6 of 10
(5,503 Views)

Andy, thank you for the response.  The UI I mention refers to the MainForm in this example program which has very poor response leading me to believe it is not async.  The textbox input for "writeInterval" is only used for the thread sleep as shown below.  I did try it with a value of 0 (sleep = 0) and the UI behavior is responsive, but I suspect that it is writing data far too frequently for a basic watchdog function.

 

To test this I put a counter in and verified with a sleep 0 that it is executing OnDataWritten about 400 times/second.  I don't feel that I can use this example until I understand this complication - the async callback does not appear to be async or it wouldn't be holding up the UI and I don't see the need to waste so much bandwidth writing data 400 times/second.

 

System.Threading.Thread.Sleep((int)(writeInterval.Value * 1000));

0 Kudos
Message 7 of 10
(5,484 Views)

Hi IntegroEd,

 

Thanks for the clarification.  That does seem like an unnecissarily high frequency to reset a watchdog timer, especially given the relatively high timeout.  I did notice that in your previous post, you set outputTask.SynchronizeCallbacks = false.  However, the function doesn't actually include an "s" at the end.  Was this a typo on your end on the forum post, or were you trying this function with the "s" in the code?

 

Andy G
Applications Engineering
National Instruments
0 Kudos
Message 8 of 10
(5,463 Views)

This is copied exactly from my code, and I tried it without the "s" and it doesn't recognize the property:

 

outputTask.SynchronizeCallbacks = false;

0 Kudos
Message 9 of 10
(5,452 Views)

IntegroEd,

 

Hm you're right, I suppose that's a typo on the program description.  I've been experimenting with a setup on my end, and Visual Studio 2012 seems to work fine.  What version are you using?  I don't have a good idea why the UI would be more or less responsive in different versions, but do you have access to 2012 to try out?

Andy G
Applications Engineering
National Instruments
0 Kudos
Message 10 of 10
(5,424 Views)