Guest User

Untitled

a guest
Oct 8th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. import serial
  2. import time
  3. import array as arr
  4.  
  5. STX = 2
  6. ETX = 3
  7.  
  8. ser = serial.Serial(
  9.     port='COM2',\
  10.     baudrate=9600,\
  11.     parity=serial.PARITY_NONE,\
  12.     stopbits=serial.STOPBITS_ONE,\
  13.     bytesize=serial.EIGHTBITS,\
  14.         timeout=0)
  15.  
  16. print("connected to: " + ser.portstr)
  17.  
  18. #this will store the line
  19. val = []
  20. res = bytearray()
  21. readString = 0
  22. while True:
  23.     read = bytes(ser.read(2))
  24.     #print(read)
  25.     if read == b'\x03':
  26.         readString=0
  27.         ## TODO:
  28.         print(res)
  29.         print(res).decode("CP852")
  30.  
  31.     else:
  32.         if read == b'\x02':
  33.             res = []
  34.             readString = 1
  35.         else:
  36.             res += read
  37.  
  38.  
  39. ser.close()
  40.  
Advertisement
Add Comment
Please, Sign In to add comment