public ArduinoSession GetArduinoSession() { if (arduinoSession == null) { var connection = GetConnection(); var session = new ArduinoSession(connection); var firmware = session.GetFirmware(); if (firmware.MajorVersion >= 2) { session.ResetBoard(); //步进电机 session.CreateStepperMoveCompleteMonitor().Monitor(f => { GetStepperStep(f.DeviceNumber).Invoke(f.DeviceNumber); }); session.CreateReceivedStringMonitor().Monitor(f => { }); session.StepperConfiguration(0, new DeviceConfig { MotorInterface = DeviceConfig.MotorInterfaceType.Driver, StepOrPin1Number = 26, DirectionOrPin2Number = 28, EnablePinNumber = 24, InvertEnablePinNumber = true }); session.StepperEnable(0, true); session.StepperSetSpeed(0, 32767); session.StepperSetScceleration(0, 5000); arduinoSession = session; } else { session.Dispose(); throw new Exception("读取设备失败"); } } return(arduinoSession); }