3.7.0 3.6.0 3.5.0 3.4.0 3.3.0 3.2.2 3.2.1 3.2.0 Korean English Chinese Czech Dutch French German Hungarian Italian Japanese Polish Portuguese Spanish
3.7.0 3.6.0 3.5.0 3.4.0 3.3.0 3.2.2 3.2.1 3.2.0 Korean English Chinese Czech Dutch French German Hungarian Italian Japanese Polish Portuguese Spanish

serial_write()

Definition

serial_write(ser, tx_data)

Features

This function writes the data (tx_data) to a serial port.

Parameters

Parameter Name

Data Type

Default Value

Description

ser

serial.Serial

-

Serial instance

tx_data

byte

-

Data to be transmitted

  • The data type must be a byte.

  • Refer to the example below.

Return

Value

Description

0

Success

-1

The port is not open.

-2

serial.SerialException error occurred

Exception

Exception

Description

DR_Error (DR_ERROR_TYPE)

Parameter data type error occurred

Example

Python
ser = serial_open(port="COM", baudrate=115200, bytesize=DR_EIGHTBITS, 
          parity=DR_PARITY_NONE, stopbits=DR_STOPBITS_ONE)
 
serial_write(ser, b"123456789") # b means the byte type.
 
# Convert string to byte
msg = “abcd”               # msg is a string variable
serial_write(ser, msg.encode()) # encode() converts string type to byte type
 
serial_close(ser)

Keyword

serial_ / write