LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA Serial resource

Gurus,

 

I am having some issues with serial communications. I have a piece of code I have not looked at in about 9 months. I contacted NI support, but I did not get a chance to implement their suggestions/comments. Can someone please explain this to me:

 

If you address a specific port and configure it then you need to use the
reference coming out of your configuration, otherwise you essentially
select an unconfigured port again.
Sooner or later this will cause conflicts and errors. You will still have
to define the correct Serial Port number at the beginning, however you will
need to take the reference out of this VI (selecting a resource), pass it
through for configuration, and eventually use this reference for your read
or write. At the end of your read or write you will have to release this
resource with a Clear or Stop vi.

 Does this basically mean doing what is shown in the attached piccie?

 

What I have in my code is a set up VI that writes the serial resource name (e.g. COM1) and a whole load of other parameters to a cluster and pass it to a Functional Global Variable. I then call this FGV when I need a particular parameter to perform a task, such as configuring the specific port or reading from it. Should I be passing the resource name back to the FGV after the configuration? I think I am missing something.

 

Thanks in advance,

 

Paul

"When I read about the horrors of drinking, I gave up reading"
0 Kudos
Message 1 of 8
(3,569 Views)
Yes and the reference has to closed before you use it again. You cannot open multiple sessions at the same time. Are you getting any errors?
0 Kudos
Message 2 of 8
(3,563 Views)

Muks,

 

I don't understand your answer. You do not have to close a reference before you open a new one and you can have multiple sessions if you want.

0 Kudos
Message 3 of 8
(3,557 Views)
I meant you cannot open the same reference simultaneously and i suppose you will get a "session invalid".
0 Kudos
Message 4 of 8
(3,551 Views)

Yes, you can open the same reference simultaneously and you will not get a session invalid error.

 

Open VISA.png

 

Don't suppose - actually try it. You can also wire a True constant to the duplicate session input and see multiple sessions created.

0 Kudos
Message 5 of 8
(3,547 Views)

Whether I get an error depends on which PC I am using. It varies.

 

I guess a question is, if I close a session, do I have to re-configure the serial port if I want to use it again? I have my configuration VI in one bit and the read and writes in other VIs further in running continuously. So what I tend to do is cheat. I have a control at the very begin to select the resource (port number), and then force a close on it, incase it was left open from a previous run. Then call that port number from a FGV for the config and later the reading/writing.

 

I don't see why passing the resource name back to the FGV from the configure vi is needed, as it appears to be just a duplicate of what has been passed to it. But if that is needed, so be it 🙂

"When I read about the horrors of drinking, I gave up reading"
0 Kudos
Message 6 of 8
(3,526 Views)
If the setting for the port in MAX is different than what you use in the program, then you should probably repeat the init function if you close the port but remember that opening and closing is optional and has been optional for quite a few years. You only really need to close a session if you want another process to be able to access the port while you have LabVIEW running. Once you close LabVIEW, the sessions are closed and you can select to automatically close sessions when the top level VI stops.
0 Kudos
Message 7 of 8
(3,521 Views)

thanks for the info. That was close to my basic understanding. The initial closing of the port was something that was a fix. From olden days when I used labview 5 - 6, never had these problems. When I upgraded and the term VISA came in, started getting a few issues with serial communication and found forcing a close on a port before trying to do anything, even before configuring it, solved most of them. I have never bothered with the opening and closing, just configure,read, write VIs. Luckily, I never have more than one application, or even VI, talking to a particular serial port.

 

Paul

 

Message Edited by Manc Pablo on 03-26-2010 11:22 AM
"When I read about the horrors of drinking, I gave up reading"
0 Kudos
Message 8 of 8
(3,508 Views)