09-30-2010 06:55 AM
When using a VISA Resource controller to list and select a serial port, is it possible to check if the selected port is busy (already active in another application) or not?
Solved! Go to Solution.
09-30-2010 07:00 AM
Do you mean if it is used by another application such as HyperTerminal or TerraTerm?
If so, then yes it is possible. I am trying to remember how I did it... I think it was using activeX (or dll) to find out if an application was running.
I will do a quick search and post it (if I find it). Otherwise, I can look at the code tonight to see how I did that.
OR
Do you mean if the port is used by another running instance of LabVIEW or even applications which use the same VISA drivers, such as CVI?
09-30-2010 07:03 AM
Thanks for your quick(!) answer!
Yes, that's exactly what I mean. If a different program like HyperTerminal, Putty or TeraTerm is connected to the port. I'm selecting the port in the very beginning of the program, and opening the port later in a different part of the init phase, so I can't try to open the port to check for error messages either.
09-30-2010 07:07 AM
Checking for error message didn't work. That part I remember.
I did a bit of a search and did not find anything yet.
I do remember looking on the MIcrosoft site and it mentionned how to do it. I then coded the explanation into LabVIEW.
I thought I posted something here.
09-30-2010 07:10 AM
I think I used the FindProcDLL plugin as described below.
You can detect if your application is running by using the FindProcDLL plug-in to check if a process having the name of your application executable is running.
Make sure your application executable has an easily identifiable name, or you risk detecting another unrelated application having the same name as yours.
Example:
FindProcDLL::FindProc "MyApp.exe" IntCmp $R0 1 0 notRunning MessageBox MB_OK|MB_ICONEXCLAMATION "MyApp is running. Please close it first" /SD IDOK Abort notRunning:
Additionally you may decide (or offer the user the possibility) to kill the running process forcibly, by using the KillProc plug-in. Note: This can be dangerous as the state of the application and edited files might not be saved correctly.
If your application creates a (main) window with a specific classname or title, you can use it to detect whether the application is running.
Unless you're sure of the application behaviour, be aware that many applications have dynamically generated window classname (different each time), and localized window title depending on the user language.
You can use Visual Studio tool Spy++ or freeware tool SysTree++ to find the window class of your application.
Examples:
FindWindow $0 "MyAppWindowClass" StrCmp $0 0 notRunning MessageBox MB_OK|MB_ICONEXCLAMATION "MyApp is running. Please close it first" /SD IDOK Abort
or
FindWindow $0 "" "MyApp Window Title" StrCmp $0 0 notRunning MessageBox MB_OK|MB_ICONEXCLAMATION "MyApp is running. Please close it first" /SD IDOK Abort
09-30-2010 07:12 AM
This rings a bell.
All I wanted was to know if the application was running. I did not care which port it used, I just killed the application (HyperTerm or TerraTerm).
If you followed the link in my last post, you also find KillProcDll.exe
This plugin provides the ability to check if any process running just with the name of its .exe file.
FindProc "process_name.exe"
The return code is stored in the $R0 variable.
The return codes are as follows:
09-30-2010 07:24 AM
Ouch, this was advanced! 🙂 And way beyond my LabVIEW skills, I'm afraid. 🙂
It's not possible to use a reference to the selected port and check a status flag in any way?
If not, how then can I implement the code you proposed?
I'm not so interested in knowing which application is using the selected port, and definitely not in forcibly ending the application. I just want to know if the port it busy/connected or not.
09-30-2010 07:26 AM
For checking if port already opened or not you can also use CreateFile WinAPI function.
Also you can read following article: Serial Communications in Win32.
From my point of view using VISA functions much more easier. Just call VISA Configure Serial Port.vi, and if port buzy, then you should receive error code 0xBFFF0072 (the resource is valid, but VISA cannot currently access it). Not fully understand, why you can't use it.
Andrey.
09-30-2010 12:24 PM
In my case, I wanted to close whatever application was using the serial port.
So I guess, it was a more complicated approach.. 😉
Andrey's suggestion is very easy to implement.
10-01-2010 02:14 AM
@Andrey Dimitriev:
VISA Configure Serial Port.vi worked like a charm. Exactly what I was after. 🙂
@Ray.R:
Yes, I would expect that killing a process would involve a bit more extensive coding. 🙂 I'll keep your tips in mind if I have to look into that on another project.