예제 #1
0
            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;
                }
            }
예제 #2
0
            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;
                }
            }