Perry will know more about the Javadoc situation, but the answer to both of your questions should be yes. As in @KGarner’s linked thread, you’ll need to have a dependency on the Perspective module in your module’s code to be in the right classloader scope, and after that get the PerspectiveGatewayContext.
You’ll then have to either know how to get into the session you want (or, and it’ll be much easier, just send your message to all sessions). You’ll need to ‘target’ this session by it’s ID; see
That gives you an
Optional<InternalSession>, which extends
Session has a
queue method which returns an
ExecutorService. All operations against Perspective properties must go through this queue - dispatch lambdas using
Once you’ve got a session, you need to decide the scope you’re going to send to, and what to actually send. I’d recommend starting at the whole session. Construct a
com.inductiveautomation.perspective.gateway.event.UserScopeMessageEvent - for the PyObject, just create a
PyStringMap from a hashmap. Then, get into the queue and dispatch an event to the session:
session.queue().submit(() -> session.getEventBus().post(message)));
Sending to pages or views requires accessing the
viewEventBus, respectively - you’ll need to drill in from the
Session object. That should be enough to get you started.
- Is it possible to write a session custom prop with the sdk ?
Yes - similarly, you’ll need to have a
Session, and any operations you do must go through the queue. You’ll need to get the
custom property tree, via
com.inductiveautomation.perspective.gateway.api.PropertyTreeOwner#getPropertyTreeOf - the
InternalSession is a
PropertyTreeOwner, so just
session.getPropertyTreeOf(PropertyType.custom). Then there are a few public
write overloads, such as:
com.inductiveautomation.perspective.gateway.property.PropertyTree#write(java.lang.String, com.inductiveautomation.ignition.common.gson.JsonElement, com.inductiveautomation.perspective.common.property.Origin, java.lang.Object)
The plain Object parameter should just be a reference to wherever you’re calling the write from.
Writing to a session parameter that doesn’t exist will implicitly create it.