//每个对象持有一个端口 public StickObject(string f_ComPort) { SerialPortConfig.getSerialPortConfig().SetPortProperty(f_ComPort, "921600", "1", "8", "无"); m_MotorPort = SerialPortConfig.getSerialPortConfig().MotorConnect(); if (m_MotorPort == null) { return; } m_MotorPort.DataReceived += InspireMotorBroadcastMessage.MotorAResolver; m_MotorLeft = new InspireMotorFunction(1, m_MotorPort); m_MotorRight = new InspireMotorFunction(2, m_MotorPort); MessageBox.Show(f_ComPort + "链接成功", "Success"); }
public MoveObject(string f_ComPort) { SerialPortConfig.getSerialPortConfig().SetPortProperty(f_ComPort, "9600", "1", "8", "无"); m_MotorPort = SerialPortConfig.getSerialPortConfig().MotorConnect(); if (m_MotorPort == null) { return; } m_MotorPort.DataReceived += InspireMotorBroadcastMessage.MotorAResolver; MoveMotor = new VinceMotorFunction(1, m_MotorPort); MoveMotor.motorEnable(); Thread.Sleep(500); MoveMotor.setMotorVelocity(0); Thread.Sleep(500); MoveMotor.setMotorMode(MOTOR_MODE.VELOCITY); Thread.Sleep(500); MessageBox.Show(f_ComPort + "链接成功", "Success"); }