LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Specific Labview .NET question

Solved!
Go to solution

Hello folks, I've done a lot of searching before posting this, as I cannot find the exact information I need specific to my programming requirements.

 

Situation:

 

>.NET dll driver provided to me, written specifically to talk to one of our Bluetooth devices.

 

>Labview VI written using case structures, in order to interface between Teststand and the DLL driver so we can control it from Teststand

(we don't want to use the native Teststand .NET connector, and require a VI for other uses).

 

In my VI I have a Constructor Node > Invoke Node and all behaves. I initialise and connect to a COM port, run some commands and it works fine.

 

However if I stop the VI to run it again using a different case from the structure, I have to re-start the entire port connection process.

 

I want to run the initialise case once, then call the command cases as many times over as I need without having to re-construct the .NET reference and establish the port again.

 

Do I require use of passing refnums to achieve this? The port remains connected (unavailable to other applications) after the VI stops. But I take it using the constructor each time resets the connection.

 

I then can't use an invoke node to run a command, without having a constructor node before it, so how do I do this?

 

Many thanks!

0 Kudos
Message 1 of 16
(2,804 Views)

Hi Tom,

 

However if I stop the VI to run it again using a different case from the structure, I have to re-start the entire port connection process.

The problem is: why do you need to restart your VI to select a different case?

Shouldn't this be just a switch on your frontpanel? (Or some kind of state machine?)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 16
(2,766 Views)

Hi GerdW

 

Thanks for getting back to me. Teststand will call the VI, run it, take results from the VI terminals and stop it. It will do this on repeat through it's test sequence steps.

 

Normally when testing something in Teststand I will run an initialise step, which runs an initialise case in the VI.

Next I'll run a connect, to the target device

Then I'll run 'read something' or 'write something' etc

Then run a case to disconnect once I've finished with it.

 

Usually once a port is attached I can continue to read / write without having to start over. I just wondered how to chime in on a .NET object once it's been constructed, but the VI has stopped running. Or am I doing this wrong?

 

Thanks!

0 Kudos
Message 3 of 16
(2,762 Views)

Hi Tom,

 

I see two problems:

1. Usually you need to forward the .NET reference to your second VI/case/state: how do you do this in your current setup?

2. LabVIEW might do some garbage collection when a VI stops: Cleaning up references is part of that. How do you prevent LabVIEW from doing so?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 16
(2,760 Views)

I added a 'reference out' after the case structure, but I haven't done anything with it yet as not sure what.

 

The constructor sits before the case structure, so each time it runs, a new .NET object is created, then an Enum selects the required case. Then in each case I currently have to start over with my port connection, and disconnect it every time.


What I want to do it pickup the existing .NET instance of the connection when I'm running reads and writes.

 

I don't currently stop anything being cleared up, any advice on this?

 

Thank you!

0 Kudos
Message 5 of 16
(2,756 Views)

Hi Tom,

 

when you create a new .NET reference you need to open the port again.

 

What I want to do it pickup the existing .NET instance of the connection when I'm running reads and writes.

As written before: don't close the .NET reference and use it with your next call.

 

As this seems to be a TestStand (and no LabVIEW) problem you shoul dask in a Teststand forum

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 16
(2,752 Views)

Hi thanks

 

One thing, "don't close the .NET reference and use it with your next call."

 

How do I wire the .NET ref input terminal, on the first invoke node, of the new call/case? The problem I have is the left-most invoke node needs a reference, so I'm using a Constructor node each time. How do I instead pass it the existing reference?

 

Thanks again

0 Kudos
Message 7 of 16
(2,747 Views)

Hi Tom,

 

How do I instead pass it the existing reference?

In LabVIEW you use the connector pane of the VI to define VI inputs/outputs. And you use wires to forward data from one VI to the next (and to enforce DATAFLOW)…

 

No idea how you do that in Teststand.

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 16
(2,744 Views)

Ah yes, I'll experiment with the reference in and out, that may hold the answer to using an invoke node without a new constructor node at the start.

 

Thanks!

0 Kudos
Message 9 of 16
(2,738 Views)

Opening a reference in one VI, and then passing the reference to teststand probably won't work. When the VI stops running, it will close the reference as it is part of its data space.

 

To prevent that, you probably need to start a dynamic VI that opens the connection, passes it to the rest of the code (a (functional) global), and then keeps running.

 

DISCLAMER: my TS is a bit rusty. It was called TestExecutive last time I used it.

0 Kudos
Message 10 of 16
(2,728 Views)