Device routing is a mechanism that allows you to send commands to a specific device using the connection with the base. This is done by specifying the device_identifier when sending a command through a service. The service doesn't need to be implemented by the base.
In other words, a command can be sent to a sub device, using a service known ony by the sub device (e.g.: ActuatorConfigClient
) as long as the device_identifier is specified in the command parameters.
To obtain the device_identifier you need to use the Device Manager service.
The sole purpose of the Device Manager service is to return a device handle list containing handles for all devices present using the method ReadAllDevices()
.
- The device handle list returned by
ReadAllDevices()
is not in any specific device order - Device handles also have the fields
device_type
andorder
# API initialisation
device_manager = DeviceManagerClient(router)
subDevicesInfo = device_manager.ReadAllDevices()
The DeviceConfig
service provides information about the interrogated device:
- device type
- firmware and bootloader version
- model, part, and serial number
- MAC address and
- hardware revision
# Api initialisation
device_manager = DeviceManagerClient(router)
device_config = DeviceConfigClient(router)
# Get all device routing information (from DeviceManagerClient service)
all_devices_info = device_manager.ReadAllDevices()
options = RouterClientSendOptions()
options.timeout_ms = 4000
# Use device routing information to route to every devices (base, actuator, interconnect, etc.) in the arm/base system and request their general device information
for dev in all_devices_info.device_handle:
device_info = {}
device_info.update( json_format.MessageToDict( device_config.GetDeviceType (dev.device_identifier, options) ) )
device_info.update( json_format.MessageToDict( device_config.GetFirmwareVersion (dev.device_identifier, options) ) )
device_info.update( json_format.MessageToDict( device_config.GetBootloaderVersion (dev.device_identifier, options) ) )
device_info.update( json_format.MessageToDict( device_config.GetModelNumber (dev.device_identifier, options) ) )
device_info.update( json_format.MessageToDict( device_config.GetPartNumber (dev.device_identifier, options) ) )
device_info.update( json_format.MessageToDict( device_config.GetPartNumberRevision (dev.device_identifier, options) ) )
device_info.update( json_format.MessageToDict( device_config.GetSerialNumber (dev.device_identifier, options) ) )
# Get hexadecimal representation of MAC address
macAddress_hexstr = ""
for b in device_config.GetMACAddress(dev.device_identifier, options).mac_address:
macAddress_hexstr += "%02X:" % b
macAddress_hexstr = macAddress_hexstr[:-1] # remove last ':'
device_info.update( { "macAddress": macAddress_hexstr } )
print("-----------------------------")
print("-- {}: id = {} --".format(Common_pb2._DEVICETYPES.values_by_number[dev.device_type].name, dev.device_identifier))
for key, value in device_info.items():
print(str("%20s") % key + ": " + str(value))
The device_identifier can be used with other services to directly interrogate a device.
# API initialisation
device_manager = DeviceManagerClient(router)
vision_config = VisionConfigClient(router)
# Getting all device routing information (from DeviceManagerClient service)
allDevicesInfo = device_manager.ReadAllDevices()
vision_handles = [hd for hd in allDevicesInfo.device_handle if hd.device_type == DeviceConfig_pb2.VISION ]
if len(vision_handles) == 0:
print("Error: there is no vision device registered in the devices info")
elif len(vision_handles) > 1:
print("Error: there are more than one vision device register in the devices infos")
else:
handle = vision_handles[0]
sensor_id = VisionConfig_pb2.SensorIdentifier()
sensor_id.sensor = VisionConfig_pb2.SENSOR_COLOR
intrinsic_value = vision_config.GetIntrinsicParameters(sensor_id, handle.device_identifier)
print("Width: {0}".format(intrinsic_value.width))
print("Height: {0}".format(intrinsic_value.height))
print("Principal point x: {0}".format(intrinsic_value.principal_point_x))
print("Principal point y: {0}".format(intrinsic_value.principal_point_y))
print("Focal length x: {0}".format(intrinsic_value.focal_length_x))
print("Focal length y: {0}".format(intrinsic_value.focal_length_y))