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

정의

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

기능

Serial 통신 포트를 오픈합니다.

인수

인수명

자료형

기본값

설명

port

string

None

  • D-SUB(9 pin) 연결 : “COM”

  • USB to Serial 연결 : “COM_USB”

baudrate

int

115200

Baud rate

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

bytesize

int

8

데이터 bit 수

  • 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

Stop bit의 수

  • DR_STOPBITS_ONE =1

  • DR_STOPBITS_ONE_POINT_FIVE = 1.5

  • DR_STOPBITS_TWO = 2

리턴

설명

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)

Keyword

serial / serial_ / open