示例#1
0
        public UartTelegram(UartHeader header, string[] data)
        {
            if (header == null)
            {
                throw new Exception("Impossível montar telegrama com cabeçalho nulo");
            }

            _Header = header;
            _Data   = data;
            _Buffer = null;
        }
示例#2
0
        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)
            {
            }
        }
示例#3
0
 public UartTelegram(string[] buffer)
 {
     _Buffer = buffer;
     _Header = null;
     _Data   = null;
 }