NanoBot
Mitglied
Ich versuche auf dem Mac (SL) das "OK" vom "AT" aufzufangen, aber es funktioniert nicht:
Er schreibt es zwar, aber wie bekomme ich das in eine Variable ?
Code:
import time
import serial
ser = serial.Serial(
port='/dev/tty.usbserial-xygeheim',
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=5
)
ser.open()
ser.isOpen()
ser.write('AT' + '\r\n')
out = ''
print 'out1 ='+out
#Soweit perfekt !
# let's wait one second before reading output (let's give device time to answer)
time.sleep(1)
while ser.inWaiting() > 0:
out += ser.read(1)
#s = ser.readline()
#s = ser.read(5)
#print 'Antwort: '+ s
print 'out2 ='+out
if out != '':
print "d>>" + out
if out == 'OK':
print 'Juhu es funktioniert!'
print 'out3 ='+out
ser.close()
exit()
Er schreibt es zwar, aber wie bekomme ich das in eine Variable ?
Code:
$ python AT.py
out1 =
out2 =AT
OK
d>>AT
OK
out3 =AT
OK