LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to determine if the current application is active (frontmost)?

Hi all,

 

I have several independent LabVIEW programs running on the same PC (all compiled as executables) that need to use the same barcode scanner.

As I cannot access the scanner through more than one application at once, I came up with the idea of running an extra program (I call it ScannerMonitor) in the background that deals with the scanner and passes data to whoever needs it.

This is done through a subVI, running within each application that receives data from 'ScannerMonitor' and triggers a user event to process the data.

 

Ofcourse, when scanning a barcode, only one application should process the data, this should be the application that the user has chosen, by having one of it's front panels open and frontmost.

 

I can use the FP.IsFrontMost property to determine if the main front panel window of the application is on top to decide whether to trigger the event.

This works fine when interacting with the main panel of the application.

 

But when the user has to enter data into a dialog window, this approach does not work anymore, as the main frontpanel is no longer frontmost (the dialog panel is).

 

What I would like to do, is check weather the application is "frontmost" , instead of it's main frontpanel.

 

Any suggestions?

 

 

 

 

0 Kudos
Message 1 of 9
(4,447 Views)

There may be some method in the Windows API Function Utilities that could help determine which exe is foremost but I've never done this myself...

http://zone.ni.com/devzone/cda/epd/p/id/4935

0 Kudos
Message 2 of 9
(4,420 Views)

Most barcode scanners, especially USB ones, are virtual keyboards. As such, if you simply have a string control activated and scan it'll write in that control, just like if you wrote it yourself. Set the control to Single line and the scanners Endline will create a value change event.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 9
(4,410 Views)

Another solution is to make the scanner program a small webserver, to which you can communicate. Send Address and Message to the scannerprogram, it presents a dialog and then sends the result back to Address.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 9
(4,409 Views)

@Electromecha: I've glanced at the readme file, nothing jumps out at me... I'll investigate further though.

Thanks for the tip!

0 Kudos
Message 5 of 9
(4,397 Views)

@Yamaeda:

 

Configuring the scanner as 'keyboard input' is not an option, as the data read by the scanner determines where the data has to go.

The barcode data consists of a data identifier field, preceding data. This identifier holds information about what kind of data was read (eg. 'Part number' or 'Serial number' etc.) and where to write it. Also, the user has to be able to type in the data if needed.

 

I'm not familiar with the 'web server' idea, but it seems that I would have to 'ask' for scanner data. This is not what I need. The act of scanning a certain barcode should trigger an event in the client application, not the other way round.

 

Thank you for you reply.

0 Kudos
Message 6 of 9
(4,395 Views)

Hello Pianne,

 

To check which "application window" is active there are several ways to do this.

 

If you want to work with multiple LabVIEW Executable, then the FrontMost VI property doesn't really provide any use.

This will only show you which Window inside your LabVIEW executable has the most focus.


If you have multiple executables, then in each of those executables one VI can be the Frontmost.

So it could be that in this case multiple executables have their own FrontMost main VI.

 

All your different LabVIEW Executables on the one pc their Application Windows are (as far as I know) created using the same LabVIEW.exe process.
(If this information would be incorrect, please let me know).

So this means that the same process "creates" the Windows for all the different applications.

 

This makes the backtracking of to which application a certain Window belongs a lot more difficult.

 

What you can easily do is detect which Window is active and use the Window Title to determine to which application it belongs:

eg: I have a "Test 1.exe". In this case I can make sure that all the panels a user can view contain a link to the executable you're running.

Some examples of different "panel names" withing the same Test 1.exe could be:

- Test 1
- Test 1: Enter UUT Information.
- Test 1: Modify Report Options

In general it can be useful to have some descriptor of the application in any pop-up window you're using.

An example of how you can retrieve this name (through the Windows API) can be found in attachment.

 

Remember that this is just one simple approach that could be used and it also has its drawbacks.

 

To get back to the main program I would like to have some more background information:

- Why do you need multiple independent applications?

- Wouldn't it be more useful and easier to work with a Plug-In Framework and one executable?

- What are the independent applications actually doing?
- Why are they open at the same time?

 

 

 

Kind Regards,
Thierry C - CLA, CTA - Senior R&D Engineer (Former Support Engineer) - National Instruments
If someone helped you, let them know. Mark as solved and/or give a kudo. 😉
Message 7 of 9
(4,370 Views)
@ThiCop: Could you possibly save your example in LV2012?
0 Kudos
Message 8 of 9
(4,210 Views)

Hello,

 

Here is the VI reverted to LabVIEW 2012.

Kind Regards,
Thierry C - CLA, CTA - Senior R&D Engineer (Former Support Engineer) - National Instruments
If someone helped you, let them know. Mark as solved and/or give a kudo. 😉
Message 9 of 9
(4,182 Views)