示例#1
0
        //Funcion que envia la informacion con la lectura del chip al Autorizador
        void EnviarDatosChip(object Parametro)
        {
            DatosLector obj = (DatosLector)Parametro;

            byte[] DatosLeidos = obj.ArregloBytes;
            try
            {
                if (DatosLeidos.Length == 148)
                {
                    byte[] Trama = new byte[147];
                    for (int y = 0; y < DatosLeidos.Length - 1; y++)
                    {
                        Trama[y] = DatosLeidos[y];
                    }
                    ExtraerInformacionRecibidaDelDispositivoDTI(Trama);
                }

                else if (DatosLeidos.Length == 6)
                {
                    byte[] Trama = new byte[5];
                    for (int y = 0; y < DatosLeidos.Length - 1; y++)
                    {
                        Trama[y] = DatosLeidos[y];
                    }
                    ExtraerInformacionRecibidaDelDispositivoDTI(Trama);
                }
                else
                {
                    throw new Exception("La lectura del chip no se hizo correctamente");
                }
            }
            catch (Exception ex)
            {
                LogCategorias.Clear();
                LogCategorias.Agregar("SeguimientoCodigoDTI");
                LogPropiedades.Clear();
                LogPropiedades.Agregar("Mensaje", ex.Message);
                Fabrica.LogIt.Loguear("Error recuperando ROM chip", LogPropiedades, LogCategorias);
            }
        }
示例#2
0
        private void PuertoTerminal_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            try
            {
                string      X2 = "";
                byte[]      ODatosChip, Trama;
                DatosLector OChipTemporal = new DatosLector();


                System.Threading.Thread.Sleep(Delay);
                Longitud   = PuertoTerminal.BytesToRead;
                ODatosChip = new byte[Longitud];
                PuertoTerminal.Read(ODatosChip, 0, Longitud);
                PuertoTerminal.DiscardInBuffer();
                PuertoTerminal.DiscardOutBuffer();

                Trama = new byte[Longitud];


                if (Longitud <= 0)
                {
                    PuertoTerminal.RtsEnable = true;
                    System.Threading.Thread.Sleep(10);
                    PuertoTerminal.RtsEnable = false;
                    return;
                }

                for (int y = 0; y < ODatosChip.Length; y++)
                {
                    Trama[y] = ODatosChip[y];
                }

                for (int i = 0; i < ODatosChip.Length; i++)
                {
                    X2 += ODatosChip[i].ToString("X2");
                }


                VerifySizeFile();//Verifico el tamaño del archivo de texto con las tramas
                if ((ODatosChip.Length == 6) && (Trama[5] == 0x7E))
                {
                    SWRegistro.WriteLine(DateTime.Now + " |N° Bytes Recibidos " + ODatosChip.Length.ToString() + "|" + X2);
                    SWRegistro.Flush();
                    OChipTemporal.ArregloBytes = ODatosChip;
                    System.Threading.ParameterizedThreadStart Parametro = new ParameterizedThreadStart(EnviarDatosChip);
                    System.Threading.Thread Hilo = new System.Threading.Thread(Parametro);
                    Hilo.Start(OChipTemporal);
                    Hilo.Join();
                }
                else if ((ODatosChip.Length == 148) && (Trama[147] == 0x7E))
                {
                    SWRegistro.WriteLine(DateTime.Now + " |N° Bytes Recibidos " + ODatosChip.Length.ToString() + "|" + X2);
                    SWRegistro.Flush();

                    OChipTemporal.ArregloBytes = ODatosChip;
                    System.Threading.ParameterizedThreadStart Parametro = new ParameterizedThreadStart(EnviarDatosChip);
                    System.Threading.Thread Hilo = new System.Threading.Thread(Parametro);
                    Hilo.Start(OChipTemporal);
                    Hilo.Join();
                }
                else
                {
                    if (ODatosChip.Length >= 2)
                    {
                        PuertoTerminal.RtsEnable = true;
                        System.Threading.Thread.Sleep(10);
                        PuertoTerminal.RtsEnable = false;

                        Byte[] Lector = new Byte[5] {
                            0x49, 0x3F, ODatosChip[1], 0x15, 0x7E
                        };
                        X2 = "";
                        for (int i = 0; i < Lector.Length; i++)
                        {
                            X2 += Lector[i].ToString("X2");
                        }


                        SWRegistro.WriteLine(DateTime.Now + " |Lectura incompleta del LSIB4 (" + ODatosChip.Length + ") Bytes: Reintento de Lectura  LSIB4 " + "|" + X2);
                        SWRegistro.Flush();
                        PuertoTerminal.Write(Lector, 0, Lector.Length);
                        System.Threading.Thread.Sleep(Delay);
                    }
                }
            }
            catch (Exception ex)
            {
                LogCategorias.Clear();
                LogCategorias.Agregar("SeguimientoCodigoDTI");
                LogPropiedades.Clear();
                LogPropiedades.Agregar("Mensaje", ex.Message);
                Fabrica.LogIt.Loguear("Error recuperando ROM chip PuertoTerminal_DataReceived", LogPropiedades, LogCategorias);
            }
        }