/// <summary> /// Update motor device information of Ev3 Brick by GetMotorPower command, /// especially motor output power. /// </summary> /// <param name="Command"></param> /// <param name="Brick"></param> public override void Update(ACommand Command, Ev3Brick Brick) { Debug.Assert(Command != null); Debug.Assert(Brick != null); if (Command is Command_10_01) { int Index = 0; int DataTopIndex = 4; for (Index = 0; Index < 4; Index++) { int DataIndex = DataTopIndex + Index * 2; byte Connection = Command.ResData[DataIndex++]; int Power = (int)((sbyte)(Command.ResData[DataIndex])); var Device = Brick.MotorDevice(Index); Device.ConnectedPort = (Ev3Device.OUTPORT)Index; if (0x00 == Connection) { Device.IsConnected = false; Device.Power = 0; } else { Device.IsConnected = true; Device.Power = Power; } } } }
/// <summary> /// Update motor device information of Ev3 Brick by GetMotors command. /// </summary> /// <param name="Command">GetMotors command.</param> /// <param name="Brick">Object to set data.</param> public override void Update(ACommand Command, Ev3Brick Brick) { Debug.Assert(Command != null); Debug.Assert(Brick != null); if (Command is Command_0C_00) { int Index = 0; int DataTopIndex = 4; for (Index = 0; Index < 4; Index++) { var Device = Brick.MotorDevice(Index); Device.ConnectedPort = (Ev3Device.OUTPORT)Index; DEVICE_TYPE DeviceType = DEVICE_TYPE.MOTOR_DEVICE_NO_DEVICE; byte Type = Command.ResData[DataTopIndex + Index]; bool HasValue = DeviceTypeDictionary.ContainsKey(Type); if (HasValue) { DeviceType = DeviceTypeDictionary[Type]; } else { DeviceType = DEVICE_TYPE.MOTOR_DEVICE_UNKNOWN; } Device.DeviceType = DeviceType; switch (DeviceType) { case DEVICE_TYPE.MOTOR_DEVICE_MEDIUM_MOTOR: case DEVICE_TYPE.MOTOR_DEVICE_LARGE_MOTOR: case DEVICE_TYPE.MOTOR_DEVICE_UNADJUSTED: Device.IsConnected = true; break; default: Device.IsConnected = false; break; } } } }