//private void Client_NewPackageReceived(object sender, PackageEventArgs<MesPackageInfo> e) //{ // if (e.Package.TData != null) // { // switch (e.Package.Header) // { // case "ISR": // if (e.Package.TData.CheckResult == CheckResultCode.OK.ToString()) // { // ShowMessage("请开始扫描彩盒ID条码."); // } // else // { // ShowMessage("设备未具备开工条件."); // if (client != null) // { // client.Close(); // client = null; // } // } // break; // case "SNC": // ShowSNCheckResult(e.Package.TData.CheckResult); // if (e.Package.TData.CheckResult == CheckResultCode.OK.ToString()) // { // try // { // DataTable dt = SFCInterface.SFC_DM_CheckRoute(e.Package.TData.SN, GlobalData.EquipmentNO, e.Package.TData.WO, "PASS");//FAIL // string CheckStatus = dt.Rows[0][0].ToString().ToString(); // string ReturnMsg = dt.Rows[0][1].ToString().ToString(); // if (CheckStatus == "1") //成功 // { // ShowMessage("MES过站成功>>" + CheckStatus + ":" + ReturnMsg); // // 加载下一条 // GetNextSN(WO); // } // else // { // ShowMessage("MES过站失败>>" + CheckStatus + ":" + ReturnMsg); // } // } // catch (Exception ex) // { // ShowMessage("执行过站方法出错>>" + ex.Message); // } // } // else // { // for (int i = 5; i > 0; i--) // { // ShowMessage("彩盒SN校验失败,【" + i.ToString() + "】秒后重新下发."); // Thread.Sleep(1000); // } // ShowMessage("条码已重新下发."); // SendFactory(FunCode.SND.ToString()); // } // break; // default: // ShowMessage("未能识别该功能码:" + e.Package.Header); // break; // } // } // else // { // ShowMessage("提示:协议格式错误,协议格式:3位功能码 + 空格 + json字符串 + 回车换行符."); // } //} void MesServer_NewSessionConnected(MesSession session) { this.ShowMessage(session.RemoteEndPoint, "连接成功!"); mOnLineConnections.TryAdd(session.SessionID, session); this.ShowConnectionCount(mOnLineConnections.Count); ShowClientsMessage(mOnLineConnections); }
void NewSessionConnected(MesSession session) { ShowMessage(session.RemoteEndPoint, "连接成功!"); mOnLineConnections.TryAdd(session.SessionID, session); ShowConnectionCount(mOnLineConnections.Count); ShowClientsMessage("new", session); currentMesSession = session; }
/// <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 = CheckResult.ERROR.ToString(); _transData.Description = _keyWord + " is null or white space or format error ?"; string msg = _transData.Func + " " + JsonHelper.Serialize(_transData) + Environment.NewLine; _session.Send(msg); _session.Logger.Error(_transData.CheckResult + "---" + _transData.Description); }
void SessionClosed(MesSession session, global::SuperSocket.SocketBase.CloseReason value) { ShowMessage(session.RemoteEndPoint, "断开连接"); MesSession outMesSession; mOnLineConnections.TryRemove(session.SessionID, out outMesSession); ShowConnectionCount(mOnLineConnections.Count); ShowClientsMessage("close", session); currentMesSession = null; }
private void MesServer_SessionClosed(MesSession session, global::SuperSocket.SocketBase.CloseReason value) { this.ShowMessage(session.RemoteEndPoint, "断开连接"); MesSession outMesSession; mOnLineConnections.TryRemove(session.SessionID, out outMesSession); this.ShowConnectionCount(mOnLineConnections.Count); ShowClientsMessage(mOnLineConnections); //this.ShowConnectionCount(this.tcpServerEngine.SessionCount); }
private void ShowMessage(MesSession mesSession, MesRequestInfo requestInfo) { if (this.InvokeRequired) { this.BeginInvoke(new Action <MesSession, MesRequestInfo>(this.ShowMessage), mesSession, requestInfo); } else { ShowMessage(requestInfo.MsgColor, requestInfo.Msg); } }
private void ShowMessage(MesSession mesSession, MesRequestInfo requestInfo) { if (this.InvokeRequired) { this.BeginInvoke(new Action <MesSession, MesRequestInfo>(this.ShowMessage), mesSession, requestInfo); } else { log.Info(requestInfo.Msg); lblInfo.Text = requestInfo.Msg; lblInfo.ForeColor = requestInfo.MsgColor; } }
void MesServer_NewRequestReceived(MesSession session, StringRequestInfo requestInfo) { switch (requestInfo.Key) { case "echo": this.ShowMessage(session.RemoteEndPoint, requestInfo.Body); break; case "heartbeat": this.ShowMessage(session.RemoteEndPoint, requestInfo.Body); string msg = string.Format("push {0}", requestInfo.Body + Environment.NewLine); //一定要加上分隔符 byte[] bMsg = System.Text.Encoding.UTF8.GetBytes(msg); //消息使用UTF-8编码 session.Send(new ArraySegment <byte>(bMsg, 0, bMsg.Length)); break; default: this.ShowMessage(session.RemoteEndPoint, "未知的指令(error unknow command)"); break; } }
private void ShowClientsMessage(string status, MesSession mesSession) { if (this.InvokeRequired) { this.BeginInvoke(new Action <string, MesSession>(this.ShowClientsMessage), status, mesSession); } else { if (status == "close" && lblDeviceName.Tag.ToString() == mesSession.SessionID) { lblDeviceName.Text = ""; lblDeviceID.Text = ""; } else if (status == "new") { lblDeviceName.Text = "彩盒上料设备"; lblDeviceName.Tag = mesSession.SessionID; lblDeviceID.Text = mesSession.RemoteEndPoint.ToString(); } } }
// #endregion #region 客户端发送消息 private void SendFactory(string funCode) { try { MesSession mesSession = (MesSession)this.cmbClients.SelectedItem; if (mesSession == null) { ShowMessage("没有选中任何在线设备!"); return; } if (!mesSession.Connected) { ShowMessage("目标设备不在线!"); return; } TransmitData tData = null; switch (funCode) { case "ISR": ShowMessage("询问设备是否具备开工条件."); tData = new TransmitData(WO, GlobalData.EquipmentNO, null, null, null, null); break; case "SND": ShowMessage("彩盒规格校验ok,下发SN打印."); tData = new TransmitData(WO, GlobalData.EquipmentNO, SN, null, null, null); tData.Items.Add("url", GlobalData.URL); break; } string msg = funCode + GlobalData.SpacePoint + JsonHelper.Serialize(tData) + Environment.NewLine; //一定要加上分隔符 byte[] bMsg = System.Text.Encoding.UTF8.GetBytes(msg); //消息使用UTF-8编码 mesSession.Send(new ArraySegment <byte>(bMsg, 0, bMsg.Length)); } catch (Exception ee) { ShowMessage(ee.Message); } }
/// <summary> /// 校验接收数据是否正确 /// </summary> /// <param name="session"></param> /// <param name="requestInfo"></param> /// <param name="recvTransData"></param> /// <returns></returns> public static bool CheckMesRequestInfo(MesSession session, MesRequestInfo requestInfo, CheckType checkType) { if (requestInfo.TData == null) { GlobalData.KeyWordIsNullRecv(session, requestInfo.TData, "RequestInfo"); session.Logger.Error("RequestInfo is not json format !"); return(false); } if (string.IsNullOrWhiteSpace(requestInfo.TData.EquipmentID)) { GlobalData.KeyWordIsNullRecv(session, requestInfo.TData, "EquipmentID"); session.Logger.Error("EquipmentID error !"); return(false); } if (checkType == CheckType.DeviceSN && string.IsNullOrWhiteSpace(requestInfo.TData.SN)) { GlobalData.KeyWordIsNullRecv(session, requestInfo.TData, "SN"); session.Logger.Error("SN error !"); return(false); } return(true); }
//新的连接 private void NewSessionConnected(MesSession session) { DelegateState.MsgView?.Invoke(ColorHelper.MsgOrange, "请选择制令单."); HandleStop(); }
// 连接关闭 private void SessionClosed(MesSession session, global::SuperSocket.SocketBase.CloseReason value) { HandleInit(); }
// 新的连接 private void NewSessionConnected(MesSession session) { ShowMessage(ColorHelper.MsgGreen, session.RemoteEndPoint + " 连接成功!"); ShowDeviceInfo("new", session); }
// 连接关闭 private void SessionClosed(MesSession session, global::SuperSocket.SocketBase.CloseReason value) { ShowMessage(ColorHelper.MsgRed, session.RemoteEndPoint + " 断开连接!"); ShowDeviceInfo("close", session); }