Esempio n. 1
0
        public dynamic Clone()
        {
            TracePortData c_Clonado = new TracePortData();

            c_Clonado.port        = this.port;
            c_Clonado.temperature = this.temperature;
            c_Clonado.power       = this.power;
            c_Clonado.status      = this.status;
            c_Clonado.tool        = this.tool;
            // HT hot air stations
            c_Clonado.flow       = this.flow;
            c_Clonado.tempTC1    = this.tempTC1;
            c_Clonado.tempTC2    = this.tempTC2;
            c_Clonado.timetostop = this.timetostop;

            return(c_Clonado);
        }
Esempio n. 2
0
        private void TraceData()
        {
            ArrayList listStationsUUID = new ArrayList();
            stContinuousModeData_SOLD contData_SOLD   = default(stContinuousModeData_SOLD);  // solder data
            stContinuousModeData_HA   contData_HA     = new stContinuousModeData_HA();       // hot air data
            stContinuousModePort_SOLD contDataPort    = new stContinuousModePort_SOLD();     // solder data
            stContinuousModePort_HA   contDataPort_HA = new stContinuousModePort_HA();       // hot air data

            while (m_IsAliveThreadTraceData)
            {
                // update stations list
                listStationsUUID.Clear();
                listStationsUUID.AddRange(m_htStationUUID2QueueID.Keys);

                //Iteramos en todas las estaciones
                foreach (string stationUUID in listStationsUUID)
                {
                    uint queueID = (uint)(m_htStationUUID2QueueID[stationUUID]);

                    try
                    {
                        if (DLLConnection.jbc.StationExists(stationUUID))
                        {
                            eStationType stationType = DLLConnection.jbc.GetStationType(stationUUID);
                            int          dataLength  = DLLConnection.jbc.GetContinuousModeDataCount(stationUUID, queueID);

                            //Iteramos en todos los datos recogidos
                            for (int i = 0; i <= dataLength - 1; i++)
                            {
                                bool bDataExists = false;
                                switch (stationType)
                                {
                                case eStationType.SOLD:
                                    contData_SOLD = DLLConnection.jbc.GetContinuousModeNextData_SOLD(stationUUID, queueID);
                                    if (contData_SOLD.data != null)
                                    {
                                        bDataExists = true;
                                    }
                                    break;

                                case eStationType.HA:
                                    contData_HA = DLLConnection.jbc.GetContinuousModeNextData_HA(stationUUID, queueID);
                                    if (contData_HA.data != null)
                                    {
                                        bDataExists = true;
                                    }
                                    break;
                                }

                                if (bDataExists)
                                {
                                    Hashtable portJSONData = new Hashtable();

                                    foreach (Port port in m_mdhtStationUUID2PortData.RowKeys(stationUUID))
                                    {
                                        portJSONData[port] = "";

                                        //Cabecera de datos si secuencia es cero
                                        if (System.Convert.ToInt32(m_mdhtStationUUID2PortNumSequence.Item(stationUUID, port)) == 0)
                                        {
                                            // obtener la velocidad de la cola
                                            SpeedContinuousMode queueCaptureSpeed = DLLConnection.jbc.GetContinuousModeDeliverySpeed(stationUUID, queueID);
                                            CSpeedContMode      speedcm           = new CSpeedContMode();
                                            int frequency = speedcm.SpeedFromEnum(queueCaptureSpeed);

                                            portJSONData[port] = "{" + "\r\n" + "\"uuid\":\"" + stationUUID + "\"," +
                                                                 "\r\n" + "\"port\":" + System.Convert.ToString(port) + "," +
                                                                 "\r\n" + "\"time\":\"" + DateTime.Now.ToString(TRACE_TIME_FORMAT) + "\"," +
                                                                 "\r\n" + "\"name\":\"" + DLLConnection.jbc.GetStationName(stationUUID) + "\"," +
                                                                 "\r\n" + "\"type\":\"" + stationType.ToString() + "\"," +
                                                                 "\r\n" + "\"model\":\"" + DLLConnection.jbc.GetStationModel(stationUUID) + "\"," +
                                                                 "\r\n" + "\"modeltype\":\"" + DLLConnection.jbc.GetStationModelType(stationUUID) + "\"," +
                                                                 "\r\n" + "\"modelversion\":\"" + DLLConnection.jbc.GetStationModelVersion(stationUUID).ToString() + "\"," +
                                                                 "\r\n" + "\"software\":\"" + DLLConnection.jbc.GetStationSWversion(stationUUID) + "\"," +
                                                                 "\r\n" + "\"hardware\":\"" + DLLConnection.jbc.GetStationHWversion(stationUUID) + "\"," +
                                                                 "\r\n" + "\"interval\":" + System.Convert.ToString(frequency) + "," +
                                                                 "\r\n" + "\"data\":[";
                                        }
                                    }

                                    // cantidad de puertos
                                    int iDataPortCount = 0;
                                    switch (stationType)
                                    {
                                    case eStationType.SOLD:
                                        iDataPortCount = contData_SOLD.data.Length;
                                        break;

                                    case eStationType.HA:
                                        iDataPortCount = contData_HA.data.Length;
                                        break;
                                    }

                                    // datos de los puertos
                                    for (var x = 0; x <= iDataPortCount - 1; x++)
                                    {
                                        Port readingPort = Port.NO_PORT;

                                        switch (stationType)
                                        {
                                        case eStationType.SOLD:
                                            contDataPort = contData_SOLD.data[x];
                                            readingPort  = contDataPort.port;
                                            break;

                                        case eStationType.HA:
                                            contDataPort_HA = contData_HA.data[x];
                                            readingPort     = contDataPort_HA.port;
                                            break;
                                        }

                                        //Copiamos los datos del registro anterior para comparar al crear el json
                                        Hashtable antListPortData = new Hashtable();

                                        foreach (Port port in m_mdhtStationUUID2PortData.RowKeys(stationUUID))
                                        {
                                            antListPortData.Add(port, ((TracePortData)(m_mdhtStationUUID2PortData.Item(stationUUID, port))).Clone());
                                        }

                                        //Si el puerto lo estamos trazando
                                        if (m_mdhtStationUUID2PortData.Contains(stationUUID, readingPort))
                                        {
                                            TracePortData portData = default(TracePortData);

                                            switch (stationType)
                                            {
                                            case eStationType.SOLD:
                                                portData             = (TracePortData)(m_mdhtStationUUID2PortData.Item(stationUUID, readingPort));
                                                portData.port        = readingPort;
                                                portData.temperature = System.Convert.ToInt32(contDataPort.temperature.UTI);
                                                portData.power       = System.Convert.ToInt32(contDataPort.power);
                                                portData.status      = System.Convert.ToByte(contDataPort.status);
                                                portData.tool        = DLLConnection.jbc.GetPortToolID(stationUUID, portData.port);
                                                break;

                                            case eStationType.HA:
                                                portData             = (TracePortData)(m_mdhtStationUUID2PortData.Item(stationUUID, readingPort));
                                                portData.port        = readingPort;
                                                portData.temperature = contDataPort_HA.temperature.UTI;
                                                portData.power       = contDataPort_HA.power;
                                                portData.status      = System.Convert.ToByte(contDataPort_HA.status);
                                                portData.tool        = DLLConnection.jbc.GetPortToolID(stationUUID, portData.port);
                                                // HA
                                                portData.flow       = contDataPort_HA.flow;
                                                portData.tempTC1    = contDataPort_HA.externalTC1_Temp.UTI;
                                                portData.tempTC2    = contDataPort_HA.externalTC2_Temp.UTI;
                                                portData.timetostop = contDataPort_HA.timeToStop;
                                                break;
                                            }

                                            //Coma separador de entradas
                                            if (System.Convert.ToInt32(m_mdhtStationUUID2PortNumSequence.Item(stationUUID, readingPort)) != 0)
                                            {
                                                portJSONData[readingPort] = (portJSONData[readingPort]).ToString() + "," + "\r\n";
                                            }

                                            //Escribimos número de secuencia
                                            portJSONData[readingPort] = (portJSONData[readingPort]).ToString() + "{\"n\":" + System.Convert.ToString(m_mdhtStationUUID2PortNumSequence.Item(stationUUID, readingPort));

                                            //Notificar tool en la primera entrada de datos o cada vez que haya un cambio
                                            if (m_mdhtStationUUID2PortNumSequence.Item(stationUUID, readingPort) == 0 |
                                                portData.tool != ((TracePortData)(antListPortData[readingPort])).tool)
                                            {
                                                portJSONData[readingPort] = (portJSONData[readingPort]).ToString() + ", \"o\":" + System.Convert.ToString(portData.tool);
                                            }

                                            //Si no hay tool, no notificar el status, temperatura ni power
                                            if (portData.tool != GenericStationTools.NO_TOOL)
                                            {
                                                //Notificar status en la primera entrada de datos o cada vez que haya un cambio
                                                if (System.Convert.ToInt32(m_mdhtStationUUID2PortNumSequence.Item(stationUUID, readingPort)) == 0 |
                                                    portData.status != ((TracePortData)(antListPortData[readingPort])).status)
                                                {
                                                    portJSONData[readingPort] = (portJSONData[readingPort]).ToString() + ", \"s\":" + System.Convert.ToString(portData.status);
                                                }

                                                // temperature
                                                portJSONData[readingPort] = (portJSONData[readingPort]).ToString() + ", \"t\":" + System.Convert.ToString(portData.temperature);

                                                //Si status es extractor o hibernation no notificar el power
                                                if (portData.status != (byte)ToolStatus.EXTRACTOR &
                                                    portData.status != (byte)ToolStatus.HIBERNATION)
                                                {
                                                    portJSONData[readingPort] = (portJSONData[readingPort]).ToString() + ", \"w\":" + System.Convert.ToString(portData.power);
                                                }

                                                // HA
                                                if (stationType == eStationType.HA)
                                                {
                                                    // flow
                                                    portJSONData[readingPort] = (portJSONData[readingPort]).ToString() + ", \"f\":" + System.Convert.ToString(portData.flow);

                                                    // time to stop
                                                    portJSONData[readingPort] = (portJSONData[readingPort]).ToString() + ", \"ts\":" + System.Convert.ToString(portData.timetostop);

                                                    if (portData.tempTC1 > 0)
                                                    {
                                                        portJSONData[readingPort] = (portJSONData[readingPort]).ToString() + ", \"x1\":" + System.Convert.ToString(portData.tempTC1);
                                                    }

                                                    if (portData.tempTC2 > 0)
                                                    {
                                                        portJSONData[readingPort] = (portJSONData[readingPort]).ToString() + ", \"x2\":" + System.Convert.ToString(portData.tempTC2);
                                                    }
                                                }
                                            }

                                            portJSONData[readingPort] = (portJSONData[readingPort]).ToString() + "}";
                                            (new Microsoft.VisualBasic.Devices.ServerComputer()).FileSystem.WriteAllText(TempPathFilename(m_folderData, queueID, readingPort), (portJSONData[readingPort]).ToString(), true);
                                        }
                                    }

                                    //Incrementar numero de secuencia
                                    ArrayList listPorts = new ArrayList();
                                    listPorts.AddRange(m_mdhtStationUUID2PortNumSequence.RowKeys(stationUUID));

                                    foreach (Port port in listPorts)
                                    {
                                        m_mdhtStationUUID2PortNumSequence.Add(stationUUID, port, (System.Convert.ToInt32(m_mdhtStationUUID2PortNumSequence.Item(stationUUID, port))) + 1);

                                        //Final de fichero
                                        if (System.Convert.ToInt32(m_mdhtStationUUID2PortNumSequence.Item(stationUUID, port)) == FILE_MAX_SEQUENCE)
                                        {
                                            m_mdhtStationUUID2PortNumSequence.Add(stationUUID, port, 0);

                                            //Cierre y renombre del fichero con id único
                                            (new Microsoft.VisualBasic.Devices.ServerComputer()).FileSystem.WriteAllText(TempPathFilename(m_folderData, queueID, port), "]}", true);
                                            (new Microsoft.VisualBasic.Devices.ServerComputer()).FileSystem.MoveFile(TempPathFilename(m_folderData, queueID, port),
                                                                                                                     TracePathFilename(m_folderData, queueID, port, DateTime.Now));
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            // Stop trace data
                            m_htStationUUID2QueueID.Remove(stationUUID);
                            m_mdhtStationUUID2PortData.RemoveRow(stationUUID);
                            m_mdhtStationUUID2PortNumSequence.RemoveRow(stationUUID);

                            ArrayList listPorts = new ArrayList();
                            listPorts.AddRange(m_mdhtStationUUID2PortNumSequence.RowKeys(stationUUID));

                            foreach (Port port in listPorts)
                            {
                                //close and rename file with unique name
                                if (File.Exists(TempPathFilename(m_folderData, queueID, port)))
                                {
                                    (new Microsoft.VisualBasic.Devices.ServerComputer()).FileSystem.WriteAllText(TempPathFilename(m_folderData, queueID, port), "]}", true);
                                }
                                if (File.Exists(TempPathFilename(m_folderData, queueID, port)))
                                {
                                    (new Microsoft.VisualBasic.Devices.ServerComputer()).FileSystem.MoveFile(TempPathFilename(m_folderData, queueID, port),
                                                                                                             TracePathFilename(m_folderData, queueID, port, DateTime.Now));
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        // error
                        //Stop trace data
                        m_htStationUUID2QueueID.Remove(stationUUID);
                        m_mdhtStationUUID2PortData.RemoveRow(stationUUID);
                        m_mdhtStationUUID2PortNumSequence.RemoveRow(stationUUID);

                        ArrayList listPorts = new ArrayList();
                        listPorts.AddRange(m_mdhtStationUUID2PortNumSequence.RowKeys(stationUUID));

                        foreach (Port port in listPorts)
                        {
                            //close and rename file with unique name
                            if (File.Exists(TempPathFilename(m_folderData, queueID, port)))
                            {
                                (new Microsoft.VisualBasic.Devices.ServerComputer()).FileSystem.WriteAllText(TempPathFilename(m_folderData, queueID, port), "]}", true);
                                (new Microsoft.VisualBasic.Devices.ServerComputer()).FileSystem.MoveFile(TempPathFilename(m_folderData, queueID, port),
                                                                                                         TracePathFilename(m_folderData, queueID, port, DateTime.Now));
                            }
                        }
                    }
                }

                Thread.Sleep(THREAD_SLEEP_TRACE_DATA);
            }
        }