/// <summary>
        /// Body of the thread that polls the messages.
        /// It will poll data EVEN IF nobody is registered on the event!
        /// </summary>
        protected void PollMessageThread(object pParam)
        {
            while (this.mPollMessages)
            {
                if (!this.mWaitingForAck)
                {
                    //if not waiting for a ACK
                    //small probabily of thread collision, but let's see like that first... (should lock the variable before)
                    lock (mWaitingForAckSynchroKey) {
                        if (!this.mWaitingForAck)
                        {
                            //synchro : lock the line
                            lock (this.mPollingMessageSynchroKey) {
                                try {
                                    bool         vReceiveOk = false;
                                    ARCPO_Packet vPacket    = new ARCPO_Packet();
                                    vReceiveOk = vPacket.ReadPacket(this.mPort);

                                    if (vReceiveOk && this.PacketReceived != null)
                                    {
                                        //received + someone waiting for notification : raise the event
                                        ARCPO_ReceivedEventArgs vE = new ARCPO_ReceivedEventArgs(vPacket);
                                        this.PacketReceived(this, vE);
                                    }
                                }
                                catch (Exception ex) {
                                    //nothing (for now)
                                }
                            }
                        }
                    }
                }

                //get some rest
                Thread.Sleep(RECEIVE_POLLING_IN_MS);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Body of the thread that polls the messages.
        /// It will poll data EVEN IF nobody is registered on the event!
        /// </summary>
        protected void PollMessageThread(object pParam)
        {
            while (this.mPollMessages) {

                if (!this.mWaitingForAck) {
                    //if not waiting for a ACK
                    //small probabily of thread collision, but let's see like that first... (should lock the variable before)
                    lock (mWaitingForAckSynchroKey) {
                        if (!this.mWaitingForAck) {
                            //synchro : lock the line
                            lock (this.mPollingMessageSynchroKey) {
                                try {
                                    bool vReceiveOk = false;
                                    ARCPO_Packet vPacket = new ARCPO_Packet();
                                    vReceiveOk = vPacket.ReadPacket(this.mPort);

                                    if (vReceiveOk && this.PacketReceived != null) {
                                        //received + someone waiting for notification : raise the event
                                        ARCPO_ReceivedEventArgs vE = new ARCPO_ReceivedEventArgs(vPacket);
                                        this.PacketReceived(this, vE);
                                    }
                                }
                                catch (Exception ex) {
                                    //nothing (for now)
                                }
                            }
                        }
                    }
                }

                //get some rest
                Thread.Sleep(RECEIVE_POLLING_IN_MS);
            }
        }
Exemplo n.º 3
0
 private void Connector_PacketReceived(object sender, ARCPO_ReceivedEventArgs e)
 {
     textBox1.Text += ">>RECEIVED unexpected message " + e.Packet.mID + " : ";
     textBox1.Text += e.Packet.ContentString;
     textBox1.Text += "\r\n";
 }
Exemplo n.º 4
0
        /// <summary>
        /// Message received from arduino
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Connector_PacketReceived(object sender, ARCPO_ReceivedEventArgs e)
        {
            this.mReceivedMessageHistory.Add(e.Packet);

            if (this.PacketReceived != null)
            {
                this.PacketReceived(this, e);
            }
        }