Esempio n. 1
0
        public static Ethernet GetChannel(string remoteIp, Int32 remotePort)
        {
            try
            {
                foreach (Channel c in m_channels)
                {
                    if (c.GetType() == typeof(Ethernet))
                    {
                        Ethernet ethernet = c as Ethernet;
                        if ((ethernet.RemoteIP == remoteIp) && (ethernet.RemotePort == remotePort))
                        {
                            return(ethernet);
                        }
                    }
                }

                return(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;
            }
        }
Esempio n. 2
0
        public static void main()
        {
            //Haussteuerung
            {
                Channel ch  = new Ethernet("192.168.47.12", 20257, EthProtocol.TCP);
                PLC     plc = PLCFactory.GetPLC(ch, 0);
                Console.WriteLine(plc.PlcName);
                plc.SetExecuter(OperandsExecuterType.ExecuterPartialBinaryMix);

                Console.WriteLine(plc.Version + "\t");
                Console.WriteLine(plc.RTC + "\tPLC Timer \n" + System.DateTime.Now + "\tUTC Time");

                plc_Kompressor     plcKompressor = new plc_Kompressor(ch);
                ReadWriteRequest[] rw            = plcKompressor.init();


                int j = 0;
                while (j < 30)
                {
                    plcKompressor.readData();
                    Thread.Sleep(1000);
                    j++;
                }
            }
        }
Esempio n. 3
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);
     }
 }
