/// <summary> /// Sets the state of the motor. This only works if you are in Serial/USB input mode. /// </summary> /// <param name="speed"> /// If direction is Forward or Reverse, speed is a number from 0 to 3200. /// If direction is Brake, speed is a number from 0 to 32. /// </param> /// <param name="direction"> /// The direction to drive the motor in: Forward, Reverse, or Brake. /// </param> private void setSpeed(UInt16 speed, SmcDirection direction) { // NOTE: This should be the same as the logic in the firmware (cmdSetSpeed). if (0 != (direction & SmcDirection.Brake)) { if (speed > 32) { throw new ArgumentOutOfRangeException("speed", "When braking, speed parameter must be between 0 and 32."); } } else { if (speed > 3200) { throw new ArgumentOutOfRangeException("speed", "Speed parameter must be between 0 and 3200."); } } try { controlTransfer(0x40, (Byte)SmcRequest.SetSpeed, speed, (Byte)direction); } catch (Exception exception) { throw new Exception("There was an error setting the speed.", exception); } }