diff --git a/hardware_interface/serial_communication.py b/hardware_interface/serial_communication.py new file mode 100644 index 0000000..4359281 --- /dev/null +++ b/hardware_interface/serial_communication.py @@ -0,0 +1,20 @@ +import serial + +def open_serial_port(port, baudrate): + # Open a serial port using PySerial or PyVISA + + ser = serial.Serial(port=port, baudrate=baudrate, timeout=1) + + return ser + +def send_serial_data(ser, data): + # Send data over a serial port + + ser.write(data.encode()) + +def receive_serial_data(ser): + # Receive data over a serial port + + data = ser.read(ser.inWaiting()).decode() + + return data