텍스트 파일의 데이터와 직렬 입력에서 수집 한 데이터를 비교하려고하는 경우. 기본적으로 파일에서 '그레인'을 읽고 원래 보낸 사람이 올바르게 보낸 것인지 확인하기 위해 다시 보내주는 직렬 포트를 통해 파일을 보냅니다. 코드의 다른 부분에서다른 변수의 Python 확인
내가 사용
if "AK" in command:
Do something
이것은 AK 벌금 편지를 발견하고 나는 기본적으로 필요하지만 다음 부분에 대한로 전환 :
if grain in command:
Do Something
else:
Do Something else
몇 가지 이유 그것은 항상 다른 사람에게 떨어집니다. 시리얼 포트, 그레인 및 버퍼 (명령)를 모두 출력하므로 그레인 (22.4와 같은 숫자)이 명령에 있지만 if 루프에 등록되지 않은 것을 볼 수 있습니다.
단순한 아이디어는 무엇입니까?
문제의 코드 비트 : 행복하게 실행되지만 항상 하단의 AK 메시지 대신 IC 메시지를 보냅니다.
file = open("livedata.txt")
grain = file.readline()
air = file.readline()
file.close()
sending=True
send1=True
send2=False
while(sending==True):
loop=0
command=''
serialport.write("1RDRDR1R")
print ("DR Sent")
while (loop<30):
recieved = serialport.read()
command = command + recieved
loop = loop+1
if "BS" in command:
if "AK" in command:
while (send1==True):
serialport.write("1R"+grain+"1R")
print ("GrainTemp Sent")
loop=0
command=''
while (loop<30):
recieved = serialport.read()
command = command + recieved
loop = loop+1
if grain in command:
serialport.write("1RAKAK1R")
print ("GrainTemp AK Sent")
else:
serialport.write("1RICIC1R")
print ("GrainTemp IC Sent")
실제 코드를 게시하십시오 – MattDMo
변수의 실제 내용을 보려면'print'를 추가하거나 디버거를 사용하십시오. – Javier
send1을 수정하지 않으므로 직렬 포트에서 무한 루프를 읽는 중입니다. 처음 출력물이 AK이고 화면 스크롤이 빨리 읽을 수 있습니까? 더 중요한 것은, 직렬 포트가 올바르게 에코되고 있다는 것입니까? – sirlark