Example #1
0
 private void ProcessInfoPackets()
 {
     if (this.SerialPort.RX_INFO.Processed == false)
     {
         AUX_Functions.ShowDebugInfo(false, "FW DBG INFO: " + Encoding.ASCII.GetString(this.SerialPort.RX_INFO.PARAM));
         this.SerialPort.RX_INFO.Processed = true;
     }
 }
Example #2
0
 private void button2_Click(object sender, EventArgs e)
 {
     DEFS.sCOMMAND Comando = new DEFS.sCOMMAND();
     Comando.CMD = 13;
     AUX_Functions.Enqueue_Command(Comando);
     Comando.CMD = 50;
     AUX_Functions.Enqueue_Command(Comando);
     Comando.CMD = 88;
     AUX_Functions.Enqueue_Command(Comando);
 }
Example #3
0
        private void Callback_WatchDogTimer(Object source, ElapsedEventArgs e)
        {
            //AUX_Functions.ShowDebugInfo(false, "PROCESANDO COMANDO: " + 66.ToString());
            //AUX_Functions.ShowDebugInfoERROR(false, "ENVIANDO COMANDO: " + 66.ToString());

            if ((this.EstadoCiclo == enumCiclo.WAIT_COMAND) && this.SerialPort.PortOpened)
            {
                Wdg_Comando.PARAM[0] = (byte)(++Wdg_Comando.PARAM[0] % 2);
                AUX_Functions.Enqueue_Command(Wdg_Comando);
            }
        }
 public bool SendCommand(sCOMMAND Comando)
 {
     try
     {
         if (this.m_PortOpened && mySerialPort.IsOpen)
         {
             this.mySerialPort.Write(AUX_Functions.StructureToByteArray(Comando), 0, Comando.ParamSize + 5);
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Example #5
0
        private void Ciclo()
        {
            DEFS.sCOMMAND TXComando = new sCOMMAND();

            while (!this.PararCiclo)
            {
                try
                {
                    if (this.SerialPort.PortOpened)
                    {
                        switch (this.EstadoCiclo)
                        {
                        case enumCiclo.WAIT_COMAND:
                            if (Program.TX_Commands.TryDequeue(out TXComando))
                            {
                                //NEW COMMAND
                                AUX_Functions.ShowDebugInfo(false, "PROCESANDO COMANDO: " + TXComando.CMD.ToString());
                                this.EstadoCiclo = enumCiclo.SEND_COMMAND;
                            }
                            break;

                        case enumCiclo.SEND_COMMAND:
                            if (this.SerialPort.SendCommand(TXComando))
                            {
                                this.T_EsperaACK.Stop();
                                this.T_EsperaACK.Reset();
                                this.T_EsperaACK.Start();
                                this.EstadoCiclo = enumCiclo.WAIT_ACK;
                            }
                            else
                            {
                                AUX_Functions.ShowDebugInfoERROR(false, "ENVIANDO COMANDO: " + TXComando.CMD.ToString());
                                this.EstadoCiclo = enumCiclo.WAIT_COMAND;
                            }
                            break;

                        case enumCiclo.WAIT_ACK:
                            if (this.T_EsperaACK.Alcanzado)
                            {
                                this.SerialPort.Reset_RX_STATUS();
                                AUX_Functions.ShowDebugInfoERROR(false, "TIEMOUT ESPERANDO ACK COMANDO: " + TXComando.CMD.ToString());
                                this.EstadoCiclo = enumCiclo.WAIT_COMAND;
                            }
                            else
                            {
                                if (this.SerialPort.ACK_Received)
                                {
                                    //Comprobar coherencia ComandoEnviado <=> ACK_ComandoRecibido
                                    if (TXComando.CMD == (0xFF - this.SerialPort.RX_COMMAND.CMD)) //AÑADIR VERIFICACIÓN TAMAÑO PARAMETROS Y ACK
                                    {
                                        //Proceder a procesar los datos recibidos
                                    }
                                    else
                                    {
                                        AUX_Functions.ShowDebugInfoERROR(false, "ENVIADO COMANDO: " + TXComando.CMD.ToString() + " Recibido ACK: " + (0xFF - this.SerialPort.RX_COMMAND.CMD).ToString());
                                    }
                                    this.EstadoCiclo = enumCiclo.WAIT_COMAND;
                                }
                            }

                            break;
                        }// END SWITCH

                        //PROCESS INFO PACKETS
                        this.ProcessInfoPackets();
                    }

                    Thread.Sleep(10);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + ex.StackTrace);
                    this.EstadoCiclo = enumCiclo.WAIT_COMAND;
                }
            } //END WHILE
        }     //END FUNCIÓN Ciclo