Skip to main content
Skip table of contents

serial_open(port=None, baudrate=115200, bytesize=DR_EIGHTBITS, parity=DR_PARITY_NONE, stopbits=DR_STOPBITS_ONE)

Features

This function opens a serial communication port.

Parameters

Parameter NameData TypeDefault ValueDescription

port

string

None

  • D-SUB(9 pin) Connection : “COM”
  • USB to Serial Connection : “COM_USB”

baudrate

int

115200

Baud rate

2400, 4800, 9600, 19200, 38400, 57600, 115200

bytesize

int

8

Number of data bits

  • DR_FIVEBITS: 5
  • DR_SIXBITS: 6
  • DR_SEVENBITS: 7
  • DR_EIGHTBITS: 8

parity

str

"N"

Parity checking

  • DR_PARITY_NONE: "N"
  • DR_PARITY_EVEN: "E"
  • DR_PARITY_ODD: "O"
  • DR_PARITY_MARK: "M"
  • DR_PARITY_SPACE: "S"

stopbits

int

1

Number of stop bits

  • DR_STOPBITS_ONE =1
  • DR_STOPBITS_ONE_POINT_FIVE = 1.5
  • DR_STOPBITS_TWO = 2

Return

ValueDescription

serial.Serial instance

Successful connection

Exception

ExceptionDescription

DR_Error (DR_ERROR_TYPE)

Parameter data type error occurred

DR_Error (DR_ERROR_VALUE)

Parameter value is invalid

DR_Error (DR_ERROR_RUNTIME)

Serial.SerialException error occurred

Example

PY
# When connected to serial port D-SUB (9 pin)
ser = serial_open(port="COM", baudrate=115200, bytesize=DR_EIGHTBITS, 
parity=DR_PARITY_NONE, stopbits=DR_STOPBITS_ONE)
 
res = serial_write(ser, b"123ABC")
 
serial_close(ser)
 
 
# When a USB to serial device is connected to a USB port
ser = serial_open(port="COM_USB", baudrate=115200, bytesize=DR_EIGHTBITS, 
parity=DR_PARITY_NONE, stopbits=DR_STOPBITS_ONE)
 
res = serial_write(ser, b"123ABC")
 
serial_close(ser)
JavaScript errors detected

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

If this problem persists, please contact our support.