Skip to main content
Skip table of contents

serial_write(ser, tx_data)

Features

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

Parameters

Parameter NameData TypeDefault ValueDescription

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

ValueDescription

0

Success

-1

The port is not open.

-2

serial.SerialException error occurred

Exception

ExceptionDescription

DR_Error (DR_ERROR_TYPE)

Parameter data type error occurred

Example

PY
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)
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.