Ejemplo n.º 1
0
        /// <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;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The main device_ data arrived handler.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void DataArrivedHandler(object sender, DataArrivedEventArgs e)
        {
            if (e == null)
            {
                return;
            }

            var packet = CreateReceivedPacket(e);

            if (packet != null)
            {
                this.AssignPacketToDevice(packet);
            }
        }
Ejemplo n.º 3
0
        /// <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;
        }