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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

UDP socket binding

Hi

 

I am facing a problem while running a sub VI.

I have developed a VI where I am calling windows system functions using ActiveX.

This vi will generate an event (in this sub VI it will come out from "wait for next event" with out error) whenever Ethernet cable is plugged or unplugged.
Once I run this vi it will wait at invoke node - "wait for next event". At this point I can't stop this sub VI even with abort button.

It's creating the problem in my application (application hangs).

Attached my VI.

Please let me know if you need more information.

 

Thanks

Nesara

0 Kudos
Message 1 of 6
(2,732 Views)

Your code seems to work OK. The help for WaitForNextEvent indicates that this function is blocking.

 

If you want to exit early based on some other condition, then you could reduce the TimeSpan value and use a loop to check for the event or your other conditions.

 

If you are using the Full or Professional version of LabVIEW, you could try using the Register Event Callback function.

 

 


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

Message 2 of 6
(2,716 Views)

Well, ActiveX is a pain. Since most ActiveX components are not multithreaded you can't even call a different method of the ActiveX component to abort the wait even if it would have that method, which is unlikely as most ActiveX components are programmed to only support apartement threading. It would be quite a bit of work and hassle to get the ActiveX component to support proper multithreading, as the ActiveX support on Windows is hampered by all kinds of old Windows 3.1 OLE hacks under the hood to support some form of multithreading in the cooperative multithreading of Windows 3.1.

 

In that case using a small timeout as suggested by Phillip and checking the condition to be a timeout or the actual event is the only working alternative.

 

But since you wrote the component yourself, changing this into a DLL and calling it through the Call library Node should not be a big problem (or did you use Visual Basic to write the component). A DLL is fairly easy to be made multithreading compliant and then you can easily add a second function that allows aborting your wait.

Rolf Kalbermatter
My Blog
Message 3 of 6
(2,700 Views)

Thanks Phillip, Rolf

 

I can use small time out like 100 msec but this will effect my application performance.

 

Can I make this sub VI as LabVIEW function blocks (yellow colour blocks) by any way. So that it will run like a reentrant VI

 

Thanks

Nesara

0 Kudos
Message 4 of 6
(2,696 Views)

No. LabVIEW nodes are built in primitives of the LabVIEW compiler itself and directly implemented in the LabVIEW kernel in C(++). There is no way to create such nodes yourself. To my knowledge there is not even a private interface that would allow that. Back in LabVIEW 3.x days such an interface supposedly existed but was never used outside of NI. I do believe that the first version of the Picture Control was actually using that interface before it was incorporated into LabVIEW itself, but the interface was impossible to maintain between major LabVIEW versions and subsequently entirely removed.

 

And I can assure you that you do not want to dig into the complexities of writing code that would be able to run as a LabVIEW native node. If you would you would be likely some C++ crack and working already in the LabVIEW development team Smiley Wink

Rolf Kalbermatter
My Blog
Message 5 of 6
(2,692 Views)

And as I suggested, rewriting your code as a multithreading safe DLL which exports at least a CreateEvent, WaitEvent, AbortEvent, and CloseEvent function should not be that much work and would solve all the problems you have.

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 6
(2,689 Views)