LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trigger an event from software

Hi all,

I have a problem: our lab bought a detector which comes with a LV software. unfortunately the entirety of the lab runs in Python, so while I work on writing some Python code to handle the detector we thought that we could maybe run the vi and control it from some python code via tcp. Works ok with some simple sub-vis, however the main VI relays heavily on events (mouse down on a certain button, mouse up etc.): is there a way to control such event case with some code from inside the vi itself? I read around that there should be the possibility with a control property node, however the help pages/previous discussions on the topic are rather scarce and I don't understand how am I supposed to do that (I don't know LV very well). Does anyone have a simple explanation or a reference to point me towards? Or maybe you know a better solution to my original problem of controlling a vi through python? I welcome any help.

 

0 Kudos
Message 1 of 9
(2,168 Views)

We probably would need to see some code, but a VI with e.g. "mouse down" events does not seem reasonable. Why can't you just use a simple polling loop? No need for event structures.

 

("Mouse down" is typically a poor choice for buttons, because it fires even if the button is disabled. More typical are "value change" events.)

0 Kudos
Message 2 of 9
(2,159 Views)

@altenbach wrote:

We probably would need to see some code, but a VI with e.g. "mouse down" events does not seem reasonable. Why can't you just use a simple polling loop? No need for event structures.

 

("Mouse down" is typically a poor choice for buttons, because it fires even if the button is disabled. More typical are "value change" events.)


"Value change is the best option, like you said.  Only poorly designed UIs (IMO) use "mouse down" because it doesn't give you a chance to "take it back".  On an value change, you can still slide off the button without a mouse up and not trigger the event.  (Probably all the apps everyone is familiar with work this way.)  I guess "value change" for Boolean would behave like "mouse up" but it is much cleaner to act on a button event than a mouse event.

 

I didn't know "mouse down" fired even if the button is disabled!!!  😮 Edit: Is this because disabling the control disables it against that button's event and not a mouse event?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 3 of 9
(2,144 Views)

If you have the source code for the application (which it sounds like you do) it may be easier to simply add a small TCP task which would generate user events into the existing code. However, without seeing the code it is impossible to say how feasible this would be. My thought would be that you simply create the necessary commands that you need to control and translate those to the appropriate events of the current application. It would most likely involve creating some user events which mirror specific events such as the mouse down.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 4 of 9
(2,136 Views)

@billko wrote:


"Value change is the best option, like you said.  Only poorly designed UIs (IMO) use "mouse down" because it doesn't give you a chance to "take it back". 


For buttons, a mouse down seems inappropriate. However, it does have it uses for other UI elements.

0 Kudos
Message 5 of 9
(2,131 Views)

@maurimonti wrote:

I have a problem: our lab bought a detector which comes with a LV software..


It almost looks like you are using some (potentially poorly written?) LabVIEW demo program that came with the unit. Most likely inside that VI you have the "communication/driver" subVIs that do the actual legwork. These are all you need, so write your own LabVIEW code and we can probably help you with that. I also assume there is good documentation how to communicate with the external device, so it could be implemented in your preferred language if you chose to do so.

Message 6 of 9
(2,127 Views)

@billko wrote:
I didn't know "mouse down" fired even if the button is disabled!!!  😮 Edit: Is this because disabling the control disables it against that button's event and not a mouse event?

Similarly, it even works on indicators. Can sometimes be useful as a way to avoid local variables if it "mostly" an indicator. (e.g. to click on it to acknowledge and reset an error condition LED using an event)

Message 7 of 9
(2,123 Views)

Thanks for your replies, I don't know the reason why the VI was written that way, I was hoping to make things work without having to substantially rewrite the vi, at least as a temporary measure until I write something that blends better with the rest of our equipment (being that Labview or python or C or whatever). Here's a couple of screenshots. I am also uploading the main vi itself but it is a bit complex (20+ sub-VIs in the folder) so it may take a long time to figure out every nook and cranny.

 

@Mark_Yedinak wrote:

If you have the source code for the application (which it sounds like you do) it may be easier to simply add a small TCP task which would generate user events into the existing code. However, without seeing the code it is impossible to say how feasible this would be. My thought would be that you simply create the necessary commands that you need to control and translate those to the appropriate events of the current application. It would most likely involve creating some user events which mirror specific events such as the mouse down.

This sounds more or less what I was thinking of doing I have uploaded some code. do you know where I can find information on this? As in there is a specific manual section I should look at? Thank you

 


@altenbach wrote:
It almost looks like you are using some (potentially poorly written?) LabVIEW demo program that came with the unit. Most likely inside that VI you have the "communication/driver" subVIs that do the actual legwork. These are all you need, so write your own LabVIEW code and we can probably help you with that. I also assume there is good documentation how to communicate with the external device, so it could be implemented in your preferred language if you chose to do so.


The Vi Is a bit complex (many sub-VIs) and I am not qualified to comment on the quality, however  the actual leg-work is done by a .dll file  which I have started to write a Python wrapper to, but it is also not the easiest thing to do and will take some time.


maurimonti_0-1627632948151.png

maurimonti_1-1627633083357.png

 

 

0 Kudos
Message 8 of 9
(2,064 Views)

Thanks for the VI. From the style of the front panel control and the overall program architecture, it seems like this was originally written 25+ years ago! Most likely whoever wrote this is long retired! 😄

 

Front panel: Almost everything from the classic palette, but there are a few modern element, most likely added during maintenance years later.

Block diagram: Topelevel stacked sequence structures with 16 frames is not somebody would even consider in modern times. Glaring race conditions!  Are all these globals really used globally or just locally? What about all these inner greedy loops? Value property nodes?

 

Yes, there is a lot of unmaintainable code out there. Sometimes companies hired summer interns or high school students to write a "LabVIEW driver" or demo code for their products and it shows. calling the dll in a reasonably simple program is all you need.

Message 9 of 9
(2,040 Views)