/// <summary> /// Timer dispatcher to update by Ev3Brick data. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void UpdateTimerEvent(object sender, EventArgs e) { try { this.UpdateTimer.Stop(); var Updater = new BrickDataUpdater(); Updater.UpdateViewModel(this); } finally { this.UpdateTimer.Start(); } }
public void BrickDataUpdater_UpdateViewModel_Test_001() { var Updater = new BrickDataUpdater(); var ViewModel = new Ev3ControllerMainViewModel(); var MotorDevice = new Ev3MotorDevice(); var SensorDevice = new Ev3SensorDevice(); var Brick = Ev3Brick.GetInstance(); for (int index = 0; index < 4; index++) { ViewModel.MotorViewModelArray[index] = new Ev3MotorDeviceViewModel(); ViewModel.SensorViewModelArray[index] = new Ev3SensorDeviceViewModel(); } MotorDevice.ConnectedPort = Ev3Device.OUTPORT.OUTPORT_A; MotorDevice.DeviceType = Ev3MotorDevice.DEVICE_TYPE.MOTOR_DEVICE_LARGE_MOTOR; MotorDevice.Power = 10; Brick.MotorDeviceArray[0] = MotorDevice; SensorDevice.ConnectedPort = Ev3Device.INPORT.INPORT_1; SensorDevice.DeviceType = Ev3SensorDevice.DEVICE_TYPE.SENSOR_DEVICE_COLOR; SensorDevice.Value1 = 10; SensorDevice.Value2 = 11; SensorDevice.Value3 = 12; Brick.SensorDeviceArray[0] = SensorDevice; Updater.UpdateViewModel(ViewModel); Assert.IsTrue(ViewModel.MotorViewModelArray[0].IsConnected); Assert.AreEqual("PORT_A", ViewModel.MotorViewModelArray[0].PortName); Assert.AreEqual("LARGE MOTOR", ViewModel.MotorViewModelArray[0].DeviceName); Assert.AreEqual(10, ViewModel.MotorViewModelArray[0].CurrentOutput); Assert.AreEqual("%", ViewModel.MotorViewModelArray[0].CurrentOutputUnit); Assert.IsFalse(ViewModel.MotorViewModelArray[1].IsConnected); Assert.IsFalse(ViewModel.MotorViewModelArray[2].IsConnected); Assert.IsFalse(ViewModel.MotorViewModelArray[3].IsConnected); Assert.IsTrue(ViewModel.SensorViewModelArray[0].IsConnected); Assert.AreEqual("PORT_1", ViewModel.SensorViewModelArray[0].PortName); Assert.AreEqual("COLOR", ViewModel.SensorViewModelArray[0].DeviceName); Assert.AreEqual(10, ViewModel.SensorViewModelArray[0].SensorValue1); Assert.AreEqual(11, ViewModel.SensorViewModelArray[0].SensorValue2); Assert.AreEqual(12, ViewModel.SensorViewModelArray[0].SensorValue3); Assert.AreEqual("", ViewModel.SensorViewModelArray[0].SensorValue1Unit); Assert.AreEqual("", ViewModel.SensorViewModelArray[0].SensorValue2Unit); Assert.AreEqual("", ViewModel.SensorViewModelArray[0].SensorValue3Unit); Assert.IsFalse(ViewModel.SensorViewModelArray[1].IsConnected); Assert.IsFalse(ViewModel.SensorViewModelArray[2].IsConnected); Assert.IsFalse(ViewModel.SensorViewModelArray[3].IsConnected); }