示例#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);
        }
示例#2
0
        private void TraceData()
        {
            ArrayList listStationUID                  = new ArrayList();
            Hashtable listPortData                    = default(Hashtable);
            ArrayList listPortDataKey                 = new ArrayList();
            Hashtable antListPortData                 = new Hashtable();
            stContinuousModeData_SOLD contData        = new 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

            do
            {
                // update stations
                listStationUID.Clear();
                listStationUID.AddRange(m_htStationQueue.Keys);

                //Iteramos en todas las estaciones
                foreach (string stationUID in listStationUID)
                {
                    long stationID = -1;
                    //Dim stationType As dc_EnumConstJBC.dc_StationType = dc_EnumConstJBC.dc_StationType.UNKNOWN
                    eStationType stationType = eStationType.UNKNOWN;

                    try
                    {
                        stationID   = DLLConnection.jbc.GetStationID(stationUID);
                        stationType = DLLConnection.jbc.GetStationType(stationID);

                        if (stationID >= 0)
                        {
                            string JSONData = "";

                            //Listado de puertos que estamos trazando para la estación
                            listPortData = (Hashtable)(m_htStationPortsData[stationUID]);
                            listPortDataKey.Clear();
                            listPortDataKey.AddRange(listPortData.Keys);

                            int dataLength = DLLConnection.jbc.GetContinuousModeDataCount(stationID, (uint)(m_htStationQueue[stationUID]));
                            evlogWrite("Data records to process:" + dataLength.ToString(), stationUID);
                            for (int i = 0; i <= dataLength - 1; i++)
                            {
                                bool bDataExists = false;
                                switch (stationType)
                                {
                                case eStationType.SOLD:
                                    contData = DLLConnection.jbc.GetContinuousModeNextData_SOLD(stationID, (uint)(m_htStationQueue[stationUID]));
                                    if (contData.data != null)
                                    {
                                        bDataExists = true;
                                    }
                                    break;

                                case eStationType.HA:
                                    contData_HA = DLLConnection.jbc.GetContinuousModeNextData_HA(stationID, (uint)(m_htStationQueue[stationUID]));
                                    if (contData_HA.data != null)
                                    {
                                        bDataExists = true;
                                    }
                                    break;
                                }

                                if (bDataExists)
                                {
                                    JSONData = "";

                                    //Cabecera de datos si secuencia es cero
                                    if (System.Convert.ToInt32(m_htStationNumSequence[stationUID]) == 0)
                                    {
                                        // obtener la velocidad de la cola
                                        SpeedContinuousMode queueCaptureSpeed = DLLConnection.jbc.GetContinuousModeDeliverySpeed(stationID, (uint)(m_htStationQueue[stationUID]));
                                        // convertirla a integer
                                        CSpeedContMode speedcm   = new CSpeedContMode();
                                        int            frequency = speedcm.SpeedFromEnum(queueCaptureSpeed);
                                        // obtener datos identificativos
                                        string stnName         = DLLConnection.jbc.GetStationName(stationID);
                                        string stnModel        = DLLConnection.jbc.GetStationModel(stationID);
                                        string stnModelType    = DLLConnection.jbc.GetStationModelType(stationID);
                                        string stnModelVersion = DLLConnection.jbc.GetStationModelVersion(stationID).ToString();
                                        string stnSW           = DLLConnection.jbc.GetStationSWversion(stationID);
                                        string stnHW           = DLLConnection.jbc.GetStationHWversion(stationID);

                                        JSONData = "{" + "\r\n" + "\"id\":\"" + stationUID + "\"," +
                                                   "\r\n" + "\"time\":\"" + DateTime.Now.ToString(TRACE_TIME_FORMAT) + "\"," +
                                                   "\r\n" + "\"name\":\"" + stnName + "\"," +
                                                   "\r\n" + "\"type\":\"" + stationType.ToString() + "\"," +
                                                   "\r\n" + "\"model\":\"" + stnModel + "\"," +
                                                   "\r\n" + "\"modeltype\":\"" + stnModelType + "\"," +
                                                   "\r\n" + "\"modelversion\":\"" + stnModelVersion + "\"," +
                                                   "\r\n" + "\"software\":\"" + stnSW + "\"," +
                                                   "\r\n" + "\"hardware\":\"" + stnHW + "\"," +
                                                   "\r\n" + "\"interval\":" + System.Convert.ToString(frequency);
                                    }

                                    //Por cada puerto del modo continuo
                                    bool bComma = false;

                                    //Escribimos número de secuencia y datos
                                    JSONData += "," + "\r\n" + "\"" + System.Convert.ToString(m_htStationNumSequence[stationUID]) + "\":[";

                                    // datos de los puertos

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

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

                                    // datos de los puertos
                                    //For Each contDataPort As stContinuousModePort In contData.data
                                    for (var x = 0; x <= iDataPortCount - 1; x++)
                                    {
                                        Port readingPort = Port.NO_PORT;
                                        switch (stationType)
                                        {
                                        case eStationType.SOLD:
                                            contDataPort = contData.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
                                        TracePortData portData = new TracePortData();
                                        antListPortData.Clear();
                                        foreach (Port portDataKey in listPortDataKey)
                                        {
                                            portData = (TracePortData)(listPortData[portDataKey]);
                                            antListPortData.Add(portDataKey, portData.Clone());
                                        }

                                        //Si el puerto lo estamos trazando
                                        if (listPortData.Contains(readingPort))
                                        {
                                            switch (stationType)
                                            {
                                            case eStationType.SOLD:
                                                portData             = (TracePortData)(((TracePortData)(listPortData[contDataPort.port])).Clone());
                                                portData.port        = contDataPort.port;
                                                portData.temperature = contDataPort.temperature.UTI;
                                                portData.power       = contDataPort.power;
                                                portData.status      = System.Convert.ToByte(contDataPort.status);
                                                portData.tool        = DLLConnection.jbc.GetPortToolID(stationID, portData.port);
                                                break;

                                            case eStationType.HA:
                                                portData             = (TracePortData)(((TracePortData)(listPortData[contDataPort_HA.port])).Clone());
                                                portData.port        = contDataPort_HA.port;
                                                portData.temperature = contDataPort_HA.temperature.UTI;
                                                portData.power       = contDataPort_HA.power;
                                                portData.status      = System.Convert.ToByte(contDataPort_HA.status);
                                                portData.tool        = DLLConnection.jbc.GetPortToolID(stationID, 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;
                                            }

                                            if (bComma)
                                            {
                                                JSONData += ",";
                                            }
                                            bComma = true;

                                            JSONData += "\r\n" + "{\"p\":" + System.Convert.ToString(portData.port);

                                            //Notificar tool en la primera entrada de datos o cada vez que haya un cambio
                                            // LA TOOL en TEXTO
                                            if (System.Convert.ToInt32(m_htStationNumSequence[stationUID]) == 0 | portData.tool != ((TracePortData)(antListPortData[portData.port])).tool)
                                            {
                                                JSONData += ", \"o\":" + System.Convert.ToString(portData.tool) + "";
                                            }

                                            //Si no hay tool, no notificar de 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_htStationNumSequence[stationUID]) == 0 | portData.status != ((TracePortData)(antListPortData[portData.port])).status)
                                                {
                                                    JSONData += ", \"s\":" + System.Convert.ToString(portData.status);
                                                }

                                                // temperature
                                                JSONData += ", \"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)
                                                {
                                                    JSONData += ", \"w\":" + System.Convert.ToString(portData.power);
                                                }

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

                                                    // time to stop (en décimas de segundo)
                                                    JSONData += ", \"ts\":" + System.Convert.ToString(portData.timetostop);

                                                    // viene &HFF si no hay termopar externo
                                                    if (portData.tempTC1 > 0 & portData.tempTC1 < 0xFF)
                                                    {
                                                        JSONData += ", \"x1\":" + System.Convert.ToString(portData.tempTC1);
                                                    }

                                                    // viene &HFF si no hay termopar externo
                                                    if (portData.tempTC2 > 0 & portData.tempTC2 < 0xFF)
                                                    {
                                                        JSONData += ", \"x2\":" + System.Convert.ToString(portData.tempTC2);
                                                    }
                                                }
                                            }

                                            JSONData += "}";
                                        }
                                    } // For Each contDataPort As stContinuousModePort In contData.data

                                    JSONData += "\r\n" + "]";
                                    (new Microsoft.VisualBasic.Devices.ServerComputer()).FileSystem.WriteAllText(tempPathFilename(m_folderData, stationID), JSONData, true);

                                    //Incrementar numero de secuencia
                                    m_htStationNumSequence[stationUID] = (System.Convert.ToInt32(m_htStationNumSequence[stationUID])) + 1;

                                    //Final de fichero
                                    if (System.Convert.ToInt32(m_htStationNumSequence[stationUID]) == m_MaxNumSequence)
                                    {
                                        m_htStationNumSequence[stationUID] = 0;

                                        //Cierre y renombre del fichero con id único
                                        (new Microsoft.VisualBasic.Devices.ServerComputer()).FileSystem.WriteAllText(tempPathFilename(m_folderData, stationID), "}", true);
                                        (new Microsoft.VisualBasic.Devices.ServerComputer()).FileSystem.MoveFile(tempPathFilename(m_folderData, stationID), tracePathFilename(m_folderData, stationID, DateTime.Now));
                                    }
                                } // If contData.data IsNot Nothing Then
                            }     // For i As Integer = 0 To dataLength
                        }
                        else
                        {
                            // station ID not found (disconnected?)
                            // Stop trace data
                            m_htStationQueue.Remove(stationUID);
                            m_htStationID.Remove(stationUID);
                            m_htStationPortsData.Remove(stationUID);
                            m_htStationNumSequence.Remove(stationUID);
                            m_htStationSpeed.Remove(stationUID);

                            //close and rename file with unique name
                            if (File.Exists(tempPathFilename(m_folderData, stationID)))
                            {
                                (new Microsoft.VisualBasic.Devices.ServerComputer()).FileSystem.WriteAllText(tempPathFilename(m_folderData, stationID), "}", true);
                            }
                            if (File.Exists(tempPathFilename(m_folderData, stationID)))
                            {
                                (new Microsoft.VisualBasic.Devices.ServerComputer()).FileSystem.MoveFile(tempPathFilename(m_folderData, stationID), tracePathFilename(m_folderData, stationID, DateTime.Now));
                            }

                            evlogWrite("Station ID not found. Station disconnected?", stationUID);
                        }
                    }
                    catch (Exception ex)
                    {
                        // error
                        //Stop trace data
                        m_htStationQueue.Remove(stationUID);
                        m_htStationID.Remove(stationUID);
                        m_htStationPortsData.Remove(stationUID);
                        m_htStationNumSequence.Remove(stationUID);
                        m_htStationSpeed.Remove(stationUID);

                        //close and rename file with unique name
                        if (File.Exists(tempPathFilename(m_folderData, stationID)))
                        {
                            (new Microsoft.VisualBasic.Devices.ServerComputer()).FileSystem.WriteAllText(tempPathFilename(m_folderData, stationID), "}", true);
                            (new Microsoft.VisualBasic.Devices.ServerComputer()).FileSystem.MoveFile(tempPathFilename(m_folderData, stationID), tracePathFilename(m_folderData, stationID, DateTime.Now));
                        }

                        evlogWrite(System.Reflection.MethodBase.GetCurrentMethod().Name + ". Error: " + ex.Message, stationUID);
                    }
                }

                Thread.Sleep(frequencyTrace);
            } while (true);
        }