Skip to content

brian.sensors.sensor_port_probe

brian.sensors

AutoDetect class objects

class AutoDetect(Enum)

NOT_CONNECTED

ANALOG_P1

ANALOG_P1_HACKER

Force P1 ADC mode, regardless of what AD thinks

ANALOG_P6

ANALOG_P6_HACKER

Force P6 ADC mode, regardless of what AD thinks

I2C_9K6

NXT ultrasonic uses bit banging I2C implementation and cannot operate faster than 9600 bits/s

I2C_100K

Some other 3rd party sensors may support only standard I2C speed

I2C_400K

Most other 3rd party sensors support fast I2C speeds

UART_2400

UART_9600

UART_115K

115200 baud

UART_MULTI_BRIAN_MASTER

UART_MULTI_BRIAN_SLAVE

Slave has uart RX/TX pins swapped

PROTOCOL_UART_EV3

PROTOCOL_I2C_NXT_REG

ERROR

SensorInfo class objects

class SensorInfo()

i2c protocol specifies type as 8char string; uart ev3 as a single byte 0-255 when uart ev3 protocol is used, the name can be something like: "Uart 39" and the code will contain the actual value when i2c protocol is used, the code can be = 0

sensor_type_name

@property
def sensor_type_name() -> str

The sensor type name as a string.

sensor_type_code

@property
def sensor_type_code() -> int

Represents the sensor type code.

selected_mode

@property
def selected_mode() -> int

The currently selected mode of the sensor.

mode_name

@property
def mode_name() -> str

The name of the current mode.

mode_count

@property
def mode_count() -> int

Set by sensor handler. EV3 sensors report their mode count. Generic I2C sensor will have 0. Specific I2C sensors (NXT US) will have constant mode count. Even analog sensor, such as NXT light can have multiple modes and mode count - active, passive, blinking differential handled by ST code

unit_name

@property
def unit_name() -> str

Name of the measurement unit.

raw_min

@property
def raw_min() -> float

Minimum raw sensor value.

raw_max

@property
def raw_max() -> float

Maximum raw sensor value.

pct_min

@property
def pct_min() -> float

Percent value corresponding to the minimum raw value.

pct_max

@property
def pct_max() -> float

Percent value corresponding to the maximum raw value.

si_min

@property
def si_min() -> float

Scaled International (SI) value corresponding to the minimum raw value.

si_max

@property
def si_max() -> float

Scaled International (SI) value corresponding to the maximum raw value.

SensorPortProbe class objects

class SensorPortProbe()

is_sensor_api_handler_registered

is_connected

auto_detect

auto_detect_hint

info

probe_sensor

def probe_sensor(port: SensorPort) -> SensorPortProbe

Return latest read-only information about a sensor connected to a given port. This method can be called

any time (regardless of registered Sensor port handler or if it is not registered)

Arguments:

  • port: sensor port to probe.

Returns:

information about the current port usage

probe_sensor_with_autodetect_hint

def probe_sensor_with_autodetect_hint(port: SensorPort,
                                      hint: AutoDetect) -> SensorPortProbe

Return latest read-only information about a sensor connected to a given port.

It requests a specific handling of the sensor, based on the autodetect hint. The hint may be used to initialize a specific software protocol over a detected bus (e.g. use EV3 UART protocol if the detected sensor interfaces using UART). When you expect a specific class of sensors to be connected, this may be useful to extract more information, for example about the sensor modes. This method can be used only, when there is no Sensor handler registered.

Arguments:

  • port: sensor port to probe.
  • hint: hint to for autodetect (e.g. software protocol over detected hw bus)

Raises:

  • SensorPortAlreadyInUse: When trying to probe port that is already in use.

Returns:

information about the current port usage

reboot

def reboot(port: SensorPort) -> None

Turn off power to the port and turn it back on. This will forcibly reboot the sensor.

The powered-down state lasts about 100ms. In case of some (mostly digital) sensors, there can be some additional time (~1s or more) to boot up and process connection handshake with Brian. This method can be used only, when there is no Sensor handler registered. When there is, use the method in the Sensor handler itself.

Arguments:

  • port: sensor port to force reboot.