giammo

script_KF1840

Sep 28th, 2020 (edited)
911
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python3
  2. import serial
  3. import binascii
  4.  
  5. ser = serial.Serial('/dev/ttyUSB1', 19200, bytesize=8, parity='N', stopbits=1, timeout=1)
  6.  
  7. if ser.is_open:
  8.     print(ser.name)
  9.     packet = bytearray()
  10.     packet.append(0xBE) # Magic Code
  11.     packet.append(0x07) # Length
  12.     packet.append(0x00) # Monitor ID
  13.     packet.append(0x67) # Cmd type
  14.     packet.append(0x23) # Cmd code
  15.     packet.append(0x00) # Cmd Value
  16.     packet.append(0x1D) # Check sum
  17.     ser.write(packet)
  18.     ser.flush()
  19.  
  20.     response = ser.readline()
  21.     #print( "Response byte => ", response )
  22.  
  23.     hex_string = response.hex()[2:]
  24.     #print( "hex_string => ", hex_string )
  25.     #print( "Response => ", bytes.fromhex(hex_string).decode('utf-8') )
  26.     print( binascii.hexlify(response) )
  27.  
  28.     ser.close()
  29.  
  30.  
  31. '''
  32. OUTPUT del comando "GET LANGUAGE"
  33. /dev/ttyUSB1
  34. Response =>  A!
  35. b'be07004123041d'
  36. '''
RAW Paste Data