コード例 #1
0
ファイル: RFMCommunication.cs プロジェクト: willy40/testmono
        /// <summary>
        /// The create packet.
        /// </summary>
        private static IPacket CreateReceivedPacket(DataArrivedEventArgs e)
        {
            // TODO for now we dont have defined packet types
            // so defaut is return temperature

            IPacket retPacket = null;

            try
            {
                retPacket = new Packet
                {
                    Header = e.Buffer[0],
                    SrcAddress = e.Buffer[1],
                    Time = DateTime.Now,
                    Data = Encoding.ASCII.GetString(e.Buffer, _constPacketHeaderSize, e.Size - _constPacketHeaderSize),
                    Type = PacketTypes.Temparature
                };
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return retPacket;
        }
コード例 #2
0
ファイル: RPICommunication.cs プロジェクト: willy40/testmono
        /// <summary>
        /// The create packet.
        /// </summary>
        private static IPacket CreateReceivedPacket(DataArrivedEventArgs e)
        {
            // TODO for now we dont have defined packet types
            // so defaut is return temperturae

            IPacket retPacket = null;
            try
            {
                retPacket = new Packet
                                {
                                    Header = 0, 
                                    SrcAddress = byte.Parse(e.Tag.ToString()), 
                                    Time = DateTime.Now, 
                                    Data = double.Parse(Encoding.ASCII.GetString(e.Buffer, 0, e.Size)) / 1000, 
                                    Type = PacketTypes.Temparature
                                };
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return retPacket;
        }