コード例 #1
0
        //========================================================================================
        //Fonction: Gère la Réception/Envoie
        public override void Echange()
        {
            OnChangeLabelStatus("Status: Waiting for the device...");

            bool termine = false;

            while (serialPort.IsOpen == true && termine == false)
            {
                SendMessage(deisterManager.ACK);
                termine = ReceiveMessage();
            }
            try
            {
                if (deisterManager.Trame.Rondes.Count != 0)
                {
                    deisterManager.Trame.AfficherListeRonde();
                }
            }
            catch
            {
                Program.LogFich.Error("[DeisterPortSerie] Aucune ronde à afficher");
            }
            if (enMarche)
            {
                PeripheriqueDataReceivedEventArgs received = new PeripheriqueDataReceivedEventArgs(deisterManager.Trame);
                if (received != null)
                {
                    base.OnDataReceived(received);
                }
            }
        }
コード例 #2
0
        public override void Echange()
        {
            string temp = scanner_piece();

            PeripheriqueDataReceivedEventArgs psea = new PeripheriqueDataReceivedEventArgs(temp);

            if (psea != null)
            {
                Program.LogFich.Info("[ScannerPiece] Lecture MRZ = " + temp);
                base.OnDataReceived(psea);
            }
        }
コード例 #3
0
ファイル: Peripherique.cs プロジェクト: ibtissamemme/unisbox
        //The event-invoking method that derived classes can override.
        protected virtual void OnDataReceived(PeripheriqueDataReceivedEventArgs e)
        {
            // Make a temporary copy of the event to avoid possibility of
            // a race condition if the last subscriber unsubscribes
            // immediately after the null check and before the event is raised.
            PeripheriqueDataReceivedEventHandler handler = DataReceived;

            if (handler != null)
            {
                handler(this, e);
            }
        }
コード例 #4
0
 private void perif_DataReceived(object sender, PeripheriqueDataReceivedEventArgs e)
 {
     receiving = false;
     data.traiter(e.Data);
     perif.SendMessageInLocal();
     data.envoyer(url, Functions.getHost());
     perif.Nettoyer();
     perif.DataReceived -= new Peripherique.PeripheriqueDataReceivedEventHandler(perif_DataReceived);
     ChangeLabelStatusFormPeripherique("Status : Data received...");
     Program.LogFich.Info("[FormPeripherique] Réception terminée");
     cpt = 0;
 }
コード例 #5
0
        void entreDeux_Tick(object sender, EventArgs e)
        {
            this.fini = true;
            entreDeux.Dispose();
            entreDeux = null;
            PeripheriqueDataReceivedEventArgs psea = new PeripheriqueDataReceivedEventArgs(textBox.Text);

            if (psea != null)
            {
                Program.LogFich.Info("[EcranClavier] Lecture MRZ = " + textBox.Text);
                base.OnDataReceived(psea);
            }
        }
