SHARE
TWEET

K-XC1 test

DeaD_EyE Aug 26th, 2019 (edited) 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2. """
  3. This script reads data from K-XC1 (https://www.rfbeam.ch/product?id=24)
  4. and prints the data to console.
  5. """
  6.  
  7. import serial
  8. import struct
  9.  
  10.  
  11. SYNC_LEN = 8
  12. DATA_LEN = 1024
  13. FRAME_LEN = SYNC_LEN + DATA_LEN
  14.  
  15. buffer = bytearray(FRAME_LEN)
  16. view = memoryview(buffer)
  17. sync = bytearray([0x24, 0x02, 0xa2, 0xe1, 0x5a, 0xd6, 0x19, 0x73])
  18.  
  19.  
  20. def reader(port):
  21.     with serial.Serial(port, baudrate=921600) as ser:
  22.         while True:
  23.             ser.readinto(buffer)
  24.             idx = buffer.find(sync)
  25.             if idx > 0:
  26.                 ser.read(FRAME_LEN + idx)
  27.             elif idx == 0:
  28.                 yield view[SYNC_LEN:]
  29.  
  30.  
  31. def printer(serial_port):
  32.     for frame in reader(serial_port):
  33.         data = struct.unpack('<512h', frame)
  34.         print(data)
  35.  
  36.  
  37. if __name__ == '__main__':
  38.     port = '/dev/ttyUSB1'
  39.     printer(port)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top