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_open()

Definition

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 Name

Data Type

Default Value

Description

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

Value

Description

serial.Serial instance

Successful connection

Exception

Exception

Description

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

Python
# 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)

Keyword

serial / serial_ / open