Ejemplo n.º 1
0
        protected override void RaiseNewConnection(CStationBase.Protocol commandProtocol, string sStationModel, string SoftwareVersion, string HardwareVersion)
        {
            // Cambia de referencia al puerto porque la anterior ya ha sido asignada
            RoutinesLibrary.Net.Protocols.TCP.TCP WinSock_Connected = WinSockIn;
            WinSockIn = null;

            //Cuando una estacion con un k60 esta apagada pero el usb esta conectado, sigue alimentandose.
            if (CheckStationModel(sStationModel))
            {
                //Genera el evento Nueva conexion, de protocolo de conexión/trama 02
                CConnectionData connectionData = new CConnectionData();
                connectionData.Mode             = SearchMode.ETH;
                connectionData.pWinSock         = WinSock_Connected;
                connectionData.PCNumDevice      = m_pcNumDevice;
                connectionData.StationNumDevice = m_stationNumDevice;
                connectionData.FrameProtocol    = m_Conection_FrameProtocol;
                connectionData.CommandProtocol  = commandProtocol;
                connectionData.StationModel     = sStationModel;
                connectionData.SoftwareVersion  = SoftwareVersion;
                connectionData.HardwareVersion  = HardwareVersion;

                if (NewConnectionEvent != null)
                {
                    NewConnectionEvent(ref connectionData);
                }
            }
            else
            {
                CloseWinSock(ref WinSock_Connected);
                m_Timer_Search.Stop();
                m_Timer_Search.Interval = MS_NEW_SEARCH;
                m_Timer_Search.Start();
            }
        }
Ejemplo n.º 2
0
        internal Stack_dll(ref RoutinesLibrary.Net.Protocols.TCP.TCP WinSock, byte _pcNumDevice, CStationBase.Protocol _FrameProtocol, EnumFrameFlowControl _Flowcontrol, int frameWindow)
        {
            m_phl = new Stack_phl(WinSock, (MAX_FRAME_LENGTH * frameWindow) + MAX_FRAME_LENGTH);
            m_phl.DataReceived += phl_DataReceived;
            m_phl.ErrorConnect += phl_ErrorConnect;

            Initialize(_pcNumDevice, _FrameProtocol, _Flowcontrol, frameWindow);
        }
Ejemplo n.º 3
0
 internal Stack_phl(RoutinesLibrary.Net.Protocols.TCP.TCP WinSock, int FrameWindowSizeInBytes)
 {
     m_WinSockClient_Int = WinSock;
     m_WinSockClient_Int.DataReceived        += new RoutinesLibrary.Net.Protocols.TCP.TCP.DataReceivedEventHandler(WinSockClient_Int_DataReceived);
     m_WinSockClient_Int.ClosedConnectionTCP += new RoutinesLibrary.Net.Protocols.TCP.TCP.ClosedConnectionTCPEventHandler(WinSockClient_Int_ClosedConnection);
     m_WinSockClient_Int.BufferSize           = FrameWindowSizeInBytes;
     m_TypeConnect = EnumConnect.TCP;
 }
Ejemplo n.º 4
0
        public CCommunicationChannel(CConnectionData connectionData)
        {
            m_mode          = connectionData.Mode;
            m_sourceAddress = connectionData.PCNumDevice;

            if (m_mode == SearchMode.USB)
            {
                m_pSerialPort = connectionData.pSerialPort;
            }
            else if (m_mode == SearchMode.ETH)
            {
                m_pWinSock = connectionData.pWinSock;
            }

            m_frameProtocol = connectionData.FrameProtocol;
        }
Ejemplo n.º 5
0
 internal void Eraser()
 {
     //Debug.Print("StackPhl.Eraser")
     if (m_TypeConnect == EnumConnect.USB)
     {
         m_SerialPort_Int.Dispose();
         m_SerialPort_Int.DataReceived -= new RoutinesLibrary.IO.SerialPort.DataReceivedEventHandler(SerialPort_Int_DataReceived);
         m_SerialPort_Int = null;
     }
     else if (m_TypeConnect == EnumConnect.TCP)
     {
         m_WinSockClient_Int.Dispose();
         m_WinSockClient_Int.DataReceived        -= new RoutinesLibrary.Net.Protocols.TCP.TCP.DataReceivedEventHandler(WinSockClient_Int_DataReceived);
         m_WinSockClient_Int.ClosedConnectionTCP -= new RoutinesLibrary.Net.Protocols.TCP.TCP.ClosedConnectionTCPEventHandler(WinSockClient_Int_ClosedConnection);
         m_WinSockClient_Int = null;
     }
 }
Ejemplo n.º 6
0
 private void CloseWinSock(ref RoutinesLibrary.Net.Protocols.TCP.TCP _WinSock)
 {
     try
     {
         if (_WinSock != null)
         {
             // marca como no conectado
             int idx = discoveredStations.ExistsStation(_WinSock.HostEndPoint);
             if (idx >= 0)
             {
                 //Debug.Print("SearchTCP - CloseWinSock - marca como no conectada")
                 discoveredStations.set_Connected(idx, false);
                 //discoveredStations.StationWinSock(idx) = Nothing
             }
             _WinSock.Dispose();
             _WinSock = null;
         }
     }
     catch (Exception)
     {
     }
 }
