public static event OverrideTelegramReceived OnOverrideTelegramReceived; //Return true if the message was handled elsewhere (Routing Script) public virtual void Connection_OnTelegramReceived(Core.Communication.TCPIP.Connection sender, string telegram) { if (InvokeRequired) { Core.Environment.Invoke(() => Connection_OnTelegramReceived(sender, telegram)); return; } try { if (telegram.GetFieldValue(this, TelegramFields.Flow) == "A") { int result = 0; if (int.TryParse(telegram.GetFieldValue(this, TelegramFields.CycleNo), out result) && result == lastAckCycle) //This will ignore ack if its in the wrong sequence { if (LogAll) { LogTelegrams(string.Format("{0} {1}>{2}: {3}", DateTime.Now.ToString(), ReceiverID, SenderID, telegram), Color.Black); } waitingForAck = false; ackResendCount = 0; ackTimer.Stop(); SendBuffer(); } return; } LogTelegrams(string.Format("{0} {1}>{2}: {3}", DateTime.Now.ToString(), ReceiverID, SenderID, telegram), Color.Black); //Check if this is an ack telegram TelegramTypes type = telegram.GetTelegramType(this); if (telegram.GetFieldValue(this, TelegramFields.Flow) == "R") { string ackTelegram = string.Format("/,A,{0},{1},{2},{3},{4},{5},{6},0030,##", telegram.GetFieldValue(this, TelegramFields.Type), VFCIdentifier, PLCIdentifier, telegram.GetFieldValue(this, TelegramFields.CycleNo), telegram.GetFieldValue(this, TelegramFields.Code), telegram.GetFieldValue(this, TelegramFields.BlocksCount), telegram.GetFieldValue(this, TelegramFields.BlocksType)); SendAckOnly(ackTelegram); } if (OnOverrideTelegramReceived == null || !OnOverrideTelegramReceived(this, telegram)) { HandleTelegrams(telegram, telegram.GetTelegramType(this)); } } catch (Exception se) { Experior.Core.Environment.Log.Write("Exception recieving telegram: "); Experior.Core.Environment.Log.Write(se); } }
public static event OverrideTelegramReceived OnOverrideTelegramReceived; //Return true if the message was handled elsewhere (Routing Script) public virtual void Connection_OnTelegramReceived(Core.Communication.TCPIP.Connection sender, string telegram) { if (InvokeRequired) { Core.Environment.Invoke(() => Connection_OnTelegramReceived(sender, telegram)); return; } try { this.LogTelegrams(string.Format("{0} ATC>{1}: {2}", DateTime.Now.ToString(), Name, telegram), Color.Black); string[] telegramFields = telegram.Split(','); if (OnOverrideTelegramReceived == null || !OnOverrideTelegramReceived(this, telegramFields)) { HandleTelegrams(telegramFields, telegramFields.GetTelegramType()); } } catch (Exception se) { Experior.Core.Environment.Log.Write("Exception recieving telegram: "); Experior.Core.Environment.Log.Write(se); } }
public void Connection_OnTelegramReceived(Core.Communication.TCPIP.Connection sender, string telegram) { ////If the receiver ID is incorrect (or for another controller) then ignore the message //if (telegram.Substring(6,2) != SenderID.ToString("00")) //{ // return; //} if (sender == SendConnection) { return; //Only ack telegrams should be received on this connection. For now just ignore... } if (InvokeRequired) { Core.Environment.Invoke(() => Connection_OnTelegramReceived(sender, telegram)); return; } try { string[] telegramFields = telegram.Split(sender.MVTSeparator.ToCharArray()); string type = telegramFields[2]; string telegramsender = telegramFields[3]; string telegramreciever = telegramFields[4]; ushort number_of_blocks = ushort.Parse(telegramFields[5]); bool heartbeat = false; if (type == "13") { if (telegramFields[6] == "07") { // type 13 Heartbeat status 07 heartbeat = true; } } if (!heartbeat) { Experior.Core.Environment.Log.Write(DateTime.Now.ToString() + " MFH>PLC: " + sender.Id.ToString() + " " + telegram); } if (LogHeartBeat && heartbeat) { Experior.Core.Environment.Log.Write(DateTime.Now.ToString() + " MFH>PLC: " + sender.Id.ToString() + " " + telegram); } if (HandleTelegram != null) { //If user method returns true then it is handled by the user. if (HandleTelegram(this, type, telegramFields, number_of_blocks)) { return; } } HandleTelegrams(telegramFields, type, number_of_blocks); } catch (Exception se) { Experior.Core.Environment.Log.Write("Exception recieving telegram: "); Experior.Core.Environment.Log.Write(se); } }