public void TreatMessage(IMsgUart msg) { if (m_Handlers.ContainsKey(msg.GetID())) { m_Handlers[msg.GetID()](msg); } else { throw new Exception(String.Format("Tratamento do telegrama {0} do PIC não foi inicializado", msg.GetID())); } }
private short GetStartAddress(IMsgUart msg) { switch (msg.GetID()) { case 200: return(0); case 201: return(2); default: return(-1); } }
internal static string ToString(this IMsgUart self) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("[{0}] ->", self.GetID()); PropertyInfo[] propsInfo = self.GetType().GetProperties(); if ((propsInfo != null) && (propsInfo.Length > 0)) { foreach (PropertyInfo prop in propsInfo) { sb.AppendFormat(" {0}:{1}", prop.Name, prop.GetValue(self, null)); } } return(sb.ToString()); }
public void SendDataHandler(IMsgUart msg) { try { UartHeader header = null; string[] data = null; PropertyInfo[] propsInfo = msg.GetType().GetProperties(); if ((propsInfo != null) && (propsInfo.Length > 0)) { header = new UartHeader { Size = propsInfo.Length, ID = msg.GetID() }; data = new string[propsInfo.Length]; for (int i = 0; i < propsInfo.Length; i++) { data[i] = propsInfo[i].GetValue(msg, null).ToString(); } } if (header != null) { UartTelegram telegram = new UartTelegram(header, data); _SerialPort.WriteLine(string.Join(";", telegram.Buffer)); } else { throw new Exception("Impossível criar telegrama sem cabeçalho."); } } catch (Exception exc) { } }