Пример #1
0
        public override void FunctionToExecuteByThread()
        {
            try
            {
                List <CMedida> measurement = (List <CMedida>)((SharedData <List <CMedida> >)_SharedMemory["Chapas"]).Pop();

                if (measurement.Count > 5)
                {
                    // si ya he recibido el ancho lo uso para procesar , si no pongo ancho =0 y proceso sin el
                    if (!((SharedData <PlateID>)SharedMemory["IDChapa"]).Vacio)
                    {
                        PlateID id = ((PlateID)((SharedData <PlateID>)SharedMemory["IDChapa"]).Get(0));
                        duracion = _Proc.ProcesamientoDatos(measurement, id.Width, id.Tolerance1, id.Tolerance2);
                    }
                    else
                    {
                        duracion = _Proc.ProcesamientoDatos(measurement, 900, 5, 5);
                    }

                    ActualizarResultados();
                }
            }
            catch (Exception e)
            {
                _AuxLogError.LOGTXTMessage = "PROCESAMIENTO : ERROR en el procesamiento : " + e.Message;
                _Padre.LogError.SetData(ref _AuxLogError, "Informacion");
            }
        }
Пример #2
0
        public override void FunctionToExecuteByThread()
        {
            while (((SharedData <Byte[]>)SharedMemory["SocketReader"]).Elementos > 0)
            {
                Byte[] val     = (Byte[])((SharedData <Byte[]>)SharedMemory["SocketReader"]).Pop();
                string mensaje = Encoding.ASCII.GetString(val);
                Trace.WriteLine(mensaje);
                try
                {
                    String messageid = mensaje.Substring(0, 2);
                    switch (messageid)
                    {
                    //TODO
                    case "M9":
                        //Events["IDChapa"].Set();

                        string _ID        = mensaje.Substring(2, 16);
                        string _Width     = mensaje.Substring(18, 4);
                        string _Length    = mensaje.Substring(22, 5);
                        string _Thickness = mensaje.Substring(27, 5);
                        string _Tol1      = mensaje.Substring(32, 3);
                        string _Tol2      = mensaje.Substring(35, 3);


                        PlateID valor = new PlateID(_ID, double.Parse(_Width), double.Parse(_Length), double.Parse(_Thickness) / 100, double.Parse(_Tol1) / 10, double.Parse(_Tol2) / 10);
                        ((SharedData <PlateID>)SharedMemory["IDChapa"]).Add(valor);
                        _AuxLogCom.LOGTXTMessage = "OP : New ID received : " + _ID + " Width : " + _Width + " Length : " + _Length + " Thickness : " + _Thickness + " Tol1 : " + _Tol1 + " Tol2 : " + _Tol2;
                        _Padre.Log.SetData(ref _AuxLogCom, "Informacion");

                        _Padre.PrepareEvent(_Name);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    _AuxLogError.LOGTXTMessage = "Error receiving ID from Process computer : " + ex.Message;
                    _Padre.Log.SetData(ref _AuxLogError, "Informacion");
                }
            }
        }
Пример #3
0
        private void CalcularOffset()
        {
            ((ComunicacionTarjeta)_Padre._DispatcherThreads["ComunicacionTarjeta"])._server.GetData(ref _AuxMeplaca, "EstadoSocket");
            int    _NumeroModulos           = int.Parse(_AuxMeplaca.MEPNumeroModulos);
            double distancia_a_la_chapa     = double.Parse(_AuxMeplaca.MEPDistancia_nominal_trabajo);
            double distancia_entre_sensores = double.Parse(_AuxMeplaca.MEPDistancia_entre_sensores);

            double[] Referencias = new double[_NumeroModulos * 6];
            double[] medidas     = new double[_NumeroModulos * 6];

            if (!((SharedData <PlateID>)SharedMemory["IDChapa"]).Vacio)
            {
                PlateID id = ((PlateID)((SharedData <PlateID>)SharedMemory["IDChapa"]).Get(0));


                _Meplaca.GetData(ref _AuxMeplaca, "UltimaMedida");
                medidas = (double[])_AuxMeplaca.MEPUltimoPerfil;

                double valor  = (distancia_a_la_chapa - id.Thickness) / 10;
                double limder = (int)Math.Round(id.Width / distancia_entre_sensores);
                double limizq = 1;



                for (int i = 0; i < Referencias.Length; i++)
                {
                    if ((i >= limizq) && (i <= limder))
                    {
                        Referencias[i] = valor;
                    }
                    else
                    {
                        medidas[i]     = 0;
                        Referencias[i] = 0;
                    }
                }
                ((SharedData <Offset>)SharedMemory["Offset"]).Set(0, new Offset(medidas, Referencias));
            }
            //guardo los offset para enviarlos luego
        }
Пример #4
0
        void PintarResultados(dynamic datos)
        {
            if (datos.MEPErrors == "")
            {
                foreach (string data in datos.MEPReturnedData)
                {
                    switch (data)
                    {
                    case "Resultados":
                        #region resultados

                        Resultados resultados = datos.MEPResultados;
                        if (resultados.Perfiles > 0)
                        {
                            double[,] pixeles = resultados.Pixeles;
                            double[,] puntos  = resultados.Puntos;
                            int ancho, alto;
                            resultados.Z.GetImageSize(out ancho, out alto);
                            // perfiles.Text = ancho.ToString() + " perfiles";

                            VentanaHalconPrincipal.HalconWindow.SetPart(0, 0, alto - 1, ancho - 1);

                            resultados.Z.SetGrayval(0, 0, resultados.Distancia_nominal - 50);      // para fijar la escala de colores
                            label_escala_min.Text = (resultados.Distancia_nominal - 50).ToString();

                            resultados.Z.SetGrayval(alto - 1, ancho - 1, resultados.Distancia_nominal + 50);     // para fijar la escala de valores
                            label_escala_max.Text   = (resultados.Distancia_nominal + 50).ToString() + " mm";
                            label_escala_inter.Text = ((resultados.Distancia_nominal + 50) / 2).ToString() + " mm";

                            VentanaHalconPrincipal.HalconWindow.DispObj(resultados.Z);

                            //pinto los defectos en el mapa

                            for (int i = 0; i < pixeles.Length / 5; i++)
                            {
                                if (i < 5)
                                {
                                    VentanaHalconPrincipal.HalconWindow.SetColor("blue");
                                }
                                else
                                {
                                    VentanaHalconPrincipal.HalconWindow.SetColor("green");
                                }
                                VentanaHalconPrincipal.HalconWindow.DispLine(pixeles[i, 0], pixeles[i, 1], pixeles[i, 2], pixeles[i, 3]);
                                VentanaHalconPrincipal.HalconWindow.SetColor("black");
                                if (i < 5)
                                {
                                    VentanaHalconPrincipal.HalconWindow.SetTposition((int)pixeles[i, 0], (int)pixeles[i, 1]);
                                    VentanaHalconPrincipal.HalconWindow.WriteString(pixeles[i, 4].ToString("F1"));
                                }
                            }


                            // Añado los defectos al ListView

                            _listViewPuntos.Items.Clear();
                            for (int i = 0; i < puntos.Length / 7; i++)
                            {
                                _listViewPuntos.Items.Add((i + 1).ToString(), i);
                                if (i < 5)
                                {
                                    _listViewPuntos.Items[i].Group = _listViewPuntos.Groups[0];
                                }
                                else
                                {
                                    _listViewPuntos.Items[i].Group = _listViewPuntos.Groups[1];
                                }
                                for (int j = 0; j < 7; j++)
                                {
                                    _listViewPuntos.Items[i].SubItems.Add(puntos[i, j].ToString("F0"));
                                }
                            }

                            //Actualizo la informacion de la chapa
                            labelPlateId.MainText   = resultados.ID;
                            labelLength.MainText    = resultados.Longitud.ToString();
                            labelWidth.MainText     = resultados.Ancho.ToString();
                            labelThickness.MainText = resultados.Thickness.ToString();
                            labelMinimum1.MainText  = resultados.Tolerance1.ToString();
                            labelMinimum2.MainText  = resultados.Tolerance2.ToString();
                            label1.MainText         = resultados.NumDefects1.ToString();
                            label2.MainText         = resultados.NumDefects2.ToString();

                            if (resultados.NumDefects1 + resultados.NumDefects2 == 0)
                            {
                                spinBlackDataLabelControl5.PageStartColor = Color.DarkGreen;
                                spinBlackDataLabelControl5.PageEndColor   = Color.FromArgb(0, 192, 0);
                                spinBlackDataLabelControl5.MainText       = "OK";
                                spinBlackDataLabelControl5.SubtitleText   = "Plate Accepted";
                            }
                            else
                            {
                                spinBlackDataLabelControl5.PageStartColor = Color.Maroon;
                                spinBlackDataLabelControl5.PageEndColor   = Color.Red;
                                spinBlackDataLabelControl5.MainText       = "NO";
                                spinBlackDataLabelControl5.SubtitleText   = "Plate Rejected";
                            }


                            //formPrincipal.VentanaHalconPrincipal.HalconWindow.DumpWindow("jpeg", "meplaca_lab");
                        }
                        #endregion
                        break;

                    case "ComunicacionOP":
                        #region ID
                        PlateID ID = datos.MEPID;
                        //Actualizo la informacion de la chapa
                        labelPlateId.MainText   = ID.ID;
                        labelLength.MainText    = ID.Length.ToString();
                        labelWidth.MainText     = ID.Width.ToString();
                        labelThickness.MainText = ID.Thickness.ToString();
                        labelMinimum1.MainText  = ID.Tolerance1.ToString();
                        labelMinimum2.MainText  = ID.Tolerance2.ToString();

                        spinBlackDataLabelControl5.PageStartColor = Color.DarkGreen;
                        spinBlackDataLabelControl5.PageEndColor   = Color.FromArgb(0, 192, 0);
                        spinBlackDataLabelControl5.MainText       = "OK";
                        spinBlackDataLabelControl5.SubtitleText   = "Plate Accepted";
                        #endregion

                        break;

                    case "Informacion":
                        #region informacion

                        Informacion informacion = datos.MEPInformacion;
                        labelLength.MainText          = ((double)(informacion.Avance / 1000)).ToString("F02");
                        toolStripStatusframerate.Text = "FRAMERATE : " + informacion.Rate.ToString("F1") + " perfiles / sec";
                        #endregion

                        break;

                    default:
                        break;
                    }
                }
            }
        }
Пример #5
0
        void ActualizarResultados()
        {
            string id, id_file;
            double ancho, largo, espesor, tol1, tol2;

            if (!((SharedData <PlateID>)SharedMemory["IDChapa"]).Vacio)
            {
                PlateID temp = (PlateID)((SharedData <PlateID>)SharedMemory["IDChapa"]).Pop();

                id      = temp.ID;
                id_file = id;
                ancho   = temp.Width;
                largo   = temp.Length;
                tol1    = temp.Tolerance1;
                espesor = temp.Thickness;
                tol2    = temp.Tolerance2;
            }
            else
            {
                DateTime now = DateTime.Now;
                id      = now.Hour.ToString() + "/" + now.Minute.ToString() + "/" + now.Second.ToString() + now.Hour.ToString() + "/" + now.Minute.ToString() + "/" + now.Second.ToString();
                id_file = now.Day.ToString() + "_" + now.Month.ToString() + "_" + now.Year.ToString() + "_" + now.Hour.ToString() + "_" + now.Minute.ToString() + "_" + now.Second.ToString();
                ancho   = 0;
                largo   = 0;
                espesor = 0;
                tol1    = 0;
                tol2    = 0;
                _AuxLogError.LOGTXTMessage = "Plate measured with default Parameters. No ID sent";
                _Padre.LogError.SetData(ref _AuxLogError, "Informacion");
            }

            //envio los resultados al ordenador de proceso
            ((ComunicacionOP)((Meplate)_Padre)._DispatcherThreads["ComunicacionOP"]).SendMessageM5(id, _Proc.Puntos, _Proc._Decision, _Proc._Puntuacion * 10);


            //lanzo el evento para pintar los resultados en el form
            ((SharedData <Resultados>)SharedMemory["Resultados"]).Set(0, new Resultados(_Proc.Z, _Proc.columnas, _Proc.Pixeles, _Proc.Puntos, _Proc.numeroMedidas, _Proc.distancia_a_la_chapa, id, ancho, largo, espesor, tol1, tol2, _Proc._Defectos1m, _Proc._Defectos2m));
            _Padre.PrepareEvent(_Name);



            // guardo al log los resultados
            _AuxLog.LOGTXTMessage = "New Plate measured : " + id + " Decission : " + _Proc._Decision + " Score : " + _Proc._Puntuacion + " Number of defects 1m : " + _Proc._Defectos1m + " Number of defects 2m : " + _Proc._Defectos2m;
            _Padre.Log.SetData(ref _AuxLog, "Informacion");

            //Envio por ftpj
            if (_Proc._EnviarFTP)
            {
                if (!File.Exists(id_file + ".tif"))
                {
                    File.Move("ZCORREGIDA.tif", id_file + ".tif");
                    _AuxLogError.LOGTXTMessage = "File " + id_file + ".tif" + " already exists in Imeges directory";
                    _Padre.Log.SetData(ref _AuxLogError, "Informacion");
                }
                _AuxFTP.FTP.FTPNombreArchivo = id_file + ".tif";
                _FTP.SetData(ref _AuxFTP, "SubirArchivo");
                if (_AuxFTP.FTPErrors != "")
                {
                    _AuxLogError.LOGTXTMessage = "Error sending via FTP : " + _AuxFTP.FTPErrors;
                    _Padre.Log.SetData(ref _AuxLogError, "Informacion");
                }
                File.Delete(id_file + ".tif");
            }
        }