List connected devices in java sdk

I am writing a module and I want to get a list of connected devices. Can someone point me to the some class or function that would allow me to do this.

There is no public API for this.

You could possibly query the “DeviceSettings” table in the internal DB for a list of configured devices but this won’t get you information about whether they are connected or not.

Additionally, being “connected” is not something that is even universal to every type of device, and is not something you can ask of a device even if you could get a list. Every device has getStatus() call that returns String and can be whatever is appropriate at the current time for that type of device.

so there is nothing similar to system.device.listDevices() from python (https://docs.inductiveautomation.com/display/DOC80/system.device.listDevices)? I want something similar in java

That function is implemented by querying the DeviceSettings table + using private APIs to get the device status.

Your module could get the script manager to call that python function … (:

Haha :smiley: I was hoping for a java solution but since there is no public API … why not! Thanks

Can a module developer query “DeviceSEttings” Table in the internal DB? If yes how ? Any reading recommendations ?

Where context is a GatewayContext:

List<DeviceSettingsRecord> deviceSettingsRecords = context.getPersistenceInterface().query(
    new SQuery<>(
        DeviceSettingsRecord.META,
        SQueryMode.SREAD_ONLY)
);

Thanks so much !!

DeviceSettingsRecord belongs to the OPC UA module, which means your module will have to be dependent on the OPC UA module in order to reference it and run this query.

So I added the following import in my code:

import com.inductiveautomation.ignition.gateway.opcua.server.api.DeviceSettingsRecord;

and the following dependecy in my poml file for the import to work:

        <dependency>
            <groupId>com.inductiveautomation.ignitionsdk</groupId>
            <artifactId>driver-api</artifactId>
            <version>${ignition-sdk-version}</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>
    </dependencies>

but i get this error:

java.lang.NoClassDefFoundError: com/inductiveautomation/ignition/gateway/opcua/server/api/DeviceSettingsRecord

at net.cpxinfra.cpxtools.GatewayHook.deviceListGetter(GatewayHook.java:54)

at net.cpxinfra.cpxtools.GatewayHook.startup(GatewayHook.java:49)

at com.inductiveautomation.ignition.gateway.modules.ModuleManagerImpl$LoadedModule.startup(ModuleManagerImpl.java:2433)

at com.inductiveautomation.ignition.gateway.modules.ModuleManagerImpl.startupModule(ModuleManagerImpl.java:1226)

at com.inductiveautomation.ignition.gateway.modules.ModuleManagerImpl$2.call(ModuleManagerImpl.java:771)

at com.inductiveautomation.ignition.gateway.modules.ModuleManagerImpl.executeModuleOperation(ModuleManagerImpl.java:947)

at com.inductiveautomation.ignition.gateway.modules.ModuleManagerImpl.installModuleInternal(ModuleManagerImpl.java:737)

at com.inductiveautomation.ignition.gateway.modules.ModuleManagerImpl$InstallCommand.execute(ModuleManagerImpl.java:1903)

at com.inductiveautomation.ignition.gateway.modules.ModuleManagerImpl$Receiver.receiveCall(ModuleManagerImpl.java:1856)

at com.inductiveautomation.ignition.gateway.redundancy.QueueableMessageReceiver.receiveCall(QueueableMessageReceiver.java:47)

at com.inductiveautomation.ignition.gateway.redundancy.RedundancyManagerImpl.dispatchMessage(RedundancyManagerImpl.java:933)

at com.inductiveautomation.ignition.gateway.redundancy.RedundancyManagerImpl$ExecuteTask.run(RedundancyManagerImpl.java:1008)

at com.inductiveautomation.ignition.common.execution.impl.BasicExecutionEngine$ThrowableCatchingRunnable.run(BasicExecutionEngine.java:518)

at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.base/java.lang.Thread.run(Unknown Source)

Caused by: java.lang.ClassNotFoundException: com.inductiveautomation.ignition.gateway.opcua.server.api.DeviceSettingsRecord

at java.base/java.net.URLClassLoader.findClass(Unknown Source)

at com.inductiveautomation.ignition.gateway.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:37)

at java.base/java.lang.ClassLoader.loadClass(Unknown Source)

at com.inductiveautomation.ignition.gateway.modules.ModuleClassLoader.loadClass(ModuleClassLoader.java:85)

at java.base/java.lang.ClassLoader.loadClass(Unknown Source)

You need an entry like this in your module configuration as well: https://github.com/inductiveautomation/ignition-sdk-examples/blob/63a037020f4b7a7455ca928fed6c4511af4c7bc8/opc-ua-device/opc-ua-device-build/pom.xml#L56-L61