import serial #imports the serial library... ser = serial.Serial('COM8', 9600, timeout=1) #create basic port connection object... ser.close() #close port to keep it available to other applications... def connect(): #explicitly reconnect to serial port created above... if ser.isOpen() == False: ser.open() print("connected to robot...") return else: print("already connected...") return return def disconnect(): #explicitly reconnect to serial port created above... if ser.isOpen() == True: ser.close() print("disconnected from robot...") return else: print("already disconnected...") return return def fwd(): #send command to go forward... if ser.isOpen() == False: print("not connected to a robot...") return else: ser.write("a") ser.readline() return return def rev(): #send command to go reverse... if ser.isOpen() == False: print("not connected to a robot...") return else: ser.write("b") ser.readline() return return def stop(): #send command to stop... if ser.isOpen() == False: print("not connected to a robot...") return else: ser.write("c") ser.readline() return return