예제 #1
0
 public static Channel GetChannel(Channel channel)
 {
     if (channel is Serial)
     {
         Serial serial = channel as Serial;
         return(GetChannel(serial.PortName));
     }
     else if (channel is Ethernet)
     {
         Ethernet ethernet = channel as Ethernet;
         return(GetChannel(ethernet.RemoteIP, ethernet.RemotePort));
     }
     else if (channel is EthernetListener)
     {
         EthernetListener listener = channel as EthernetListener;
         return(GetChannel(listener.LocalPort));
     }
     else if (channel is ListenerServer)
     {
         ListenerServer listenerServer = channel as ListenerServer;
         ListenerServer result;
         GetChannel(listenerServer.LocalPort, out result);
         return(result);
     }
     else
     {
         return(null);
     }
 }
예제 #2
0
        public static void GetChannel(int port, out ListenerServer listenerServer)
        {
            try
            {
                foreach (Channel c in m_channels)
                {
                    if (c.GetType() == typeof(ListenerServer))
                    {
                        ListenerServer listener = c as ListenerServer;
                        if (listener.LocalPort == port)
                        {
                            listenerServer = listener;
                            return;
                        }
                    }
                }

                listenerServer = null;
            }
            catch (ComDriveExceptions ex)
            {
                throw;
            }
            catch (Exception ex)
            {
                string exceptionText = ex.GetType().ToString() + ": " + ex.Message + "\n\n" + ex.StackTrace;
                ComDriverLogger.LogExceptions(DateTime.Now, exceptionText);
                throw;
            }
        }
예제 #3
0
        public static void GetPLC(ListenerServer litenerServer)
        {
            try
            {
                bool           isConnected = false;
                Channel        plcChannel  = getChannel(litenerServer, ref isConnected);
                ListenerServer listener    = plcChannel as ListenerServer;
                if (listener == null)
                {
                    throw new ComDriveExceptions("Listener Server could not be intialized due to unexpected error",
                                                 ComDriveExceptions.ComDriveException.UnexpectedError);
                }

                listener.Listen();
            }
            catch (ComDriveExceptions ex)
            {
                throw;
            }
            catch (Exception ex)
            {
                string exceptionText = ex.GetType().ToString() + ": " + ex.Message + "\n\n" + ex.StackTrace;
                ComDriverLogger.LogExceptions(DateTime.Now, exceptionText);
                throw;
            }
        }
예제 #4
0
        internal override bool IsEquivalentChannel(Channel anotherChanel)
        {
            ListenerServer listenerServer = anotherChanel as ListenerServer;

            if (listenerServer.LocalPort == m_LocalPort)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #5
0
 internal static bool ValidateChannelPropertyChange(ListenerServer channel, int newPort)
 {
     if (!m_channels.Contains(channel))
     {
         return(true);
     }
     else
     {
         ListenerServer listener;
         GetChannel(newPort, out listener);
         if (listener == null)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }