serial_write(ser, tx_data)
기능
Serial 포트에 데이터(tx_data)를 기록합니다.
인수
인수명 | 자료형 | 기본값 | 설명 |
---|---|---|---|
ser | serial.Serial | - | Serial instance |
tx_data | byte | - | 송신할 데이터
|
리턴
값 | 설명 |
---|---|
0 | 성공 |
-1 | Port가 open 상태가 아닙니다. |
-2 | serial.SerialException 예외 발생 |
예외
예외 | 설명 |
---|---|
DR_Error (DR_ERROR_TYPE) | 인수의 데이터형 오류 시 |
예제
ser = serial_open(port="COM", baudrate=115200, bytesize=DR_EIGHTBITS,
parity=DR_PARITY_NONE, stopbits=DR_STOPBITS_ONE)
serial_write(ser, b"123456789") #b는 bytes 형을 의미합니다.
# string을 byte 형으로 변환
msg = “abcd” # msg는 string 변수
serial_write(ser, msg.encode()) # encode()는 string형을 byte형으로 변환
serial_close(ser)