Ejemplo n.º 7
0
 internal void StopSearch()
 {
     iRefreshUDPCount = -1;
     bRefreshUDPForce = false;
     if (searchStationsUPD.IsSearching())
     {
         StopUDPDiscover();
     }
     m_StatusConnect         = StatusConnect.StopSearch;
     m_Timer_Search.Interval = MS_WAIT_SEARCH;
     m_Timer_Search.Enabled  = false;
     if (WinSockIn != null)
     {
         try
         {
             CloseWinSock(ref WinSockIn);
             WinSockIn = null;
         }
         catch (Exception)
         {
         }
     }
 }
Ejemplo n.º 8
0
        public void Dispose()
        {
            m_mutexStackAddressMessages.WaitOne();

            if (m_htStackAddressMessages != null)
            {
                foreach (DictionaryEntry stack in m_htStackAddressMessages)
                {
                    ((CStackMessages)stack.Value).Dispose();
                }
                m_htStackAddressMessages.Clear();
                m_htStackAddressMessages = null;
            }

            m_mutexStackAddressMessages.Release();

            m_pSerialPort = null;
            m_pWinSock    = null;

            m_mutexStackDll.WaitOne();
            if (m_StackDll != null)
            {
#if LibraryTest
                m_StackDll.DataSentFrame             -= StackDll_DataSentFrame;
                m_StackDll.DataReceivedFrame         -= StackDll_DataReceivedFrame;
                m_StackDll.DataReceivedFrameMessages -= StackDll_DataReceivedFrame_Burst;
                m_StackDll.DataSentRawData           -= StackDll_DataSentRawData;
                m_StackDll.DataReceivedRawData       -= StackDll_DataReceivedRawData;
#endif
                m_StackDll.Eraser();
                m_StackDll = null;
                //m_StackDll.DataReceived += DataReceived;
                //m_StackDll.DataReceivedMessages += DataReceived_Burst;
                //m_StackDll.ErrorConnect += Event_ConnectionError;
            }
            m_mutexStackDll.Release();
        }
