device.open

device.open

device.open

Function

Open the device connection. The current implementation supports serial serial devices.

Syntax

Parameters

ParametersTypeRequiredDefault valueDescription
configObjectYesNoneThe device configuration object.

Serial port configuration field

Currently device.open(config) only supports opening serial serial devices. config fields are as follows:

FieldTypeRequiredDefault valueDescription
typeStringNoserialDevice type. Currently only serial is supported, passing in other values will throw an unsupported device type error.
portStringYesNoneSystem serial port name, such as COM3, /dev/ttyUSB0. Usually comes from the device.scan() return object's port fields.
baud_rateIntNo9600Baud rate, indicating the number of symbols transmitted per second. Must be consistent with the external device configuration.
data_bitsIntNo8Number of data bits. Supports 5, 6, 7, 8.
stop_bitsIntNo1Number of stop bits. Supports 1, 2.
parityStringNononeParity digit. Supports none, odd, even; empty strings are processed as none.
timeoutIntNo1000Read and write timeout, in milliseconds.

Return value

TypeDescription
DeviceReturns the opened device handle.

Example

Notes

  • Configuration fields use snake_case uniformly.
  • baud_rate, data_bits, stop_bits, parity must be consistent with the serial port parameters of the hardware device, otherwise normal communication may not be possible.