barsalo221 / Pacman

pacman game
1 stars 0 forks source link

Connect to com line for write erase #1

Open barsalo221 opened 2 months ago

barsalo221 commented 2 months ago

חיבור למתג דרך com line

import serial import time

def connect_to_switch(port, baudrate, commands): try:

ser = serial.Serial(port, baudrate, timeout=1)

time.sleep(2)

    for command in commands:
        ser.write((command + '\n').encode())  
        time.sleep(1)  # Give some time for the command to execute

output = ser.read(ser.inWaiting()).decode()
print(f"Executing command: {command}") print(output)

    ser.close()

except serial.SerialException as e:
    print(f"Error: {e}")

if name == "main": serial_port = "/dev/ttyUSB0"
baudrate = 9600 baudrate commands = [ "Test" ]

connect_to_switch(serial_port, baudrate, commands)
barsalo221 commented 2 months ago

Code