Ejemplo n.º 9
0
        public void Timer_Search_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            //Este timer se desactiva siempre al entrar y se debe hacer un start siempre qu se salga
            bool   bRestartTimer = true;
            string sError        = "";

            lock (m_LockTimer)
            {
                StatusConnect StatusConnect_New = new StatusConnect();
                IPEndPoint    NumEndPoint       = default(IPEndPoint);

                switch (m_StatusConnect)
                {
                case StatusConnect.StopSearch:
                    // si se solicitó un puerto
                    if (!string.IsNullOrEmpty(EndPointSearch))
                    {
                        bRestartTimer = false;
                    }
                    break;

                case StatusConnect.WaitSearch:
                    // iRefreshUDPCount = -1 Detenida la actualización
                    if (iRefreshUDPCount >= 0)
                    {
                        iRefreshUDPCount++;
                    }
                    if (iRefreshUDPCount >= iRefreshUDPinWaitSearch || bRefreshUDPForce)
                    {
                        myRefreshStationList();
                        iRefreshUDPCount = 0;
                    }

                    IndexStation = discoveredStations.Number - 1;

                    StatusConnect_New       = StatusConnect.Search;
                    m_Timer_Search.Interval = MS_NEW_SEARCH;
                    break;

                case StatusConnect.Search:
                    try
                    {
                        if (!string.IsNullOrEmpty(EndPointSearch))
                        {
                            string[] aIPPort = EndPointSearch.Split(':');
                            WinSockIn = new RoutinesLibrary.Net.Protocols.TCP.TCP(new IPEndPoint(IPAddress.Parse(aIPPort[0].Trim()), System.Convert.ToInt32(ushort.Parse(aIPPort[1].Trim()))));
                            WinSockIn.ClosedConnectionTCP += new RoutinesLibrary.Net.Protocols.TCP.TCP.ClosedConnectionTCPEventHandler(WinSockIn_FinishConnection);
                            WinSockIn.DataReceived        += new RoutinesLibrary.Net.Protocols.TCP.TCP.DataReceivedEventHandler(WinSockIn_DataReceived);
                            if (WinSockIn.Connect(ref sError))
                            {
                                m_Timer_Search.Interval = MS_WAIT_NAK;
                                StatusConnect_New       = StatusConnect.WaitNAKorHS;
                                m_FrameDataIn01.Reset();     // preparar buffer de entrada
                                m_FrameDataOut01.Reset();    // preparar buffer de salida
                                m_FrameDataIn02.Reset();     // preparar buffer de entrada
                                m_FrameDataOut02.Reset();    // preparar buffer de salida
                                m_Conection_FrameProtocol = CStationBase.Protocol.Protocol_undefined;
                            }
                            else
                            {
                                //Error. Se prepara para una nueva busqueda
                                StatusConnect_New = StatusConnect.Search;
                                if (m_Timer_Search != null)
                                {
                                    m_Timer_Search.Interval = MS_NEW_SEARCH; //Genera un nuevo evento lo antes posible
                                }
                                CloseWinSock(ref WinSockIn);                 // se elimina el puerto creado
                            }
                        }
                        else if (IndexStation < 0)
                        {
                            StatusConnect_New       = StatusConnect.WaitSearch;
                            m_Timer_Search.Interval = MS_WAIT_SEARCH;
                        }
                        else
                        {
                            // define the next indexstation
                            while (IndexStation >= 0)
                            {
                                if (discoveredStations.get_Connected(IndexStation))
                                {
                                    IndexStation--;
                                }
                                else
                                {
                                    break;
                                }
                            }

                            if (IndexStation < 0)
                            {
                                StatusConnect_New       = StatusConnect.WaitSearch;
                                m_Timer_Search.Interval = MS_WAIT_SEARCH;
                            }
                            else
                            {
                                NumEndPoint = discoveredStations.GetStation(IndexStation).StationData.IPEndPointValue;
                                WinSockIn   = new RoutinesLibrary.Net.Protocols.TCP.TCP(new IPEndPoint(NumEndPoint.Address, System.Convert.ToInt32((ushort)NumEndPoint.Port)));
                                WinSockIn.ClosedConnectionTCP += new RoutinesLibrary.Net.Protocols.TCP.TCP.ClosedConnectionTCPEventHandler(WinSockIn_FinishConnection);
                                WinSockIn.DataReceived        += new RoutinesLibrary.Net.Protocols.TCP.TCP.DataReceivedEventHandler(WinSockIn_DataReceived);
                                if (WinSockIn.Connect(ref sError))
                                {
                                    //Debug.Print("SearchTCP WinSockIn.Connect true: " & NumEndPoint.ToString)
                                    m_Timer_Search.Interval = MS_WAIT_NAK;
                                    StatusConnect_New       = StatusConnect.WaitNAKorHS;
                                    m_FrameDataIn01.Reset();     // preparar buffer de entrada
                                    m_FrameDataOut01.Reset();    // preparar buffer de salida
                                    m_FrameDataIn02.Reset();     // preparar buffer de entrada
                                    m_FrameDataOut02.Reset();    // preparar buffer de salida
                                    m_Conection_FrameProtocol = CStationBase.Protocol.Protocol_undefined;
                                }
                                else
                                {
                                    //Debug.Print("SearchTCP WinSockIn.Connect false: " & NumEndPoint.ToString)
                                    //Error. Se prepara para una nueva busqueda
                                    StatusConnect_New = StatusConnect.Search;
                                    if (m_Timer_Search != null)
                                    {
                                        m_Timer_Search.Interval = MS_NEW_SEARCH; //Genera un nuevo evento lo antes posible
                                    }
                                    CloseWinSock(ref WinSockIn);                 // se elimina el puerto creado
                                }
                                IndexStation--;
                            }
                        }
                    }
                    catch (Exception)
                    {
                        //Debug.Print("SearchTCP Exception in Search: " & ex.Message)
                        //Error. Se prepara para una nueva busqueda
                        StatusConnect_New = StatusConnect.Search;
                        if (m_Timer_Search != null)
                        {
                            m_Timer_Search.Interval = MS_NEW_SEARCH; //Genera un nuevo evento lo antes posible
                        }
                        CloseWinSock(ref WinSockIn);                 // se elimina el puerto creado
                        IndexStation--;
                    }
                    break;

                case StatusConnect.WaitNAKorHS:
                case StatusConnect.WaitFW:
                case StatusConnect.WaitHS:
                case StatusConnect.WaitACK:
                case StatusConnect.WaitNum:
                    //TimeOut. Se prepara para una nueva busqueda
                    //Debug.Print("SearchTCP TimeOut en StatusConnect: " & StatusConnect.ToString)
                    StatusConnect_New       = StatusConnect.Search;
                    m_Timer_Search.Interval = MS_NEW_SEARCH; //Genera un nuevo evento lo antes posible
                    CloseWinSock(ref WinSockIn);             // se elimina el puerto creado

                    // si se solicitó una dirección específica, reintentar y luego parar
                    if (!string.IsNullOrEmpty(EndPointSearch))
                    {
                        if (iReintentosSobreEndPointSolicitado >= MAX_REINTENTOS_SOBRE_ENDPOINT_SOLICITADO)
                        {
                            if (NoConexionEvent != null)
                            {
                                NoConexionEvent(EndPointSearch);
                            }
                            m_StatusConnect = StatusConnect.StopSearch;
                            // no rearranca el timer
                            bRestartTimer = false;
                        }
                        else
                        {
                            iReintentosSobreEndPointSolicitado++;
                        }
                    }
                    else
                    {
                        IndexStation--;
                    }
                    break;
                }

                m_reintentos   += 1;
                m_StatusConnect = StatusConnect_New;

                try
                {
                    if (bRestartTimer && m_Timer_Search != null)
                    {
                        m_Timer_Search.Start();
                    }
                }
                catch (Exception)
                {
                }
            }
        }