From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

NI-CAN port access from various vi

Hi,
I use NI-CAN ncOpen.vi to open a CAN port (say, CAN0). It returns a objHandle to be used for further accesses to that CAN port (say again, CAN0). That's all fine, access to CAN0 works. Problem is, when I run a vi inside a Sub Panel (via Invoke Node), that vi is not directly wired in the blcok diagram. I have to pass parameters to that vi to function properly. If I pass the objHandle to that vi so it could access CAN0, the objHandle value (it is a U32 originally) is retained (OK) but access to CAN0 fails.

Anyone with an idea, how to access same CAN port from different vi that are open but not directly wired?

Thanks,

Ran
0 Kudos
Message 1 of 2
(3,201 Views)
Ran,

I would recommend that you write your objHandle to a global after your ncOpen or start through ncAction.  Any vi that would be invoked through vi server can then read that global and pass it to any CAN driver subvis.  In your subvi that gets spawned, be careful not to read the global in a loop (its a waste of resources); just read it once outside of any loop that you may have; as the value of objHandle will not change.  Close your objHandles with ncClose in your main program after any spawned subvis have terminated.

I have been using this concept for years and have found it to be very reliable.

Milan

0 Kudos
Message 2 of 2
(3,193 Views)