11-22-2022 02:15 PM
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.
11-22-2022 02:18 PM
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 🤠
11-22-2022 02:18 PM
What is this at the end of your code?
It appears your closing your reference. That would be the reason it is not working.
11-22-2022 02:47 PM
Note that your code can be simplified. (See attachment)
11-22-2022 09:57 PM
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. 🙂
11-23-2022 01:58 AM - edited 11-23-2022 01:59 AM
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).
11-23-2022 08:10 AM
@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.