public SettingLightViewModel(LightControlService lightControlService, StateStore stateStore, CoreConfig coreConfig) { StateStore = stateStore; CoreConfig = coreConfig; _responseTimeout = CoreConfig.ReponseTimeout; OnCommand = new DelegateCommand(() => { lightControlService.SetValue(coreConfig.LightValues); lightControlService.LightOn(); }); OffCommand = new DelegateCommand(() => { lightControlService.LightOff(); }); var temp = new byte[coreConfig.LightNum]; if (coreConfig.LightValues != null) { Array.Copy(coreConfig.LightValues, temp, coreConfig.LightNum); } LightNum = coreConfig.LightNum; if (coreConfig.LightValues != null) { for (int i = 0; i < LightNum; i++) { _lightValues[i].Value = temp[i]; } } RefreshPorts(); BaudRates = new int[] { 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200 }; Parities = Enum.GetValues(typeof(Parity)).Cast <Parity>(); DataBits = new int[] { 5, 6, 7, 8 }; StopBits = Enum.GetValues(typeof(StopBits)).Cast <StopBits>(); RefreshCommand = new DelegateCommand(() => { RefreshPorts(); }); ConnectCommand = new DelegateCommand(() => { if (CoreConfig.LightSerialInfo != null) { lightControlService.Connect(); } }); DisconnectCommand = new DelegateCommand(() => { lightControlService.Disconnect(); }); }
public CommunicationViewModel( GrabService grabService, LightControlService lightControlService, HostCommService hostCommService, InspectService inspectService, StateStore stateStore, CoreConfig coreConfig, CancellationToken token) { _stateStore = stateStore; Task.Run(async() => { while (token.IsCancellationRequested == false) { _stateStore.HostInfo = GetConnectionInfo(hostCommService.IsConnected()); _stateStore.InspectorInfo = GetConnectionInfo(inspectService.IsConnected()); _stateStore.CameraInfo = GetConnectionInfo(grabService.IsConnected()); _stateStore.LightInfo = GetConnectionInfo(lightControlService.IsConnected()); await Task.Delay(coreConfig.CommCheckDelay).ConfigureAwait(false); } }); }
public ControlViewModel( GrabService grabService, LightControlService lightControlService, InspectService inspectService, StateStore stateStore, CoreConfig coreConfig) { _stateStore = stateStore; GrabCommand = new DelegateCommand(async() => { lightControlService.SetValue(coreConfig.LightValues); lightControlService.LightOn(); var grabInfo = await grabService.Grab(); lightControlService.LightOff(); //if (grabInfo != null && coreConfig.UseInspector && stateStore.IsManualEnabled) // inspectService.Inspect(grabInfo.Value); //if (lightControlService.SetValue(coreConfig.LightValues) && lightControlService.LightOn()) //{ // var grabInfo = await grabService.Grab(); // lightControlService.LightOff(); // if (grabInfo != null && coreConfig.UseInspector && stateStore.IsManualEnabled) // inspectService.Inspect(grabInfo.Value); //} }); LiveCommand = new DelegateCommand(() => { lightControlService.SetValue(coreConfig.LightValues); lightControlService.LightOn(); grabService.StartGrab(); //if (lightControlService.SetValue(coreConfig.LightValues) && lightControlService.LightOn()) //if (inspectService.Inspected != null) //{ // List<SubResult> subResults = new List<SubResult>(); // subResults.Add(new SubResult(@"Pass, C:\Projects\KT_Interface_20210602\KT_Interface_20210602\KT_Interface\bin\Debug\Temp\1234_20210408120030.Bmp")); // subResults.Add(new SubResult(@"Fail, C:\Projects\KT_Interface_20210602\KT_Interface_20210602\KT_Interface\bin\Debug\Temp\2345_20210408124853.Bmp")); // inspectService.Inspected(new InspectResult(EJudgement.Pass, subResults)); //} StateStore.IsLiveMode = true; }); StopCommand = new DelegateCommand(() => { grabService.Stop(); lightControlService.LightOff(); StateStore.IsLiveMode = false; }); ExitCommand = new DelegateCommand(() => { Application.Current.Shutdown(); }); }