Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import serial
- def checksum(array):
- checksum = (sum(DataArray) ^ 255) + 1
- checksum = hex(checksum)
- return checksum[-2:]
- def processbyte(byte):
- if byte.hex() != checksum(DataArray):
- DataArray.append(int.from_bytes(byte, byteorder='little'))
- else:
- print(f'MID: {str(DataArray[0]):4}', end=" ")
- print(f'Data: 0x{DataArray[1:].hex().upper():30}', end=" ")
- print(f'CS: 0x{checksum(DataArray).upper():3}')
- DataArray.clear()
- com = serial.Serial()
- com.port = "COM28"
- com.baudrate = 9600
- com.timeout= (1/9600)*22
- com.STOPBITS = 1
- com.PARITIES = 0
- com.set_buffer_size = 21
- com.interCharTimeout = 0.01
- DataArray = bytearray()
- if ~com.is_open:
- com.open()
- while(com.is_open):
- if(com.in_waiting):
- byte = com.read()
- processbyte(byte)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement