LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can a Functional Global Variable retain a connection instance in a shift register?

I'm attempting this with a ModbusTCP Master connection, but it doesn't seem to be working out. And I don't know if it's something I'm forgetting, or if it's just not possible. I attached my VI, as well as a screenshot below.

 

Keep in mind, this is a scratch VI. So some of the logic is incomplete, or doesn't make sense. But that shouldn't be affecting my connection to the device. I've tested my connection to the ModbusTCP Server with a continuously running loop, and I'm able to stay connected and read from it just fine. The problem only arises when I try to use an FGV style VI.

 

connection fgv.PNG

0 Kudos
Message 1 of 7
(1,443 Views)

Lol, never mind. As soon as I read through my question after posting it, I noticed I was closing the connection each time the loop exited. And since it's a FGV, the loop was exiting every time it was called. Nice one 🤠

Message 2 of 7
(1,441 Views)

What is this at the end of your code?

Frozen_0-1669148256194.png

 

It appears your closing your reference. That would be the reason it is not working.

---------------------------------------------
Former Certified LabVIEW Developer (CLD)
Message 3 of 7
(1,440 Views)

Note that your code can be simplified.  (See attachment)

"If you weren't supposed to push it, it wouldn't be a button."
Message 4 of 7
(1,406 Views)

Isn't it frustrating when your code does exactly what you told it to do, and that's not what you wanted it to do?  The best we can hope for is that eventually the two converge.  🙂

 

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 5 of 7
(1,365 Views)

One other thing that bites most FGV users sooner or later who try to let their FGV manage a LabVIEW refnum resource:

 

LabVIEW refnums have a very well defined life time. They are closed either on an explicit close or when the VI hierarchy in which it was opened goes idle. A VI hierarchy is a top level VI and all its subVIs and yes you can have multiple top level VI hierarchies in a program. Any VI started with the VI server method "Run" is a top level VI and so are VIs opened and started with Call Asynchronous. If you call your FGV in the hierarchy of such a top level VI to open the refnum, that refnum will be garbage collected the instant that top level VI stops executing 

 

So you should always open LabVIEW refnums in the context of the main (longest running) hierarchy if you plan to keep them around for some time in a FGV (or any other global access granting storage).

Rolf Kalbermatter
My Blog
Message 6 of 7
(1,349 Views)

@billko wrote:

Isn't it frustrating when your code does exactly what you told it to do, and that's not what you wanted it to do?  The best we can hope for is that eventually the two converge.  🙂

 


And it can be worse:  I can look right at the wrong code and not 'see' an extremely obvious mistake.

"If you weren't supposed to push it, it wouldn't be a button."
Message 7 of 7
(1,315 Views)