Exemplo n.º 1
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);
            }
        }
Exemplo n.º 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);
        }