정의
serial_open(port=None, baudrate=115200, bytesize=DR_EIGHTBITS, parity=DR_PARITY_NONE, stopbits=DR_STOPBITS_ONE)
기능
Serial 통신 포트를 오픈합니다.
인수
|
인수명 |
자료형 |
기본값 |
설명 |
|---|---|---|---|
|
port |
string |
None |
|
|
baudrate |
int |
115200 |
Baud rate 2400, 4800, 9600, 19200, 38400, 57600, 115200 |
|
bytesize |
int |
8 |
데이터 bit 수
|
|
parity |
str |
"N" |
Parity checking
|
|
stopbits |
int |
1 |
Stop bit의 수
|
리턴
|
값 |
설명 |
|---|---|
|
serial.Serial instance |
연결 성공 |
예외
|
예외 |
설명 |
|---|---|
|
DR_Error (DR_ERROR_TYPE) |
인수의 데이터형 오류 시 |
|
DR_Error (DR_ERROR_VALUE) |
인수의 값이 유효하지 않을 시 |
|
DR_Error (DR_ERROR_RUNTIME) |
Serial.SerialException 예외 발생 |
예제
Python
# 시리얼 포트 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)
# USB to serial 장비를 USB 포트에 연결한 경우
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)