03-26-2010 09:38 AM
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
03-26-2010 09:58 AM
03-26-2010 10:07 AM
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.
03-26-2010 10:09 AM
03-26-2010 10:16 AM
Yes, you can open the same reference simultaneously and you will not get a session invalid error.
Don't suppose - actually try it. You can also wire a True constant to the duplicate session input and see multiple sessions created.
03-26-2010 10:48 AM
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 🙂
03-26-2010 11:06 AM
03-26-2010 11:21 AM - edited 03-26-2010 11:22 AM
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