NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to keep CAN XNET session open

Solved!
Go to solution

I'm calling TestStand 2014 sequences from Python using TestStand.Engine NewExecution() and WaitForEndEx(-1). This is working well until I try to interface with the CAN hardware. When the CAN initialization sequence is called from Python it runs a LabView CAN VI that performs the hardware initialization. Subsequently, when Python calls the enable CAN receiver sequence from Python 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. Interestingly, if I call the CAN initialization sequence 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 2
(126 Views)
Solution
Accepted by topic author VNF

The solution is to keep the sequence file loaded by doing the following two steps:

 

  1. Set the sequence's "Unload Option" in "Run Options" to "Unload when sequence file is unloaded".
  2. In Python, the sequence object is acquired using NI Engine.GetSequenceFileEx() and is released using Engine.ReleaseSequenceFileEx(). Instead of releasing the sequence object immediately after the sequence has finished executing, save the sequence object from Engine.GetSequenceFileEx() and then release it at program exit by calling Engine.ReleaseSequenceFileEx() in a Python function that is registered with atexit.register().

Assuming the sequence is called multiple times, the sequence object should not be immediately released on the first call but can be immediately released on the subsequent calls since NI keeps a load reference count.

0 Kudos
Message 2 of 2
(93 Views)