![입력 오버플로 메시지를 억제하는 방법](https://linux55.com/image/58732/%EC%9E%85%EB%A0%A5%20%EC%98%A4%EB%B2%84%ED%94%8C%EB%A1%9C%20%EB%A9%94%EC%8B%9C%EC%A7%80%EB%A5%BC%20%EC%96%B5%EC%A0%9C%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95.png)
Raspbian(Debian 버전: )을 실행하는 Raspberry Pi가 있습니다.Linux version 3.12-1-rpi ([email protected]) (gcc version 4.7.2 (Debian 4.7.2-5+rpi1) ) #1 Debian 3.12.9-1+rpi1 (2014-05-19)
USB를 통해 연결된 직렬 출력 장치(전력계)가 있습니다. Python 스크립트를 사용하여 매분마다 직렬 포트를 읽습니다.
편집: 내가 기대하는 데이터는 다음 기준을 따릅니다.DSMR v3.0
데이터 텔레그램은 10초마다 제공됩니다. Python 스크립트는 1분마다 시작되어 cron
하나의 데이터 텔레그램을 읽습니다.
내 것에 는 다음 dmesg
이 넘쳐납니다.var/log/messages
/var/log/syslog
Nov 2 10:32:07 electron kernel: [151762.159243] ttyUSB0: 2 input overrun(s)
나는 그것을 조정했다 /etc/rsyslog.conf
. 삭제함으로써 *.=kern;
이러한 메시지가 수신되는 것을 성공적으로 억제했습니다 /var/log/messages
. 불행하게도 메시지는 계속 표시되었습니다 dmesg
./var/log/syslog
/var/log/syslog
에서는 언급되지 않았습니다 /etc/rsyslog.conf
. 다른 메커니즘으로 제공됩니까? ttyUSB0 에서 들어 dmesg
오고 나가는 메시지를 어떻게 억제합니까 /var/log/syslog
?
Python 스크립트에서 원인을 찾을 수 있다고 우려하시는 분들을 위해 알려드립니다(개선 사항이 있으면 감사하겠습니다). 내가 사용하는 스크립트는 다음과 같습니다(데이터 후처리 생략).
#! /usr/bin/python
import sys, serial, re
port = serial.Serial()
port.baudrate = 9600
port.bytesize = serial.SEVENBITS
port.parity = serial.PARITY_EVEN
port.stopbits = serial.STOPBITS_ONE
port.xonxoff = 1
port.rtscts = 0
port.dsrdtr = 0
port.timeout = 0
port.port = "/dev/ttyUSB0"
def gettelegram():
# flag used to exit the while-loop
abort = 0
# countdown counter used to prevent infinite loops
loops2go = 40
# storage space for the telegram
telegram = []
# end of line delimiter
delim = "\x0a"
try:
port.open()
serial.XON
except:
abort == 4
# open error terminates immediately
return telegram, abort
while abort == 0:
try:
# this doesn't seem to work
#line = str(port.readline()).strip()
line = "".join(iter(lambda:port.read(1),delim)).strip()
except:
# read error, terminate prematurely
abort = 2
if line == "!":
abort = 1
if line != "":
telegram.append(line)
loops2go = loops2go - 1
if loops2go < 0:
abort = 3
# test for correct start of telegram
if telegram[0][0] != "/":
abort = 2
try:
serial.XOFF
port.close()
except:
abort == 5
# Return codes:
# abort == 1 indicates a successful read
# abort == 2 means that no valid data was read from the serial port
# abort == 3 indicates a data overrun. More lines were received than expected.
# abort == 4 indicates a serial port open error.
# abort == 5 indicates a serial port close error.
return (telegram, abort)
if __name__ == "__main__":
telegram, status = gettelegram()
편집: 몇 가지 추가 테스트를 수행했습니다. 위 프로그램이 완료된 직후에 입력 오버플로 오류가 발생합니다. port.XOFF()
이전에 추가하려고 시도했지만 port.close()
도움이 되지 않았습니다.
EDIT2: 명령 주위에 삽입을 시도했습니다 serial.XON
. 그러나 이것은 도움이 되지 않습니다.serial.XOFF
port.read(1)
답변1
더 이상 이 문제가 발생하지 않으므로 내 솔루션을 공유하고 싶습니다.
Python 스크립트를 데몬화했습니다. 이를 통해 스크립트가 시작될 때 직렬 연결을 열고 10초마다 직렬 포트 데이터를 읽을 수 있습니다.
더 이상 과잉 지출이 없습니다.
스크립트의 코드는 다음과 같습니다GitHub에서
답변2
http://hintshop.ludvig.co.nz/show/pertant-names-usb-serial-devices/
IT가 도움을 주었고 즉각적인 해결책을 얻었습니다.