/// <summary> /// Sets the busy. /// </summary> /// <param name="busy">If set to <c>true</c> busy.</param> private void SetBusy(bool busy) { _cameraBusy = busy; // set camera busy Busy?.Invoke(this, _cameraBusy); }
private void OnTimerElapsed(object sender, ElapsedEventArgs args) { try { IdleScanAnalysis analysis = new IdleScanAnalysis(this); Scan?.Invoke(this, analysis); try { if (analysis.Busy) { IdleCount = 0; Busy?.Invoke(this, analysis); } else { IdleCount++; Idle?.Invoke(this, analysis); } } catch (Exception e) { EventLog.WriteEntry(e.ToString(), EventLogEntryType.Error, 18); analysis.Error = true; } Eval?.Invoke(this, analysis); } catch (Exception e) { EventLog.WriteEntry(e.ToString(), EventLogEntryType.Error, 19); } }
/// <summary> /// Notifies the busy. /// </summary> /// <param name="sender">Sender.</param> /// <param name="busy">If set to <c>true</c> busy.</param> public void NotifyBusy(object sender, bool busy) { Busy?.Invoke(this, busy); }
/// <summary> /// Takes the photo. /// </summary> public void TakePhoto() { if (_context != null && _cameraDevice != null) { try { Busy?.Invoke(this, true); if (_mediaSoundLoaded) { _mediaSound.Play(MediaActionSoundType.ShutterClick); } // Pick the best JPEG size that can be captures with this CameraDevice var characteristics = _manager.GetCameraCharacteristics(_cameraDevice.Id); Size[] jpegSizes = null; if (characteristics != null) { jpegSizes = ((StreamConfigurationMap)characteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap)).GetOutputSizes((int)ImageFormatType.RawSensor); } int width = 640; int height = 480; if (jpegSizes != null && jpegSizes.Length > 0) { width = jpegSizes[0].Width; height = jpegSizes[0].Height; } // We use an ImageReader to get a JPEG from CameraDevice // Here, we create a new ImageReader and prepare its Surface as an output from the camera var reader = ImageReader.NewInstance(width, height, ImageFormatType.Jpeg, 1); var outputSurfaces = new List <Surface>(2); outputSurfaces.Add(reader.Surface); outputSurfaces.Add(new Surface(_viewSurface)); CaptureRequest.Builder captureBuilder = _cameraDevice.CreateCaptureRequest(CameraTemplate.StillCapture); captureBuilder.AddTarget(reader.Surface); captureBuilder.Set(CaptureRequest.ControlMode, new Integer((int)ControlMode.Auto)); // Orientation var windowManager = _context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>(); SurfaceOrientation rotation = windowManager.DefaultDisplay.Rotation; captureBuilder.Set(CaptureRequest.JpegOrientation, new Integer(ORIENTATIONS.Get((int)rotation))); // This listener is called when an image is ready in ImageReader ImageAvailableListener readerListener = new ImageAvailableListener(); readerListener.ImageProcessingCompleted += (sender, e) => { Photo?.Invoke(this, e); }; // We create a Handler since we want to handle the resulting JPEG in a background thread HandlerThread thread = new HandlerThread("CameraPicture"); thread.Start(); Handler backgroundHandler = new Handler(thread.Looper); reader.SetOnImageAvailableListener(readerListener, backgroundHandler); var captureListener = new CameraCaptureListener(); captureListener.PhotoComplete += (sender, e) => { Busy?.Invoke(this, false); StartPreview(); }; _cameraDevice.CreateCaptureSession(outputSurfaces, new CameraCaptureStateListener() { OnConfiguredAction = (CameraCaptureSession session) => { try { _previewSession = session; session.Capture(captureBuilder.Build(), captureListener, backgroundHandler); } catch (CameraAccessException ex) { Log.WriteLine(LogPriority.Info, "Capture Session error: ", ex.ToString()); } } }, backgroundHandler); } catch (CameraAccessException error) { Log.WriteLine(LogPriority.Error, error.Source, error.Message); } catch (Java.Lang.Exception error) { Log.WriteLine(LogPriority.Error, error.Source, error.Message); } } }
protected void OnBusy(string str) { Busy?.Invoke(this, str); }
internal async void ProcessAsync(object sender, EventArgs e) { try { if (!Enabled) { return; } Logger.Debug("{0}光栅触发", scaleOperator.Name); if (IsBusy) { return; } IsBusy = true; Busy?.Invoke(this, new EventArgs()); await scaleOperator.SwitchRelayAsync(false);//turn red double weight = 0; GetWtResponse resp = null; for (int i = 1; i <= 5; i++) { Logger.Debug("[{0}]请求重量", scaleOperator.Name); resp = await scaleOperator.RestClient.GetWtAsync(scaleOperator.ScaleIP, scaleOperator.InOrOut.ToString()); Logger.Debug("[{0}]返回重量{1}", scaleOperator.Name, resp.wt_num); /*GetWtResponse resp = new GetWtResponse() * { * status = "1", * tk_no = "辽A 88888888", * wt_num = "1000.88" * };*/ if (resp.status == "0") { //Progress?.Invoke(this, new ProgressEventArgs("请求重量失败")); Logger.Warn("称重失败"); await Task.Delay(1000); continue; } var w = Convert.ToDouble(resp.wt_num); if (w > 1000) { Logger.Debug("称重大于1000"); weight = w; break; } await Task.Delay(1000); } if (weight < 1000) { Logger.Debug("称重小于1000, 开始抬杆"); Logger.Debug("[{0}]请求抬杆", scaleOperator.Name); GatePassResponse gpResp = await scaleOperator.RestClient.GatePassAsync(scaleOperator.ScaleIP, scaleOperator.InOrOut.ToString(), resp.tk_no, resp.wt_num); Logger.Debug("[{0}]返回抬杆", scaleOperator.Name); /*GatePassResponse gpResp = new GatePassResponse() * { * status = 1 * };*/ if (gpResp.status == "0")//抬杆失败 { //Progress?.Invoke(this, new ProgressEventArgs("抬杆失败")); Logger.Warn("抬杆失败:" + gpResp.reason); //SwitchRelay(false);//no need to call this, it's already red } else if (gpResp.status == "1") { Logger.Info("抬杆成功"); //Progress?.Invoke(this, new ProgressEventArgs("抬杆成功")); //SwitchRelay(true); } FakeCar?.Invoke(this, new EventArgs()); } } catch (Exception ex) { Error?.Invoke(this, new EventArgs()); Logger.Debug("处理前光栅事件发生异常:{0}", ex.Message); } finally { IsBusy = false; } }
private void OnBusy(object sender, EventArgs e) { Busy?.Invoke(this, new EventArgs()); _idleTimer.Stop(); }
internal async void ProcessAsync(object sender, EventArgs e) { try { if (!Enabled) { return; } Logger.Debug("{0}按钮触发", scaleOperator.Name); if (IsBusy) { return; } IsBusy = true; //Progress?.Invoke(this, new ProgressEventArgs("开始工作")); Logger.Debug("开始工作"); Busy?.Invoke(this, new EventArgs()); if (!scaleOperator.IsGratingsOff()) { var config = new LEDMessageShowConfig { FontSize = 0, ShowStyle = 3, ShowSpeed = 8 }; scaleOperator.Display("调整车辆", config); NeedAdjust?.Invoke(this, new EventArgs()); return; } //call remote service to get weight and plate number //Progress?.Invoke(this, new ProgressEventArgs("正在请求重量")); Logger.Debug("[{0}]请求重量", scaleOperator.Name); GetWtResponse resp = await scaleOperator.RestClient.GetWtAsync(scaleOperator.ScaleIP, scaleOperator.InOrOut.ToString()); Logger.Debug("[{0}]返回重量{1}", scaleOperator.Name, resp.wt_num); /*GetWtResponse resp = new GetWtResponse() * { * status = 1, * tk_no = "辽A 88888888", * wt_num = 888.88 * };*/ if (resp.status == "0") { //Progress?.Invoke(this, new ProgressEventArgs("请求重量失败")); Logger.Warn("称重失败"); return; } //Progress?.Invoke(this, new ProgressEventArgs("正在输出到显示屏")); string text = String.Format(scaleOperator.LEDOptions.CPZLMessage.Template, resp.tk_no, resp.wt_num); if (!scaleOperator.Display(text, scaleOperator.LEDOptions.CPZLMessage.ShowConfig)) { //Progress?.Invoke(this, new ProgressEventArgs("输出到显示屏失败")); Logger.Warn("LED显示失败"); //return; } //Progress?.Invoke(this, new ProgressEventArgs("正在抬杆")); Logger.Debug("[{0}]请求抬杆", scaleOperator.Name); GatePassResponse gpResp = await scaleOperator.RestClient.GatePassAsync(scaleOperator.ScaleIP, scaleOperator.InOrOut.ToString(), resp.tk_no, resp.wt_num); Logger.Debug("[{0}]返回抬杆", scaleOperator.Name); /*GatePassResponse gpResp = new GatePassResponse() * { * status = 1 * };*/ if (gpResp.status == "0")//抬杆失败 { //Progress?.Invoke(this, new ProgressEventArgs("抬杆失败")); Logger.Warn("抬杆失败:" + gpResp.reason); //SwitchRelay(false);//no need to call this, it's already red return; } Logger.Info("抬杆成功:"); //Progress?.Invoke(this, new ProgressEventArgs("抬杆成功")); Succeed?.Invoke(this, new EventArgs()); } catch (Exception ex) { //Progress?.Invoke(this, new ProgressEventArgs("发生错误:" + ex.Message)); Logger.Warn("{0}上的本次操作失败:{1}", scaleOperator.Name, ex.ToString()); } finally { IsBusy = false; } }
public BusyIndicator() { Busy.Invoke(this, EventArgs.Empty); }