I'm very new at this, so excuse the stupid questions. I have a RS232 level shifter connect to an external device, I use a bash script to send a handshake to this device every second and I expect a certain response before I can send data to it again. I have a python script that monitors /dev/ttyAMA0 and should write something to a file when the correct response is receive, below is my code
Code: Select all
from __future__ import print_function
import serial
serialport = serial.Serial("/dev/ttyAMA0", 38400, timeout=0.5)
f = open('talk.txt', 'w')
while True:
response = serialport.readlines()
print(response)
if "\x07\x07\x07\x07\x07\x07" in response:
print("yes")
print(response)
print("Handshake\n", file=f)
f.write('Handshake\n')
f.flush()
f.close()
Output from python script
Code: Select all
-pi:/opt/temp# python newserialtest.py
[]
[]
[]
[]
[]
[]
[]
[]
[]
['\x07\x07\x07\x07\x07\x07']
yes
['\x07\x07\x07\x07\x07\x07']
[]
[]
[]
Also, if I get a longer string, for example
Code: Select all
[]
[]
['\x02\x07\x07\x07\x07\x07\x07\x06\x08\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00']
[]
[]
[]ANY suggestions PLEASE, I'm out of ideas