LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Acquiring a COM port

Hello,
 
Can you think of a way to "reserve" a COM port in LabVIEW?  I have a GUI with several VI's running concurrently (this can't be changed) and each uses the same COM port.  Right now, I am opening the port in the main VI and using a semaphore to control access to the COM port.  Instead I would like to "reserve" the COM port so that only my main VI and it's sub VIs can access it.  If this is possible then I will be able to use the VISA open/close VIs in each page and get rid of the semaphore completely.
 
Thanks!
Jorge
0 Kudos
Message 1 of 9
(3,828 Views)
I'm confused as to what you want.  What do you mean by "reserve" a com port?  Is it open or closed in that state?  If you want "only" your main VI and subVI's to access the com port, what other things beside those do you have that could access the com port?  Another external program?
 
You can open a com port once in the main VI and keep it open.  Pass the VISA reference into the respective subVI's by way of the purple wire.  Close the VISA port at the end of the program.  But this contradicts your statement of opening and closing in each "page".  What is a "page"?
 
Perhaps if you post  more of a description of your application, even VI's, or some screenshots of your front panel and block diagram, we can propose a different solution to what you are trying to do.
0 Kudos
Message 2 of 9
(3,823 Views)
It sounds like you may be under the mistaken presumption that setting a semaphore for a resource will make it apply to other applications. This is not the case. If you open a COM port in LabVIEW, and you try to launch, say, HyperTerminal to access that same COM port, you will get an error from HyperTerminal telling you the COM port is in use. You do not need a semaphore for this to happen. And even if you used one it would do you no good since HyperTerminal knows nothing about that semaphore.
0 Kudos
Message 3 of 9
(3,813 Views)
It seems that I butchered the explanation of my program and confused everyone Smiley Very Happy.  Attached is a diagram to help.
 
My program launches several VIs which run concurrently.  The top-level VI opens the COM port and passes the reference along with a semaphore to each subVI.  The subVIs then use the semaphore to determine if the COM port is currently being used by another subVI.
 
I want to get rid of the semaphore and only use VISA OPEN/CLOSE calls in each sub VI.  If the port is in use, the VISA OPEN will fail and I will know to try again later.  I want to be able to do this without allowing another application (such as hyperterminal) to steal the COM port from my program.
 
Is this possible?
 
Jorge
 
 
0 Kudos
Message 4 of 9
(3,808 Views)
It is possible, but what prevents the sub-vi from communicating over the serial port at the same time, or sending commands and expecting replies "out of turn"?  Which means that if one sub-vi sends a command and expects a reply, another sub-vi may intercept it.
 
There are other ways of dealing with multi-to-one resource, but it would require quite a bit of code change.
 
Why do you want to remove the semaphore?  And why was it placed in the first place?  (just to verify its original need).
 
BTW, VISA OPEN may not prevent the other sub-vi's from grabbing the port..
 
R


Message Edited by JoeLabView on 07-10-2008 01:01 PM
0 Kudos
Message 5 of 9
(3,797 Views)
I think you need to look at using the VISA Lock/Unlock functions.
Message 6 of 9
(3,787 Views)
In a situation like this, I would consider breaking out all serial port interaction from the subVI's and create a single point of communication (in a subVI, perhaps with a action engine architecture).  If an original subVI wants to use the com port, it just puts its message into a queue.  The new Com subVI monitors the queue and handles the communication.  It can pass back any returned messages through a separate notification.  Since the subVI will only handle one message at a time, the other messages are held up in the queue until the subVI completes its prior messages.
0 Kudos
Message 7 of 9
(3,780 Views)

Ravens,

you read minds..  ! 😮

That's similar to what I had in mind when I mentionned this:


JoeLabView wrote:
There are other ways of dealing with multi-to-one resource, but it would require quite a bit of code change.



0 Kudos
Message 8 of 9
(3,778 Views)
 
        Dennis Wrote:
        I think you need to look at using the VISA Lock/Unlock functions.

 
Yes! Thanks! The is exactly what I was looking for.  I did not notice them earlier because they are in the "Advanced VISA" menu which I was unaware of. 
 
Raven and Joe: I like your solution, but as Joe mentioned it will require a bit of modification to my current program.  This method will definitely be used in future projects (this is only my first experience with LabVIEW).
 
Thanks again everyone!
0 Kudos
Message 9 of 9
(3,756 Views)