From: Jannik ZANDER Date: Thu, 23 Jun 2016 08:59:10 +0000 (+0200) Subject: Serial wired working X-Git-Url: https://git.zndr.dk/?a=commitdiff_plain;h=925322dfc3733f8598fdad332ad9d77040ff503a;p=dotfiles.git Serial wired working --- diff --git a/work/geni/geni.py b/work/geni/geni.py index 2874452..a4a2cab 100755 --- a/work/geni/geni.py +++ b/work/geni/geni.py @@ -17,7 +17,6 @@ import string # section: debugging {{{1 ###################################################### -#telegrams=[b'\x27\x0D\x22\x20\x0B\x03\x34\x35\x70\x02\x04\xBE\x71\x72\x73\xE5\x5B'] telegrams=[b'\xb7M\x012\x00\xc1\x01\x00\x00.\x0c\x13\x00\x00\x00\x00\x00d\x00\x00\x02X\x00\x02\x00\n'] telegrams.append(b"\x00<\x07\xd0\x00\x00\x1a,\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\x00\x00\x00\x00\x05\x8aC\x00D\x00E\x00F\x00\x05\x00\x15\xbd'\r! \x0b\x0345p\x02\x04\xbeqrs*\xfe$\x10 !\x0b\x06\x00\x00\xff\xff\x00\x00\x02\x04\x00\xff\xff\xff\x8b^&G\xf7 \n") telegrams.append(b"\xb7M\x013\x00\xc1\x01\x00\x00.\x0e&\x00\x00\x00\x1d\x00\x01\xb3.\x00\x00\x00\x00\x00\x00\x00\x1d\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x01,\x00\x00\x00\x00\x05\x8aC\x00D\x00E\x00F\x00\x05\x00o\xf4'\n") @@ -466,14 +465,14 @@ def process_telegram(line): else: line=line[ale:] # section: filtering {{{2 - if cl==5: - td,master,speed=dbg_speed(ids5,val5,ts,sa) +# if cl==5: +# td,master,speed=dbg_speed(ids5,val5,ts,sa) # crc=process_crc(line) return # section: main {{{1 ###################################################### - +telegram=b'\x27\x0D\x22\x20\x0B\x03\x34\x35\x70\x02\x04\xBE\x71\x72\x73\xE5\x5B' # section: serial {{{2 lsser=serial_ports() ser=serial.Serial() @@ -482,10 +481,10 @@ ser.baudrate=9600 ser.parity=serial.PARITY_NONE ser.stopbits=serial.STOPBITS_ONE ser.bytesize=serial.EIGHTBITS -ser.timeout=40 # msec +#ser.timeout=40 # msec ser.open() print("Connected to",repr(ser.portstr)) - +# DL_IDLE=0 DL_SENDING=1 @@ -493,18 +492,21 @@ DL_RECEIVING=2 state=DL_IDLE frame=bytearray() index=0 -while True: +try: + while True: +# byte,telegram=readbyte(telegram) byte=ser.read() - frame.append(byte) +# print(byte) + frame.extend(byte) if index==1: - framelen=byte+4 + framelen=ord(byte)+4 numbytes=framelen-1 state=DL_RECEIVING elif index==0: - print("START") +# print("START") pass if state==DL_RECEIVING: - print(numbytes) +# print(numbytes) numbytes=numbytes-1 if numbytes==0: if crc.verifyCrc(frame): @@ -513,10 +515,12 @@ while True: else: print("CRC error") state=DL_IDLE + frame=bytearray() index=0 - break # frame done + continue # frame done index=index+1 - +except KeyInterrupt: + pass ser.close() print("Disconnected") @@ -524,21 +528,21 @@ print("Disconnected") ###################################################### # Calculate timedelta -if len(td)==0: exit() -t0=td[0] -td[:]=[x-t0 for x in td] - -# Make a plot -fig=plt.figure() -plt.xlabel('time/s') -plt.ylabel('speed/upper') -plt.plot(td,speed[0],'green') -plt.plot(td,speed[1],'red') -plt.plot(td,speed[2],'blue') -plt.plot(td,speed[3],'magenta') -plt.legend('1234') -plt.plot(td,master,'black') -plt.title('multipump') -plt.show() -plt.close(fig) - +#if len(td)==0: exit() +#t0=td[0] +#td[:]=[x-t0 for x in td] +# +## Make a plot +#fig=plt.figure() +#plt.xlabel('time/s') +#plt.ylabel('speed/upper') +#plt.plot(td,speed[0],'green') +#plt.plot(td,speed[1],'red') +#plt.plot(td,speed[2],'blue') +#plt.plot(td,speed[3],'magenta') +#plt.legend('1234') +#plt.plot(td,master,'black') +#plt.title('multipump') +#plt.show() +#plt.close(fig) +#