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 |
|
|
baudrate |
int |
115200 |
Baud rate 2400, 4800, 9600, 19200, 38400, 57600, 115200 |
|
bytesize |
int |
8 |
Number of data bits
|
|
parity |
str |
"N" |
Parity checking
|
|
stopbits |
int |
1 |
Number of stop bits
|
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
# 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)