Open barsalo221 opened 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)
Code
חיבור למתג דרך com line
import serial import time
def connect_to_switch(port, baudrate, commands): try:
ser = serial.Serial(port, baudrate, timeout=1)
time.sleep(2)
output = ser.read(ser.inWaiting()).decode()
print(f"Executing command: {command}") print(output)
if name == "main": serial_port = "/dev/ttyUSB0"
baudrate = 9600 baudrate commands = [ "Test" ]