/// <summary> /// 检验工序过站(值类型) /// </summary> /// <param name="_session"></param> /// <param name="_transData"></param> private void ExecuteTVC(MesSession _session, TransData _transData) { LogInfo log = null; //1、参数校验---EquipmentNumber--------------------------------- string equipmentID = string.Empty; if (!EmployeeComm.CheckEquipmentID(_session, _transData, out equipmentID, EmployeeName)) { return; } //2、参数校验---WorkOrder--------------------------------- string workOrder = string.Empty; if (!EmployeeComm.CheckWorkOrder(_session, _transData, out workOrder, EmployeeName, DataFrom.SQLite)) { return; } //3、参数校验---获取待检验数据并校验有效性 --------------------------------- decimal weight = ConvertHelper.ToDecimal(_transData.ProcessData, 0); if (weight <= 0) { log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{EmployeeName}】之称重检验接口失败>> 协议错误,请检查协议中过程数据是否为有效值(数值需大于0),当前过程数据:{_transData.ProcessData}。"); EmployeeComm.SendMsg(_session, _transData, CheckResult.NG); return; } if (!GlobalData.IsDebug) { //4、执行称重校验 --------------------------------- string apiStatus = string.Empty; CheckWeight(_session, _transData, weight, out apiStatus); //5、执行过站 if (!EmployeeComm.CheckRoute(_session, _transData, workOrder, equipmentID, apiStatus, EmployeeName)) { return; } //5.1、队列方式进行报工(如果记录了不良则无需进行第二次报工,因为记录不良时已经进行第一次报工了) if (apiStatus != "FAIL") { GlobalData.queueServerNDQ.EnqueueItem(new TestItemFlex(_session, _transData, equipmentID, EmployeeName, "103OUT")); } } //6、API执行成功 --------------------------------- EmployeeComm.SendMsg(_session, _transData, CheckResult.OK); }
/// <summary> /// 校验EquipmentID并返回 /// </summary> /// <param name="_session"></param> /// <param name="_transData"></param> /// <param name="equipmentID"></param> /// <returns></returns> public static bool CheckEquipmentID(MesSession _session, TransData _transData, out string equipmentID, string caller) { caller += "-获取设备编码"; equipmentID = string.Empty; META_DevLinkInfo info = BLLFactory <META_DevLink> .Instance.FindSingle($"DevCode='{_transData.DeviceCode}'"); if (info == null) { LogInfo log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{caller}】接口失败>> 参数错误,根据机台编码[{_transData.DeviceCode}] 获取设备编码失败,请检查SQLLite中是否配置机台映射关系。"); _transData.ProcessData = $"Failed to get the equipmentID by {_transData.DeviceCode},Check SQLite DB."; EmployeeComm.SendMsg(_session, _transData, CheckResult.NG); return(false); } //前工序校验是获取产品工艺类型 if (!GlobalData.IsDebug && _transData.FuncCode == "PRC") { DataTable dtR; DM_API.DM_SFCInterface Dm_Interface = new DM_API.DM_SFCInterface(); caller += "-获取工艺类型<用于识别设备编码>"; string[] arrSN = _transData.SN.Trim().Split('-'); bool bRet = GlobalData.RunTaskWithTimeoutDT <DataTable>(delegate { return(Dm_Interface.SFC_DM_SelectProductionProcess(arrSN[0])); }, out dtR, GlobalData.ApiTimeout, _session, _transData, arrSN[0], caller); if (!bRet) { return(false); } string type = DataTableHelper.GetCellValueinDT(dtR, 0, 1); info.ProcessType = type; BLLFactory <META_DevLink> .Instance.Update(info, info.ID); LogInfo log = new SocketService.LogInfo(_session, LogLevel.Info, $"[{_transData.SN}]获取当前机台工艺类型成功,工艺类型[{info.ProcessType}]【已缓存】 "); } switch (info.ProcessType) { case "PHEV-3.3KW": equipmentID = info.EquipmentID2; break; case "PHEV-6.6KW": equipmentID = info.EquipmentID3; break; default: equipmentID = info.EquipmentID1; break; } return(true); }
/// <summary> /// 校验Status并返回 /// </summary> /// <param name="_session"></param> /// <param name="_transData"></param> /// <param name="status"></param> /// <param name="caller"></param> /// <returns></returns> public static bool CheckApiStatus(MesSession _session, TransData _transData, out string apiStatus, string caller) { META_ParameterInfo info = BLLFactory <META_Parameter> .Instance.FindSingle($"Key='{_transData.Status}'"); apiStatus = "ERROR"; if (info == null || string.IsNullOrEmpty(info.Value)) { LogInfo log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{caller}】接口失败>> 参数错误,请检查SQLLite中是否配置WorkOrder参数,执行参数:{_transData.Status}。"); EmployeeComm.SendMsg(_session, _transData, CheckResult.NG); return(false); } apiStatus = info.Value; return(true); }
/// <summary> /// 校验WorkOrder并返回 /// </summary> /// <param name="_session"></param> /// <param name="_transData"></param> /// <param name="workOrder"></param> /// <param name="caller"></param> /// <returns></returns> public static bool CheckNormalParam(MesSession _session, TransData _transData, string paramKey, out string paramValue, string paramDisplay, string caller) { META_ParameterInfo info = BLLFactory <META_Parameter> .Instance.FindSingle($"Key='{paramKey}'"); if (info == null && string.IsNullOrEmpty(info.Value)) { paramValue = "ERROR"; LogInfo log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{caller}】接口失败>> 参数错误,获取{paramDisplay}失败,请检查SQLLite中是否缓存{paramDisplay},(请求参数:{paramKey})。"); _transData.ProcessData = $"Failed to get the cache barcode by [{paramKey}],Check SQLite DB."; EmployeeComm.SendMsg(_session, _transData, CheckResult.NG); return(false); } paramValue = info.Value; return(true); }
/// <summary> /// 校验ProcessData并返回 /// </summary> /// <param name="_session"></param> /// <param name="_transData"></param> /// <param name="status"></param> /// <param name="caller"></param> /// <returns></returns> public static bool CheckProcessData(MesSession _session, TransData _transData, out List <string> lstProcessData, string caller, Comparator comparator, int count) { lstProcessData = StringHelper.GetStrArray(_transData.ProcessData, ',', false); bool bCp = false; switch (comparator) { case Comparator.MoreThan: if (lstProcessData.Count > count) { bCp = true; } break; case Comparator.LessThan: if (lstProcessData.Count < count) { bCp = true; } break; case Comparator.Equal: if (lstProcessData.Count == count) { bCp = true; } break; case Comparator.NotEqual: if (lstProcessData.Count != count) { bCp = true; } break; } if (!bCp) { LogInfo log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{caller}】协议错误,当前协议中过程数据项应该是{EnumHelper.GetDescription(typeof(Comparator), comparator)}{count}项,当前过程数据({lstProcessData.Count} 项):{_transData.ProcessData}。"); _transData.ProcessData = $"Protocol error, procedure data should be {comparator} {count} items, current is {lstProcessData.Count} items, procedure data: {_transData.ProcessData}"; EmployeeComm.SendMsg(_session, _transData, CheckResult.NG); } return(bCp); }
/// <summary> /// 校验WorkOrder并返回(配置文件获取) /// </summary> /// <param name="_session"></param> /// <param name="_transData"></param> /// <param name="workOrder"></param> /// <param name="caller"></param> /// <returns></returns> public static bool CheckWorkOrder(MesSession _session, TransData _transData, out string workOrder, string caller, DataFrom getFrom) { workOrder = string.Empty; caller += "-获取工单编码"; META_ParameterInfo info = BLLFactory <META_Parameter> .Instance.FindSingle($"Key='WorkOrder'"); if (info == null && string.IsNullOrEmpty(info.Value)) { LogInfo log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{caller}】接口失败>> 参数错误,请检查SQLLite中是否配置WorkOrder参数。"); EmployeeComm.SendMsg(_session, _transData, CheckResult.NG); return(false); } switch (getFrom) { case DataFrom.SQLite: workOrder = info.Value; break; case DataFrom.SQLServer: DataTable dtR; DM_API.DM_SFCInterface Dm_Interface = new DM_API.DM_SFCInterface(); bool bRet = GlobalData.RunTaskWithTimeoutDT <DataTable>(delegate { return(DBHelper.GetWorkOrderRemain()); }, out dtR, GlobalData.ApiTimeout, _session, _transData, "空", caller); if (!bRet) { return(false); } workOrder = DataTableHelper.GetCellValueinDT(dtR, 0, "ReturnMsg"); info.Value = workOrder; BLLFactory <META_Parameter> .Instance.Update(info, info.ID); LogInfo log = new SocketService.LogInfo(_session, LogLevel.Info, $"[{_transData.SN}]执行【{caller}】接口成功,数据缓存本地成功,当前工单号:{workOrder}。"); break; } return(true); }
/// <summary> /// 新的连接 /// </summary> /// <param name="session"></param> protected override void OnNewSessionConnected(MesSession session) { base.OnNewSessionConnected(session); //设置连接别名 string remoteDeviceName = AppConfig.Instance().AppConfigGet(session.RemoteEndPoint.Address.ToString()); string localDeviceName = AppConfig.Instance().AppConfigGet(session.LocalEndPoint.Port.ToString()); if (!string.IsNullOrEmpty(remoteDeviceName)) { session.RemoteDeviceName = $"{remoteDeviceName} [{session.RemoteEndPoint}]"; } if (!string.IsNullOrEmpty(localDeviceName)) { session.LocalDeviceName = $"{localDeviceName} [{session.LocalEndPoint}]"; } //添加至客户端连接List GlobalData.ClientSessionList.Add(session); LogInfo log = new SocketService.LogInfo(session, LogLevel.Info, GlobalData.ClientConnect + session.RemoteEndPoint); //触发事件 DelegateState.NewSessionConnected?.Invoke(session); }
protected override void HandleUnknownRequest(MesRequestInfo requestInfo) { base.HandleUnknownRequest(requestInfo); LogInfo log = new SocketService.LogInfo(this, LogLevel.Error, $"未知请求,该功能码[{requestInfo.Key}]在服务中未注册,当前请求内容:{requestInfo.Body}。"); }
protected override void HandleException(Exception e) { base.HandleException(e); LogInfo log = new SocketService.LogInfo(this, LogLevel.Error, GlobalData.Exception + e.ToString()); }
protected override void OnStopped() { base.OnStopped(); LogInfo log = new SocketService.LogInfo(this, LogLevel.Info, GlobalData.ServerStop); }
public TransData ToTransData(string key, string body, string cmdFullText) { try { LogInfo log = null; if (body.Length == 0) { log = new SocketService.LogInfo(this.Session as MesSession, LogLevel.Info, GlobalData.Pre_Receive + body); log = new SocketService.LogInfo(this.Session as MesSession, LogLevel.Error, "协议解析出错,原因:发送协议内容为空."); SendError("The protocol is empty."); return(null); } string[] arrStr = body.Split(';'); TransData transData = new SocketService.TransData(); transData.FuncCode = arrStr[0]; switch (key) { case "HEA": #region 心跳 if (arrStr.Length != 4) { log = new SocketService.LogInfo(this.Session as MesSession, LogLevel.Info, GlobalData.Pre_Receive + body); log = new SocketService.LogInfo(this.Session as MesSession, LogLevel.Error, $"协议解析出错,原因:协议长度不对,(按分号分割,正确为4段),当前请求内容:{body}。"); SendError($"Parsing fail, should be 4 items, current is: [{body}]"); return(null); } transData.DeviceCode = arrStr[1]; transData.OpeIndex = arrStr[2]; transData.Status = arrStr[3]; #endregion log = new SocketService.LogInfo(this.Session as MesSession, LogLevel.Debug, GlobalData.Pre_Receive + body); break; default: #region 业务数据 if (arrStr.Length != 6) { log = new SocketService.LogInfo(this.Session as MesSession, LogLevel.Info, GlobalData.Pre_Receive + body); log = new SocketService.LogInfo(this.Session as MesSession, LogLevel.Error, $"协议解析出错,原因:协议长度不对,(按分号分割,正确为6段),当前请求内容:{body}。"); SendError($"Parsing fail, should be 6 items, current is: [{body}]"); return(null); } transData.DeviceCode = arrStr[1]; transData.OpeIndex = arrStr[2]; transData.SN = arrStr[3]; transData.ProcessData = arrStr[4]; transData.Status = arrStr[5]; #endregion log = new SocketService.LogInfo(this.Session as MesSession, LogLevel.Info, GlobalData.Pre_Receive + body); break; } return(transData); } catch (Exception e) { LogInfo log = new SocketService.LogInfo(this.Session as MesSession, LogLevel.Info, GlobalData.Pre_Receive + body); log = new SocketService.LogInfo(this.Session as MesSession, LogLevel.Error, $"协议解析出错,当前请求内容:{body};异常信息:{e.Message}。"); SendError($"Parsing fail, try catch, current is: [{body}]"); return(null); } }
public static bool RunTaskWithTimeoutDT <DataTableT>(Func <DataTable> TaskAction, out DataTable dtR, int TimeoutMillisecond, MesSession _session, TransData _transData, string actionParam, string caller, bool toPlc = true) { LogInfo log; Task <DataTable> backgroundTask; dtR = null; try { backgroundTask = Task.Factory.StartNew(TaskAction); backgroundTask.Wait(new TimeSpan(0, 0, 0, 0, TimeoutMillisecond)); } catch (AggregateException ex) { var failMessage = ex.Flatten().InnerException.Message; log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{caller}】接口超时(>{TimeoutMillisecond}ms),原因:{failMessage},执行参数:{actionParam}."); _transData.ProcessData = $"Mission Timeout({TimeoutMillisecond}ms) , Please check the database connection"; if (toPlc) { EmployeeComm.SendMsg(_session, _transData, CheckResult.NG); } return(false); } catch (Exception ex) { var failMessage = ex.Message; log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{caller}】接口超时(>{TimeoutMillisecond}ms),原因:{failMessage},执行参数:{actionParam}."); _transData.ProcessData = $"Mission Timeout({TimeoutMillisecond}ms) , Please check the database connection"; if (toPlc) { EmployeeComm.SendMsg(_session, _transData, CheckResult.NG); } return(false); } if (!backgroundTask.IsCompleted) { log = new SocketService.LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{caller}】接口超时(>{TimeoutMillisecond}ms),请检查网络状况或数据库连接配置文件是否正确,执行参数:{actionParam}."); _transData.ProcessData = $"Mission Timeout({TimeoutMillisecond}ms) , Please check the database connection"; if (toPlc) { EmployeeComm.SendMsg(_session, _transData, CheckResult.NG); } return(false); } // task succeeded dtR = backgroundTask.Result; // 判断API是否执行成功 --------------------------------- //string checkStatusR = DataTableHelper.GetCellValueinDT(dtR, 0, "CheckStatus"); //string checkMsgR = DataTableHelper.GetCellValueinDT(dtR, 0, "ReturnMsg"); string checkStatusR = DataTableHelper.GetCellValueinDT(dtR, 0, 0); string checkMsgR = DataTableHelper.GetCellValueinDT(dtR, 0, 1); if (checkStatusR == "-1") { log = new LogInfo(_session, LogLevel.Error, $"[{_transData.SN}]执行【{caller}】接口失败>> 接口返回({checkStatusR}---{checkMsgR}),执行参数:{actionParam}。"); _transData.ProcessData = $"Error:{checkMsgR}"; if (toPlc) { EmployeeComm.SendMsg(_session, _transData, CheckResult.NG); } return(false); } log = new LogInfo(_session, LogLevel.Info, $"[{_transData.SN}]执行【{caller}】接口成功>> 执行参数:{actionParam}。"); return(true); }