3.12. UART¶
-
serial_ctrl.serial_config(baud_rate, data_bit, odd_even, stop_bit)¶ Description: Sets the baud rate, data bit, parity bit, and stop bit attributes of the serial port
参数: - baud_rate – Set the baud rate, which can be 9600, 19200, 38400, 57600, or 115200
- data_bit – Set the data bit, which can be cs7 or cs8
- odd_even_crc – Set parity check. For details, refer to the
odd_even_crctable. - stop_bit – Set the stop bit, which can be 1 or 2
返回: None
Example: serial_ctrl.serial_config(9600, 'cs8', 'none', 1)Example description: Set the baud rate to 9600, 8 data bits, no parity check, and 1 stop bit for the serial port
-
serial_ctrl.write_line(msg_string)¶ Description: Send string information and automatically add line breaks ( '\\n')参数: msg_string (string) – The string information that needs to be sent. Automatically append line breaks ( '\\n') after the string when sending it.返回: None Example: serial_ctrl.write_line('RoboMaster EP')Example description: Write 'RoboMaster EP\\n'to the serial port and add line breaks automatically. You only need to send'RoboMaster EP'in this case.
-
serial_ctrl.write_string(msg_string)¶ Description: Send string information 参数: msg_string (string) – String information that needs to be sent 返回: None Example: serial_ctrl.write_string('RoboMaster EP')Example description: Write 'RoboMaster EP'to the serial port
-
serial_ctrl.write_number(value)¶ Description: Convert the numeric parameter to a string and send the string through the serial port 参数: value (int) – The value that needs to be sent 返回: None Example: serial_ctrl.write_number(12)Example description: Write the '12'string to the serial port
-
serial_ctrl.write_numbers(value1, value2, value3...)¶ Description: Convert the list of numbers to a string and send the string through the serial port
参数: - value1 (int) – Value 1 in the list that needs to be sent
- value2 (int) – Value 2 in the list that needs to be sent
- value3 (int) – Value 3 in the list that needs to be sent
返回: None
Example: serial_ctrl.write_numbers(12,13,14)Example description: Write the
'12,13,14'string to the serial port
-
serial_ctrl.write_value(key, value)¶ Description: Converts the parameter to a string of key-value pairs and sends the string through the serial port
参数: - key (string) – The key to be sent
- value (int) – The value to be sent
返回: None
Example: serial_ctrl.write_value('x', 12)Example description: Write the
'x:12'string to the serial port
-
serial_ctrl.read_line([timeout])¶ Description: Read the string ending with '\\n'from the serial port参数: timeout (float) – An optional parameter, which indicates the timeout period in seconds. The default value of this parameter is permanent blocking. 返回: The string read from the serial port 返回类型: string Example: recv = serial_ctrl.read_line()Example description: Read a string ending with '\\n'from the serial port
-
serial_ctrl.read_string([timeout])¶ Description: Read the string from the serial port (the string may or may not end with '\\n')参数: timeout (float) – An optional parameter, which indicates the timeout period in seconds. The default value of this parameter is permanent blocking. 返回: The string read from the serial port 返回类型: string Example: recv = serial_ctrl.read_string()Example description: Read a string from the serial port
-
serial_ctrl.read_until(stop_sig[, timeout])¶ Description: Reads a string from the serial port until the string matches the specified
'stop_sig'ending character参数: - stop_sig – The specified ending character, whose type is char and range is [
'\n'|'$'|'#'|'.'|':'|';'] - timeout (float) – An optional parameter, which indicates the timeout period in seconds. The default value of this parameter is permanent blocking.
返回: The matched string read from the serial port
返回类型: string
Example: serial_ctrl.read_until('#')Example description: Read a string from the serial port until the ending character of the string matches
'#'- stop_sig – The specified ending character, whose type is char and range is [
-
odd_even_crc¶
提示
For the description of the module, refer to UART.