02-22-2023 11:06 AM
I like the service idea, I would improve on that to create a service that acts as a man in the middle between the instrument and your application.
02-22-2023 11:28 AM
The other options discussed mostly seem like they could work, but just to throw something else out there, you could have your application register for the .NET event "SessionSwitch" and disconnect or exit when that occurs.
02-22-2023 11:41 AM
Let me throw out a simpler solution- rework your program so it doesn't hold a handle to the hardware when idle.
You didn't say which hardware it was, but if it was something like a serial port, then don't open the port at the beginning of the application- open it at the beginning of your test, then close it at the end of your test. Then leaving the program running wouldn't lock any resources. Same with a DAQmx task.
Your program shouldn't need a hardware handle while it's running idle. Something as simple as a "watchdog" style timer could wait until the user hasn't interacted with the system for X minutes, then self-close the reference. Or use Kyle's suggestion for the .NET event, where it can disconnect its hardware resource.
When your user starts interacting with the program again, have it check for "Hardware connected?" and if not, reconnect it silently.
02-22-2023 11:57 AM
@Kyle97330 wrote:
The other options discussed mostly seem like they could work, but just to throw something else out there, you could have your application register for the .NET event "SessionSwitch" and disconnect or exit when that occurs.
Do yo have an example?
System Events have no public constructors.
02-22-2023 02:18 PM - edited 02-22-2023 02:20 PM
Example attached, backsaved just in case
You don't need a "real" reference to pass in to a register event callback. A constant works fine, so no need to make a constructor node if you know the class you need.
If you run this, then do a "switch user" to log out and back in as yourself real quick, it should fire 4 times, with a different reason enum each time.
02-22-2023 09:21 PM - edited 02-22-2023 09:24 PM
You would need a valid reference normally.
But in this case, it's the system events.
02-23-2023 01:32 AM
@santo_13 wrote:
I like the service idea, I would improve on that to create a service that acts as a man in the middle between the instrument and your application.
- The application will connect to the service to control the device
- If a new application tries to connect with the service, it checks if it is free, if not it will disconnect connection with the existing application
Would you have to start the service as an admin in this case?
------
And some completely noob questions:
And how does one connect to a service with labview? And how does one run labview as a service?
I couldn't find any "native" solutions online (only plugin and some horribly outdated info... also curses on NI for changing their domain and making most of the linked white papers in forum threads dead).