Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

How to detect if CAN is "active"?

What is the best way to detect if there are ANY CAN frames coming in on a certain CAN port?

At this moment, I use a notification (see attachment), but if you run this in a loop under Win2k you get a "invalid handle" error at the ncClose vi after some iterations. You get a driver error in each next iteration. ncReset in the beginning doesn't solve the issue. Win98 didn't have this issue, but we had to migrate to Win2k.

Anyway, I'm looking for another or better way to do this, without running into driver issues.
I'm using LV6.0.2, NI-CAN1.6, Win2k.

Thanks in advance,
David.
0 Kudos
Message 1 of 3
(4,230 Views)
Hello-

Try using the "CAN Receive.vi" example. There could be some problems with the state of CAN driver if the execution of the LabVIEW program was halted without ncClose being called.

Randy Solomonson
Application Engineer
National Instruments
0 Kudos
Message 2 of 3
(4,230 Views)
Thanks for yor reply Randy. However, I'm not sure which vi you are refering to since I don't have one in my LV folder named that way. I do have one that uses RTSI, though.

Meanwhile I figured out that ncCreateOccur.vi was causing my problem. It seemed to have problems using the same value for the iteration each time, however the handle was closed on each call. After some iterations it messed up, causing cnClose to fail (as you said) and bringing the nican driver to an "internal error". It surprised me that the code works perfectly under Win98 and not under Win2k.

Anyway, my solution was:
- taking out the "occurrence stuff" and replacing by a ncWait.
- Using a read queue of 0 and using ReadNet instead of ReadNetMult. This ensures I don't get a input b
uffer overflow.
- Opening and closing my network interface once instead of on each call of "CAN Active?". I think this was not needed afterall, but it is a better way anyway. The only disadvantage is that the code that detects active CAN isn't in 1 vi any more.

It all seems to work now, I'm a happy man! ;o)

Thanks,
David Marien
Test Engineer
Ford Motor Company
0 Kudos
Message 3 of 3
(4,230 Views)