Vision - User Defined Object?

Hi all - is there something in vision like an Object data type for Custom Properties,

I have an application where I'm using a client script to open a socket for TCP communication with a device (RFID reader) and everything works great for reading while the vision gui is active so long as a use system.util.invokeAsynchronous. However, then the socket exists on some other thread, and isn't stored anywhere that I can access?

ie: on my 'rfid_connect' event on startup, or on a button I have:
returned_thread = system.util.invokeAsynchronous(RFID.RFID_CLIENT,[state_path,path,enb_path,connected_path,ip,port])

But I can't seem to find a way to store that returned thread in something I can then access in another event or script?

Problem then is if I need to send a command to that device, even though there's an active socket I have to open a second second, send a command, and close.

Thank you!

system.util.getGlobals/system.util.globals exposes a persistent string-keyed dictionary capable of holding any arbitrary type. It lasts as long as the local JVM is open (so the Vision client, Designer, or Gateway instance).

Be careful not to put any custom Jython classes into it, or you're prone to memory leaks, but that's less of a concern in client scoped executions.

1 Like

Ah!!! Thank you! that's wonderful.

no 'setGlobals' ?? :stuck_out_tongue:

# Write value 'hello' to global variable 'foo'.

system.util.getGlobals()[ 'foo' ] = 'hello'

system.util.getGlobals returns the singleton instance; you can also use Jython's property access shortcut syntax: system.util.globals.

Since it's just a regular Python/Jython dictionary, you can (and should) use Python methods like setdefault for thread-safe access to a default value in the dictionary, depending on what you're ultimately stashing in it, ex.
system.util.globals.setdefault("someKey", "someDefault")

2 Likes

I have achieved supreme victory - thank you!

1 Like