Python

파이썬에서 시리얼 데이터 받기 (String Data)

지니 2022. 9. 23. 22:59
반응형

여기는 String 형태의 시리얼 데이터를 받는 예제입니다.

Hex 데이터는 다음 글을 보세요. 

선행작업
pip install pyserial   

pip가 설치가 안된경우  pip 를 먼저 설치 합니다.
apt install python3-pip  


코드

import serial
ser = serial.Serial(port='/dev/ttyUSB0', baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS)

while True:
    if ser.readable():
        res = ser.readline()
        print(res.decode()[:len(res) - 1])

 

엄청 간단하죠? 설명이 필요 없을정도입니다. ..ㅎㅎㅎ 

반응형