public static int GetPackCount(int packId) { int count = 0; try { using (var db = new Data.AppContext()) { count = db.Batteries.Count(o => o.PackId == packId && o.PackStatus == PackStatus.打包中); } } catch (Exception ex) { Running.StopRunAndShowMsg(ex); } return(count); }
public void Comm() { if (Arthur.App.Current.Option.RemainingMinutes <= 0) { return; } if (Current.MainMachine.IsAlive && Current.Option.IsBatteryScanReady && !Current.Option.IsAlreadyBatteryScan && Current.Option.Tray11_Id > 0) { //绑盘位电池已满,不扫码,直到出现新托盘再扫 if (ProcTrayManage.GetBatteryCount(Current.Option.Tray11_Id) >= Common.TRAY_BATTERY_COUNT) { Running.ShowErrorMsg("绑盘位扫码电池数超过最大值:" + Common.TRAY_BATTERY_COUNT); return; } Current.Option.IsAlreadyBatteryScan = true; var ret = this.Commor.Comm(this.ScanCommand, this.ReadTimeout); if (!ret.IsSucceed || ret.Data.ToString().StartsWith("NG")) { ret = this.Commor.Comm(this.ScanCommand, this.ReadTimeout); if (!ret.IsSucceed || ret.Data.ToString().StartsWith("NG")) { ret = this.Commor.Comm(this.ScanCommand, this.ReadTimeout); if (!ret.IsSucceed || ret.Data.ToString().StartsWith("NG")) { var msg = ret.Data.ToString().StartsWith("NG") ? "扫码NG" : " 扫码失败!" + ret.Msg; this.RealtimeStatus = msg; Current.MainMachine.Commor.Write("D433", (ushort)2); Running.ShowErrorMsg(this.Name + msg); this.IsAlive = false; return; } } } var code = ret.Data.ToString(); this.RealtimeStatus = "+" + code; Current.MainMachine.Commor.Write("D433", (ushort)1); this.IsAlive = true; //把电池条码保存进数据库 var saveRet = new Business.BatteryManage().Create(new Model.Battery() { Code = code }, true); if (saveRet.IsSucceed) { var t = new Thread(() => { //界面交替显示扫码状态 Thread.Sleep(2000); this.RealtimeStatus = "等待扫码..."; }); t.Start(); } else { Running.StopRunAndShowMsg(saveRet.Msg); } } }
public void Comm() { if (Arthur.App.Current.Option.RemainingMinutes <= 0) { return; } if (!Current.MainMachine.IsAlive) { return; } if (this == Current.BindTrayScaner && Current.Option.IsBindTrayScanReady && !Current.Option.IsAlreadyBindTrayScan) { LogHelper.WriteInfo("开始绑盘托盘扫码。。。"); var ret = this.Commor.Comm(this.ScanCommand, this.ReadTimeout); if (ret.IsSucceed) { var result = true; var code = ret.Data.ToString(); if (code.StartsWith("NR")) { var ret2 = this.Commor.Comm(this.ScanCommand, this.ReadTimeout); if (ret2.IsSucceed && !ret2.Data.ToString().StartsWith("NR")) { code = ret2.Data.ToString(); } else { result = false; LogHelper.WriteError(this.Name + " 扫码失败!"); Running.ShowErrorMsg(this.Name + " 扫码失败!"); } } if (result) { LogHelper.WriteInfo(this.Name + "扫码OK。。。"); this.RealtimeStatus = "+" + code; Current.MainMachine.Commor.Write("D434", (ushort)1); var saveRet = Result.Success; if (Current.Option.Tray11_Id < 1) { //把电池条码保存进数据库 saveRet = new Business.ProcTrayManage().Create(new Model.ProcTray() { Code = code }, true); Current.Option.Tray11_Id = (int)saveRet.Data; } if (saveRet.IsSucceed) { var t = new Thread(() => { //界面交替显示扫码状态 Thread.Sleep(2000); this.RealtimeStatus = "等待扫码..."; }); t.Start(); } else { Running.StopRunAndShowMsg(saveRet.Msg); } } else { LogHelper.WriteInfo(this.Name + "扫码NG。。。"); Current.MainMachine.Commor.Write("D434", (ushort)2); this.RealtimeStatus = "扫码失败!"; } this.IsAlive = true; } else { LogHelper.WriteInfo(this.Name + "扫码NG。。。"); Current.MainMachine.Commor.Write("D434", (ushort)2); this.RealtimeStatus = ret.Msg; this.IsAlive = false; } Current.Option.IsAlreadyBindTrayScan = true; } else if (this == Current.UnbindTrayScaner && Current.Option.IsUnbindTrayScanReady && !Current.Option.IsAlreadyUnbindTrayScan) { LogHelper.WriteInfo("开始解盘托盘扫码。。。"); var ret = this.Commor.Comm(this.ScanCommand, this.ReadTimeout); if (ret.IsSucceed) { var result = true; var code = ret.Data.ToString(); if (code.StartsWith("NR")) { var ret2 = this.Commor.Comm(this.ScanCommand, this.ReadTimeout); if (ret2.IsSucceed && !ret2.Data.ToString().StartsWith("NR")) { code = ret2.Data.ToString(); } else { result = false; LogHelper.WriteError(this.Name + " 扫码失败!"); Running.ShowErrorMsg(this.Name + " 扫码失败!"); } } if (result) { LogHelper.WriteInfo(this.Name + "扫码OK。。。"); this.RealtimeStatus = "+" + code; Current.MainMachine.Commor.Write("D435", (ushort)1); var saveRet = Result.Success; //逻辑处理 var procTrayId = GetObject.GetByCode <ProcTray>(code).Id; if (Current.Option.Tray21_Id < 1 || Current.Option.Tray21_Id != procTrayId) { Current.Option.Tray21_Id = procTrayId; } if (saveRet.IsSucceed) { var t = new Thread(() => { //界面交替显示扫码状态 Thread.Sleep(2000); this.RealtimeStatus = "等待扫码..."; }); t.Start(); } else { Running.StopRunAndShowMsg(saveRet.Msg); } } else { LogHelper.WriteInfo(this.Name + "扫码NG。。。"); Current.MainMachine.Commor.Write("D435", (ushort)(Common.PROJ_NO == "0079" ? 2 : 1)); this.RealtimeStatus = "扫码失败!"; } this.IsAlive = true; } else { LogHelper.WriteInfo(this.Name + "扫码NG。。。"); Current.MainMachine.Commor.Write("D435", (ushort)(Common.PROJ_NO == "0079" ? 2 : 1)); this.RealtimeStatus = ret.Msg; this.IsAlive = false; } Current.Option.IsAlreadyUnbindTrayScan = true; } }