Esempio n. 4
0
        internal override bool IsEquivalentChannel(Channel anotherChanel)
        {
            Ethernet ethernet = anotherChanel as Ethernet;

            if ((ethernet.RemoteIP == m_remoteIPorHostName) && (ethernet.m_remotePort == m_remotePort))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 5
0
 internal static bool ValidateChannelPropertyChange(Ethernet channel, string newIp, int newPort)
 {
     if (!m_channels.Contains(channel))
     {
         return(true);
     }
     else
     {
         Ethernet ethernet = GetChannel(newIp, newPort);
         if (ethernet == null)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Esempio n. 6
0
        public static void main()
        {
            //Haussteuerung
            {
                Channel ch  = new Ethernet("192.168.47.6", 20257, EthProtocol.TCP);
                PLC     plc = PLCFactory.GetPLC(ch, 0);
                Console.WriteLine(plc.PlcName);
                plc.SetExecuter(OperandsExecuterType.ExecuterPartialBinaryMix);

                Console.WriteLine(plc.Version + "\t");
                Console.WriteLine(plc.RTC + "\tPLC Timer \n" + System.DateTime.Now + "\tUTC Time");
//Until here
                plc_haussterung    plcHaussterung = new plc_haussterung(ch);
                ReadWriteRequest[] rw             = plcHaussterung.init();

                while (true)
                {
                    plcHaussterung.readData();
                    Thread.Sleep(60000);
                }
            }


            //Kompressor

            /*  {
             *    Channel ch = new Ethernet("192.168.47.12", 20256, EthProtocol.TCP);
             *    PLC plc = PLCFactory.GetPLC(ch, 0);
             *    Console.WriteLine(plc.PlcName);
             *    plc.SetExecuter(OperandsExecuterType.ExecuterPartialBinaryMix);
             *
             *    Console.WriteLine(plc.Version);
             *    Console.WriteLine(plc.PLCChannel);
             *    Console.WriteLine(plc.RTC + " \t" + System.DateTime.Now);
             *
             *    object[] values = new object[2048];
             *    for (int i = 0; i < values.Length; i++)
             *    {
             *        values[i] = (object) i;
             *    }
             *
             *    ReadWriteRequest[] rw = new ReadWriteRequest[1];
             *
             *    ReadWriteRequest getCurr = new ReadOperands
             *    {
             *        NumberOfOperands = 1,
             *        OperandType = OperandTypes.TimerPreset,
             *        StartAddress = 0,
             *        TimerValueFormat = TimerValueFormat.TimeFormat,
             *    };
             *    rw[0] = getCurr;
             *    try
             *    {
             *        plc.ReadWrite(ref rw);
             *        Console.WriteLine(rw[0].ResponseValues);
             *    }
             *    catch (Exception e)
             *    {
             *        Console.WriteLine(e.Message + ":" + e.StackTrace);
             *        throw;
             *    }
             *
             * }*/
        }
Esempio n. 7
0
        private static Channel getChannel(Channel channel, ref bool isConnected)
        {
            lock (objectLocker)
            {
                if (m_channels.Contains(channel) || channel is ListenerClient)
                {
                    //there is already a channel with the same configuration
                    try
                    {
                        isConnected = channel.Connected;
                    }
                    catch
                    {
                    }

                    return(channel);
                }
                else
                {
                    if (m_channels.Count == 0) //no channels
                    {
                        try
                        {
                            isConnected = channel.Connected;
                        }
                        catch
                        {
                        }

                        if (channel.GetType() == typeof(EthernetListener))
                        {
                            EthernetListener listener = channel as EthernetListener;
                            //listener.Listen();
                            listener.AlreadyInitialized = false;
                            m_channels.Add(channel);
                            return(channel);
                        }
                        else
                        {
                            channel.Connect();
                            channel.AlreadyInitialized = false;
                            m_channels.Add(channel);
                            return(channel);
                        }
                    }
                    else
                    {
                        foreach (Channel c in m_channels)
                        {
                            if (c.GetType() == channel.GetType())
                            {
                                if (c.IsEquivalentChannel(channel))
                                {
                                    try
                                    {
                                        isConnected = c.Connected;
                                    }
                                    catch
                                    {
                                    }

                                    // if Serial port name is the same or Ethernet IP:Port is the same then...
                                    if (c.GetType() == typeof(Serial))
                                    {
                                        Serial openedChannel = c as Serial;
                                        Serial newChannel    = channel as Serial;
                                        if (c.Connected == true)
                                        {
                                            c.AlreadyInitialized = true;
                                            if ((openedChannel.PortName == newChannel.PortName) &&
                                                ((openedChannel.BaudRate != newChannel.BaudRate) ||
                                                 (openedChannel.Retry != newChannel.Retry) ||
                                                 (openedChannel.TimeOut != newChannel.TimeOut) ||
                                                 (openedChannel.Parity != newChannel.Parity) ||
                                                 (openedChannel.DataBits != newChannel.DataBits) ||
                                                 (openedChannel.StopBits != newChannel.StopBits)))
                                            {
                                                throw new ComDriveExceptions(
                                                          "Opened Serial connection parameters cannot be modified",
                                                          ComDriveExceptions.ComDriveException.CommunicationParamsException);
                                            }
                                        }
                                        else
                                        {
                                            // return the c channel and change its properties
                                            c.AlreadyInitialized              = false;
                                            openedChannel.BaudRate            = newChannel.BaudRate;
                                            openedChannel.Parity              = newChannel.Parity;
                                            openedChannel.DataBits            = newChannel.DataBits;
                                            openedChannel.StopBits            = newChannel.StopBits;
                                            openedChannel.TimeOut             = newChannel.TimeOut;
                                            openedChannel.Retry               = newChannel.Retry;
                                            openedChannel.AutoDetectComParams = newChannel.AutoDetectComParams;
                                            openedChannel.Connect();
                                        }
                                    }
                                    else if (c.GetType() == typeof(Ethernet))
                                    {
                                        Ethernet newChannel    = channel as Ethernet;
                                        Ethernet openedChannel = c as Ethernet;
                                        if (c.Connected == true)
                                        {
                                            c.AlreadyInitialized = true;
                                            if ((openedChannel.Retry != newChannel.Retry) ||
                                                (openedChannel.TimeOut != newChannel.TimeOut) ||
                                                (openedChannel.Protocol != newChannel.Protocol))
                                            {
                                                throw new ComDriveExceptions(
                                                          "Opened Ethernet parameters cannot be modified",
                                                          ComDriveExceptions.ComDriveException.CommunicationParamsException);
                                            }
                                        }
                                        else
                                        {
                                            // return the c channel and change its properties
                                            c.AlreadyInitialized   = false;
                                            openedChannel.Protocol = newChannel.Protocol;
                                            openedChannel.TimeOut  = newChannel.TimeOut;
                                            openedChannel.Retry    = newChannel.Retry;
                                            openedChannel.Connect();
                                        }
                                    }
                                    else if (c.GetType() == typeof(EthernetListener))
                                    {
                                        EthernetListener newChannel    = channel as EthernetListener;
                                        EthernetListener openedChannel = c as EthernetListener;
                                        if (c.Connected == true)
                                        {
                                            c.AlreadyInitialized = true;
                                            if ((openedChannel.Retry != newChannel.Retry) ||
                                                (openedChannel.TimeOut != newChannel.TimeOut))
                                            {
                                                throw new ComDriveExceptions(
                                                          "Opened Ethernet parameters cannot be modified",
                                                          ComDriveExceptions.ComDriveException.CommunicationParamsException);
                                            }
                                        }
                                        else
                                        {
                                            // return the c channel and change its properties
                                            c.AlreadyInitialized  = false;
                                            openedChannel.TimeOut = newChannel.TimeOut;
                                            openedChannel.Retry   = newChannel.Retry;
                                            //openedChannel.Listen();
                                        }
                                    }

                                    return(c);
                                }
                            }
                        }

                        isConnected = channel.Connected;
                        if (!channel.Connected)
                        {
                            channel.Connect();
                            channel.AlreadyInitialized = false;
                            m_channels.Add(channel);
                            return(channel);
                        }

                        return(null);
                    }
                }
            }
        }