コード例 #6
0
        //Event "En cours de réception de données"
        private void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            PeripheriqueDataReceivingEventArgs receiving = new PeripheriqueDataReceivingEventArgs();

            if (receiving != null)
            {
                base.OnDataReceiving(receiving);
            }

            try
            {
                byte[] lecture = new byte[serialPort.ReadBufferSize];
                int    i       = 0;

                //On récupère la trame provenant du port série
                byte b;
                bool termine = false;
                do
                {
                    try
                    {
                        b          = Convert.ToByte(serialPort.ReadByte());
                        lecture[i] = b;
                        i++;
                    }
                    catch
                    {
                        termine = true;
                    }
                }while (!termine);

                lecture = lecteurManager.CorrectionTailleTrame(i, lecture);
                for (int cpt = 0; cpt < lecture.Length; cpt++)
                {
                    Program.LogFich.Info("[LecteurPortSerie]: Donnee brut recu = " + lecture.GetValue(cpt));
                }

                //Nettoyage des caracteres avant/apres

                /*for (int cpt = 0; cpt < lecture.Length; cpt++)
                 * {
                 *  if (lecteurManager.AvantByte != 0x00)
                 *  {
                 *      if (lecture[cpt].Equals(lecteurManager.AvantByte))
                 *      {
                 *          lecture = lecteurManager.Nettoyer(cpt, lecture);
                 *          Program.LogFich.Info("[LecteurPortSerie]: Suppression byte avant, indice = " + cpt);
                 *      }
                 *  }
                 *  if (lecteurManager.ApresByte != 0x00)
                 *  {
                 *      if (lecture[cpt].Equals(lecteurManager.ApresByte))
                 *      {
                 *          lecture = lecteurManager.Nettoyer(cpt, lecture);
                 *          Program.LogFich.Info("[LecteurPortSerie]: Suppression byte apres, indice = " + cpt);
                 *      }
                 *  }
                 * }
                 * for (int cpt = 0; cpt < lecture.Length; cpt++)
                 *  Program.LogFich.Info("[LecteurPortSerie]: Resultat du nettoyage = " + lecture.GetValue(cpt));
                 */

                //Conversion en string
                string trameBrut = lecteurManager.ByteToString(lecture, lecture.Length);
                Program.LogFich.Info("[LecteurPortSerie]: Conversion en string = " + trameBrut);

                //Nettoyage
                Program.LogFich.Info("[LecteurPortSerie]: Code Avant à nettoyer = " + lecteurManager.Avant);
                Program.LogFich.Info("[LecteurPortSerie]: Code Après à nettoyer = " + lecteurManager.Apres);
                trameBrut = lecteurManager.Nettoyer(trameBrut);
                Program.LogFich.Info("[LecteurPortSerie]: Nettoyage = " + trameBrut);

                PeripheriqueDataReceivedEventArgs DataReceived = new PeripheriqueDataReceivedEventArgs(trameBrut);
                if (DataReceived != null)
                {
                    base.OnDataReceived(DataReceived);
                }

                OnChangeLabelStatus("Status: Receiving data...[Succeeded]");
                Program.LogFich.Info("[LecteurPortSerie] Réception terminée");
            }
            catch (Exception ex)
            {
                OnChangeLabelStatus("Status: Receiving data...[Failed]");
                Program.LogFich.Error("[LecteurPortSerie] Erreur de reception: " + ex.ToString());
            }
        }
コード例 #7
0
        //Event Réception données terminée
        private void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            PeripheriqueDataReceivingEventArgs receiving = new PeripheriqueDataReceivingEventArgs();

            if (receiving != null)
            {
                base.OnDataReceiving(receiving);
            }
            try
            {
                // Ori
                //char[] buffer = new char[serialPort.ReadBufferSize];
                //bool b = true;
                //char c;

                //do
                //{
                //    try
                //    {
                //        c = Convert.ToChar(serialPort.ReadChar());
                //        sb.Append(c);
                //    }
                //    catch
                //    {
                //        b = false;
                //    }
                //} while (b);


                // Version 2
                char[] buffer  = new char[serialPort.ReadBufferSize];
                bool   termine = true;
                char   c;

                do
                {
                    try
                    {
                        c = Convert.ToChar(serialPort.ReadChar());
                        sb.Append(c);
                    }
                    catch
                    {
                        System.Threading.Thread.Sleep(1000);

                        try
                        {
                            c = Convert.ToChar(serialPort.ReadChar());
                            sb.Append(c);
                        }
                        catch
                        {
                            termine = false;
                        }
                    }
                } while (termine);


                PeripheriqueDataReceivedEventArgs DataReceived = new PeripheriqueDataReceivedEventArgs(sb.ToString());
                if (DataReceived != null)
                {
                    base.OnDataReceived(DataReceived);
                }
                OnChangeLabelStatus("Status: Receiving data...[Succeeded]");
                //Program.LogFich.Info("[MagnetaPortSerie] Réception terminée = " + sb.ToString());
                Program.LogFich.Info("[MagnetaPortSerie] Réception terminée");
            }
            catch
            {
                OnChangeLabelStatus("Status: Receiving data...[Failed]");
                Program.LogFich.Error("[MagnetaPortSerie] Erreur de reception");
            }
        }