Skip to content

Commit

Permalink
Create serial_communication.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored May 11, 2024
1 parent 4ff9525 commit 5c670fc
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions hardware_interface/serial_communication.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5c670fc

Please sign in to comment.