//建立Socket连接 public bool Startup() { try { return(OSrmSocket.Connect(m_serverIP, m_serverPort)); } catch (Exception ex) { log.WriteLog(m_strSRMNo + ": CRL CRLSRMControlB Connection Error!" + ex.Message); return(false); } }
public CRLPLCControl(string ipaddress, int port) { ServerAddr = ipaddress; ServerPortRecv = port; try { //订阅一个Socket收到数据的事件 PLCSocket.PlcNotify += new PLCNotify(PLCSocket_Notify); } catch (Exception ex) { log.WriteLog("PLC_Notify初始化函数异常" + ex.Message); } }
private void HandleRecvMsgRecord(byte[] data) { //处理分离出的信息记录 try { byte[] Buffer; switch ((int)data[7]) { //Normal Message case 1: { Buffer = new byte[data.Length - 8]; Array.Copy(data, 8, Buffer, 0, data.Length - 8); HandleRecvMsg(Buffer); break; } //Disconnect Link case 2: { break; } //Heart-Beat Poll case 4: { nt8000.Send(PackMsg(5, new Byte[0])); break; } //Heart-Beat Ack case 5: { break; } } } catch (Exception ex) { log.WriteLog("HandleRecvMsgRecord异常:" + ex.Message); } }
public CRLSRMControlB(string strsrmno, string ipaddress, int port)//构造函数 { m_serverIP = ipaddress; m_serverPort = port; m_strSRMNo = strsrmno; log = new LOG.Log("--" + m_strSRMNo + "~" + port.ToString(), ".\\卫星小车报文日志\\"); try { //订阅一个Socket收到数据的事件 OSrmSocket.Notify += new NotifyCommandHander(OSrmSocket_Notify);// } catch (Exception ex) { log.WriteLog(m_strSRMNo + ": SRM_Notify初始化函数异常" + ex.Message); } }
private void OSRM_AnalyseMessageEvent(string CommandType, object msg) { CRCObjectB findcob = crclistB.Find( delegate(CRCObjectB info) { return(info.ScNo == m_strSRMNo && info.Port == int.Parse(m_strport)); } ); if (m_strport == "4000" && CommandType == "RecvData") //if (m_strport == "80" && CommandType == "RecvData") { if (findcob != null) { findcob.connectstatus = (findcob.connectstatus == 1 ? 2 : 1); } crcb.UpdateCRCStatus(m_strSRMNo, msg.ToString(), aisle.ToString()); if (!string.IsNullOrEmpty(crcb.GetAlarmInfo(m_strSRMNo, "", false))) { log.WriteLog(crcb.GetAlarmInfo(m_strSRMNo, "", false)); } if (ENotifyTypeEventHandler != null) { ENotifyTypeEventHandler(m_strSRMNo, m_strport, CommandType, msg); } } else if (m_strport == "6000" && CommandType == "RecvData") { crcb.GetAlarmInfo(m_strSRMNo, msg.ToString(), true); } else if (CommandType == "Break") { if (findcob != null) { findcob.connectstatus = 0; } CheckConnectTimer.Start(); GetSCStatusTimer.Stop(); dal.UpdateSCStatusNTI(m_strSRMNo, "Equipment_Error"); crcb.UpdateCRCStatus(m_strSRMNo, CommandType, aisle.ToString()); //ShowText("C", "连接中断,IP地址" + m_ip + ",堆垛机编号" + m_strSRMNo + ",端口" + m_strport); } else if (CommandType == "Connect") { if (findcob != null) { findcob.connectstatus = 1; } CheckConnectTimer.Stop(); GetSCStatusTimer.Start(); ShowText("C", "连接成功,IP地址" + m_ip + ",堆垛机编号" + m_strSRMNo + ",端口" + m_strport); } }
private void CheckConnectTimer_Elapsed(object sender, ElapsedEventArgs e) { if (OSRM.Connection()) { ShowText("C", "Socket连接成功,IP地址" + m_ip + ",堆垛机编号" + m_strSRMNo + ",端口" + m_strport); // log.WriteLog("********************************************"); // log.WriteLog("Socket连接成功,IP地址" + m_ip + ",堆垛机编号" + m_strSRMNo + ",端口" + m_strport); // log.WriteLog("********************************************"); //OSRM.Initialized(m_strSRMNo); CheckConnectTimer.Stop(); } else { CheckConnectTimer.Start(); //GetSCStatusTimer.Stop(); log.WriteLog("Socket连接失败,IP地址" + m_ip + ",堆垛机编号" + m_strSRMNo + ",端口" + m_strport); ShowText("C", "Socket连接失败,IP地址" + m_ip + ",堆垛机编号" + m_strSRMNo + ",端口" + m_strport); } }
/// <summary> /// 状态请求 /// </summary> /// <param name="strSrmNu"></param> public bool RequestSRMState() { string strMsg = ""; byte[] sendBuffer = scb.RequestSRMState(); if (OSrmSocket.Connected) { try { OSrmSocket.Send(sendBuffer); char[] cr = System.Text.ASCIIEncoding.ASCII.GetChars(sendBuffer); for (int j = 0; j < cr.Length; j++) { strMsg = strMsg + cr[j].ToString(); } OnEAnlyseData(NotifyCommand.SendData, "WCS->SCS:AY:" + strMsg); //通知发送成功 log.WriteLog("********************************************"); log.WriteLog("WCS->SCS:" + strMsg); //通知发送成功 log.WriteLog("********************************************"); } catch (Exception) { return(false); } return(true); } else { OnEAnlyseData(NotifyCommand.Break, "WCS->SCS:AY:" + m_strSRMNo + "系统异常,Socket通信连接中断,状态请求不能发送!");//通知显示发送不成功 //log.WriteLog("********************************************"); //log.WriteLog("WCS->SCS:AY:" + m_strSRMNo + "系统异常,Socket通信连接中断,状态请求不能发送!"); // log.WriteLog("********************************************"); return(false); } }