public override void ExecuteCommand(MesSession session, StringRequestInfo requestInfo) { TransmitData recvTransData = new TransmitData(); recvTransData = GlobalData.CheckRecvData(session, requestInfo, recvTransData); if (recvTransData == null) { return; } if (!string.IsNullOrWhiteSpace(recvTransData.EquipmentID)) { if (recvTransData.EquipmentID == GlobalData.SpDeviceID) { if (!string.IsNullOrWhiteSpace(recvTransData.SN)) { SpDeviceProcess(session, recvTransData); } else { GlobalData.KeyWordIsNullRecv(session, recvTransData, "SN"); session.Logger.Error("SN 为空!"); return; } } } else { GlobalData.KeyWordIsNullRecv(session, recvTransData, "EquipmentID"); session.Logger.Error("未能识别该设备!"); return; } }
/// <summary> /// 关键字段为空时处理方法 /// </summary> /// <param name="_session"></param> /// <param name="_transData"></param> /// <param name="_keyWord"></param> public static void KeyWordIsNullRecv(MesSession _session, TransmitData _transData, string _keyWord) { _transData.CheckResult = "NG"; _transData.Description = _keyWord + " is null Or white space."; string sendTransData = JsonHelper.SerializeObject(_transData); _session.Send(sendTransData); _session.Logger.Error(_transData.CheckResult + "---" + _transData.Description); }
protected override MesRequestInfo ResolveRequestInfo(ArraySegment <byte> header, byte[] bodyBuffer, int offset, int length) { TransmitData res = new TransmitData(); string entireFrame = BytesToHexStr(header.Array) + BytesToHexStr(bodyBuffer.CloneRange(offset, length)); res.Func = BytesToHexStr(header.Array); res.EquipmentID = BytesToHexStr(bodyBuffer.CloneRange(offset, length)); //res.DeviceLogicalCode = entireFrame.Substring(2, 8); //res.Seq = entireFrame.Substring(10, 4); //res.ControlCode = entireFrame.Substring(16, 2); //res.Length = entireFrame.Substring(18, 4); //int dataLen = int.Parse(HEXtoDEC(ReverseHexString(res.Length))); //res.Data = entireFrame.Substring(22, dataLen * 2); //res.Cs = entireFrame.Substring(22 + dataLen * 2, 2); return(new MesRequestInfo(res)); }
/// <summary> /// 上瓶机位业务逻辑处理:3-称重校验;4-是否继续上瓶判断 /// </summary> /// <param name="sN"></param> private void SpDeviceProcess(MesSession _session, TransmitData _transData) { //3-称重校验 bool weightIsOK = CheckWeight(_transData.SN, _transData.Items["aWeight"]); if (weightIsOK) { _transData.CheckResult = CheckResult.OK.ToString(); //4-是否继续上瓶判断 bool isContinue = IsContinue(_transData.WO); _transData.Items.Add("continue", isContinue.ToString()); //5-处理完成,过站 DM_SFCInterface DM_SFC = new DM_SFCInterface(); DataTable dt = DM_SFC.SFC_DM_CheckRoute(_transData.SN, _transData.EquipmentID, _transData.WO, "PASS");//FAIL string CheckStatus = dt.Rows[0][0].ToString().ToString(); string ReturnMsg = dt.Rows[0][1].ToString().ToString(); if (CheckStatus == "1") //过站成功,开始扣料 { DM_Bucklematerial bucklematerial = new DM_Bucklematerial(); bucklematerial.BuckleMaterialIn(_transData.SN, "ASM", _transData.EquipmentID + "-01"); } else { _transData.CheckResult = "ERROR"; _transData.Description = ReturnMsg; } } else { _transData.CheckResult = "NG"; _transData.Description = "error---query fail,please check SN."; } string sendTransData = JsonHelper.SerializeObject(_transData); _session.Send(sendTransData); _session.Logger.Info(_transData.CheckResult + "---" + _transData.Description); }
/// <summary> /// 上瓶机位业务逻辑处理:1-瓶身校验;2-基液灌装剂量下发 /// </summary> /// <param name="sN"></param> private void SpDeviceProcess(MesSession _session, TransmitData _transData) { //1-瓶身校验 bool specOK = CheckBotSpec(_transData.SN); if (specOK) { _transData.CheckResult = CheckResult.OK.ToString(); //2-基液灌装查询 string baseDose = GetBaseDose(_transData.WO); _transData.Items.Add("sWeight", baseDose); } else { _transData.CheckResult = CheckResult.NG.ToString(); _transData.Description = "Check failure by sn " + _transData.SN; } string sendTransData = JsonHelper.SerializeObject(_transData); _session.Send(sendTransData); _session.Logger.Info(_transData.CheckResult + "---" + _transData.Description); }
/// <summary> /// 校验接收数据是否正确 /// </summary> /// <param name="session"></param> /// <param name="requestInfo"></param> /// <param name="recvTransData"></param> /// <returns></returns> public static TransmitData CheckRecvData(MesSession session, StringRequestInfo requestInfo, TransmitData recvTransData) { try { if (requestInfo.Parameters.Count() == 1) { recvTransData = JsonHelper.DeserializeJsonToObject <TransmitData>(requestInfo.Body); } else { session.Logger.Error(GlobalData.ProtocolFormalError); return(null); } } catch (Exception e) { session.Logger.Error("json 序列化错误:" + e.Message + ",json字符串:" + requestInfo.Body); return(null); } return(recvTransData); }