Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- """
- This script reads data from K-XC1 (https://www.rfbeam.ch/product?id=24)
- and prints the data to console.
- """
- import serial
- import struct
- SYNC_LEN = 8
- DATA_LEN = 1024
- FRAME_LEN = SYNC_LEN + DATA_LEN
- buffer = bytearray(FRAME_LEN)
- view = memoryview(buffer)
- sync = bytearray([0x24, 0x02, 0xa2, 0xe1, 0x5a, 0xd6, 0x19, 0x73])
- def reader(port):
- with serial.Serial(port, baudrate=921600) as ser:
- while True:
- ser.readinto(buffer)
- idx = buffer.find(sync)
- if idx > 0:
- ser.read(FRAME_LEN + idx)
- elif idx == 0:
- yield view[SYNC_LEN:]
- def printer(serial_port):
- for frame in reader(serial_port):
- data = struct.unpack('<512h', frame)
- print(data)
- if __name__ == '__main__':
- port = '/dev/ttyUSB1'
- printer(port)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement