Raritan PX2/PX3 JSON-RPC API: Peripheral Devices

Raritan PX2/PX3 JSON-RPC API

Peripheral Devices

Peripheral devices (external sensors and actuators) are handled by the PeripheralDeviceManager interface. The device manager has a fixed number of slots that discovered sensors can be associated with. Assigning sensors to slots defines the order in which sensors are listed in other client interfaces like SNMP.

The peripheral device manager can either be accessed via its well-known URI `/model/peripheraldevicemanager`, or its reference can be retrieved by using the getPeripheralDeviceManager method of the Pdu or Emd interfaces.

## Using Peripheral Devices

Peripheral devices must be assigned to one of the device manager's slots in order to be used. A device associated with a slot can have settings (like name or location) and a reading.

Settings for a sensor slot can be retrieved with the getSettings method and written with setSettings. getDevice returns information about the device associated with the slot (or `null` if the slot is unassigned), as well as a reference to the respective NumericSensor or StateSensor instance.

# Python example: Display information about all managed peripheral devices
import raritan.rpc.peripheral
pdm = raritan.rpc.peripheral.DeviceManager("/model/peripheraldevicemanager", agent)
slots = pdm.getDeviceSlots()
for num, slot in enumerate(slots):
settings = slot.getSettings()
device = slot.getDevice()
if device == None:
print("Slot %d: unassigned" % (num + 1))
else:
print("Slot %d: %s (%s)" % (num + 1, settings.name, device.deviceID.serial))
if device.device:
if device.deviceID.type.readingtype == raritan.rpc.sensors.Sensor.NUMERIC:
reading = device.device.getReading()
print(" Reading: %f" % reading.value)
else:
state = device.device.getState()
print(" State: %d" % state.value)

## Manually Assigning Sensors to Slots

Sensors must be assigned to one of the deivce manager's slots in order to be used. By default, newly discovered sensors are automatically associated with the first available slot. The assignment can be manually overridden with the assign and unassign methods of the PeripheralDeviceSlot interface:

# Python example: Assign the first discovered sensor to the third slot
import raritan.rpc.peripheral
pdm = raritan.rpc.peripheral.DeviceManager("/model/peripheraldevicemanager", agent)
discovered_devices = pdm.getDiscoveredDevices()
slots = pdm.getDeviceSlots()
if len(discovered_devices) > 0:
slots[2].assign(discovered_devices[0].deviceID)