Craig Craig - 4 years ago 133
Python Question

List sensors in ev3dev with python

Using the python binding, it is possible to get a list of motors using list_motors(), however I cannot find a similar function for listing sensors.

How would I list all the available sensors?

Answer Source

Using the code for list_motors, I have come up with the following function for listing sensors:

def list_sensors(name_pattern=ev3.Sensor.SYSTEM_DEVICE_NAME_CONVENTION, **kwargs):
   classpath = abspath(ev3.Device.DEVICE_ROOT_PATH + '/' + ev3.Sensor.SYSTEM_CLASS_NAME)
   return (ev3.Sensor(name_pattern=name, name_exact=True) 
           for name in ev3.list_device_names(classpath, name_pattern, **kwargs))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download