import serial, time, pty, os, threading import busio from digitalio import DigitalInOut, Direction, Pull import board #import adafruit_rfm69 import adafruit_rfm9x CS = DigitalInOut(board.CE1) RESET = DigitalInOut(board.D25) spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) #rfm = adafruit_rfm69.RFM69(spi, CS, RESET, 868.0) rfm = adafruit_rfm9x.RFM9x(spi, CS, RESET, 868.0, baudrate=20000000) def serial_port_reader(ser, rfm): while True: ser_data = bytearray() while ser.inWaiting() > 0 and len(ser_data) <= packet_len: recieved_byte = ser.read(1) ser_data += recieved_byte if ser_data == b'': pass else: print(f'Received serial data: {ser_data}') rfm.send(ser_data) def serial_port_writer(ser, rfm): while True: packet = None packet = rfm.receive() if packet is None: pass else: print(f'Received lora RSSI: {rfm.last_rssi} SNR: {rfm.last_snr} data: {packet}') ser.write(packet) baudrate = 115200 packet_len = 251 master, slave = pty.openpty() port_name = os.ttyname(slave) print("Serieller Port: %s" % port_name) ser = serial.Serial(port_name, baudrate=baudrate) reader_thread = threading.Thread(target=serial_port_reader, args=(ser,rfm), daemon=True) reader_thread.start() writer_thread = threading.Thread(target=serial_port_writer, args=(ser,rfm), daemon=True) writer_thread.start() try: while True: pass except KeyboardInterrupt: print("Programm durch Benutzer unterbrochen.") finally: virtual_serial_port.close() reader_thread.join() writer_thread.join()