LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to keep CAN XNET session open

Solved!
Go to solution

I asked this question in the TestStand forum, but it really is more of a LabView question.  So reposting here since no one replied in the other forum.

 

I'm calling a TestStand 2014 CAN sequence from Python.  This sequence calls a CAN LabView VI which can perform initialization, enable the receiver, or read frames depending on the command passed in.  Python is making separate calls to this sequence to do the CAN initialization, then to enable the CAN receiver, then Python runs the UUT to transmit CAN data, then the sequence (VI) is called to read the received frames.  However, when Python calls the enable CAN receiver sequence it gives an error "Error -1074384740 occurred at XNET Start.vi:1790006 ... Solution: Defer clear (session close) until you are done using it".

 

From my research it appears that the XNET CAN session is automatically being closed after the VI is done executing after CAN initialization. Interestingly, if I call the CAN initialization sequence manually from TestStand, then run the Python code which enables the CAN hardware and reads received frames it works as expected.

 

Is there any way to keep the XNET session open between sequence calls from Python?

0 Kudos
Message 1 of 4
(180 Views)

it would help to share the vi here.

However, I think you might pass a wrong can adapter identifier when initializing from python.

Actor Framework
0 Kudos
Message 2 of 4
(142 Views)

Change the Unload option to Unload after sequence file unloads to keep the VI in the memory.

-------------------------------------------------------
Applications Engineer | TME Systems
https://tmesystems.net/
-------------------------------------------------------
https://github.com/ZhiYang-Ong
0 Kudos
Message 3 of 4
(115 Views)
Solution
Accepted by topic author VNF

The Unload option in the sequence file was already set to "Unload when sequence file is unloaded". However, you gave me a big clue.  After Python was calling the sequence file, the code was calling NI Engine.ReleaseSequenceFileEx() to release the sequence file.  Instead of releasing it, I save the sequence object from Engine.GetSequenceFileEx() and then release it at program exit by calling Engine.ReleaseSequenceFileEx() in the Python function that is registered with atexit.register().

 

It now works perfectly, thanks!

Message 4 of 4
(78 Views)