示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            device = new List <Plc>();

            using (DataProvider db = new DataProvider(true))
            {
                db.SqlString = "SELECT [IP] FROM [ors_2016].[dbo].[PLC] WITH (NOLOCK) WHERE ADRES IS NOT NULL GROUP BY [IP]";
                using (DataTable dtip = db.GetTable())
                {
                    if (dtip != null && dtip.Rows.Count > 0)
                    {
                        foreach (DataRow row in dtip.Rows)
                        {
                            Plc plc = new Plc(CpuType.S71200, row["IP"].ToString(), 0, 0, "");
                            db.SqlString = "SELECT [IP], [ISTASYON], [ADRES], [ACIKLAMA] FROM [ors_2016].[dbo].[PLC] WITH (NOLOCK) WHERE [IP] = N'" + row["IP"].ToString() + "'";
                            using (IDataReader dr = db.Select())
                            {
                                if (dr != null)
                                {
                                    while (dr.Read())
                                    {
                                        string adres    = "";
                                        string istasyon = "";
                                        if (!dr.IsDBNull(dr.GetOrdinal("ADRES")))
                                        {
                                            adres = dr.GetValue(dr.GetOrdinal("ADRES")).ToString();
                                        }
                                        if (!dr.IsDBNull(dr.GetOrdinal("ISTASYON")))
                                        {
                                            istasyon = dr.GetValue(dr.GetOrdinal("ISTASYON")).ToString();
                                        }
                                        plc.Add(new PLCPin(adres, 0, istasyon));
                                    }
                                    dr.Close();
                                }
                            }
                            plc.Open();
                            device.Add(plc);
                        }
                    }
                }
            }

            device.TrimExcess();
            Console.WriteLine(device.Count);

            //timer1.Enabled = true;

            /*
             *
             */

            //device = new Plc(CpuType.S71200, "192.168.145.2", 0, 0);
            //device = new Plc(CpuType.S71200, "192.168.144.1", 0, 0);
            //device.Open();
            //timer1.Enabled = true;
        }
示例#2
0
        private void Initialize()
        {
            int              port, scan, count;
            string           name, logPath, logName;
            EEthernetMode    mode;
            EEthernetLogging logging;

            int    i       = 1;
            int    length  = 0;
            string section = $"PowerMeter.{i:d2}";
            string ip      = server.Ini.GetString(section, "ip");

            PowerMeter.Clear();
            PowerMeterValues.Clear();

            while (ip != "")
            {
                name    = server.Ini.GetString(section, "name");
                port    = server.Ini.GetInteger(section, "port");
                scan    = server.Ini.GetInteger(section, "scantime");
                logPath = server.Ini.GetString(section, "logpath");
                logName = server.Ini.GetString(section, "logfilename");
                logging = GetEthernetLogging(section);
                mode    = (server.Ini.GetString(section, "mode") == "Real") ? EEthernetMode.Real : EEthernetMode.Virtual;

                EWT330Phase phase = (server.Ini.GetString(section, "phase") == "P1") ? EWT330Phase.P1 : EWT330Phase.P3;
                length += 25;

                //if (phase == EWT330Phase.P1) length += 7;
                //else length += 25;

                UlWT330EthernetClient client = new UlWT330EthernetClient(name, phase, ip, port, scan);
                client.Mode     = mode;
                client.Logging  = logging;
                client.LogPath  = logPath;
                client.LogFName = $"{logName}.{i:d2}";
                PowerMeter.Add(client);

                CreatePowerMeterValues(i, phase);

                i++;
                section = $"PowerMeter.{i:d2}";
                ip      = server.Ini.GetString(section, "ip");
            }

            i       = 1;
            section = $"Recorder.{i:d2}";
            ip      = server.Ini.GetString(section, "ip");
            Recorder.Clear();

            while (ip != "")
            {
                name    = server.Ini.GetString(section, "name");
                port    = server.Ini.GetInteger(section, "port");
                count   = server.Ini.GetInteger(section, "length");
                scan    = server.Ini.GetInteger(section, "scantime");
                logPath = server.Ini.GetString(section, "logpath");
                logName = server.Ini.GetString(section, "logfilename");
                logging = GetEthernetLogging(section);
                mode    = (server.Ini.GetString(section, "mode") == "Real") ? EEthernetMode.Real : EEthernetMode.Virtual;

                length += count;

                UlGM10EthernetClient client = new UlGM10EthernetClient(name, ip, port, count, scan);
                client.Mode     = mode;
                client.Logging  = logging;
                client.LogPath  = logPath;
                client.LogFName = $"{logName}.{i:d2}";
                Recorder.Add(client);

                CreateRecorderValues(i, count);

                i++;
                section = $"Recorder.{i:d2}";
                ip      = server.Ini.GetString(section, "ip");
            }

            i       = 1;
            section = $"Controller.{i:d2}";
            ip      = server.Ini.GetString(section, "ip");
            Controller.Clear();

            while (ip != "")
            {
                name    = server.Ini.GetString(section, "name");
                port    = server.Ini.GetInteger(section, "port");
                scan    = server.Ini.GetInteger(section, "scantime");
                logPath = server.Ini.GetString(section, "logpath");
                logName = server.Ini.GetString(section, "logfilename");
                logging = GetEthernetLogging(section);
                mode    = (server.Ini.GetString(section, "mode") == "Real") ? EEthernetMode.Real : EEthernetMode.Virtual;

                int slaveAddr  = server.Ini.GetInteger(section, "slaveaddress");
                int slaveCount = server.Ini.GetInteger(section, "slavecount");

                float defDecial = (float)server.Ini.GetDouble(section, "DefaultFixedDecimal");

                length += (slaveCount * 12);

                UlUT55AEthernetClient client = new UlUT55AEthernetClient(name, ip, port, slaveAddr, slaveCount, scan);
                client.Mode     = mode;
                client.Logging  = logging;
                client.LogPath  = logPath;
                client.LogFName = $"{logName}.{i:d2}";

                int   addr;
                float fixedDec;

                for (int j = 0; j < slaveCount; j++)
                {
                    addr     = slaveAddr + j;
                    fixedDec = (float)server.Ini.GetDouble(section, $"FixedDecimal{addr}");

                    if (fixedDec < 0.1)
                    {
                        client.SetFixedDecimal(addr, defDecial);
                    }
                    else
                    {
                        client.SetFixedDecimal(addr, fixedDec);
                    }
                }

                Controller.Add(client);
                CreateControllerValues(slaveAddr, slaveCount);

                i++;
                section = $"Controller.{i:d2}";
                ip      = server.Ini.GetString(section, "ip");
            }

            Values = new float[length];

            i       = 1;
            section = $"Plc.{i:d2}";
            ip      = server.Ini.GetString(section, "ip");
            Plc.Clear();

            while (ip != "")
            {
                name    = server.Ini.GetString(section, "name");
                port    = server.Ini.GetInteger(section, "port");
                scan    = server.Ini.GetInteger(section, "scantime");
                logPath = server.Ini.GetString(section, "logpath");
                logName = server.Ini.GetString(section, "logfilename");
                logging = GetEthernetLogging(section);
                mode    = (server.Ini.GetString(section, "mode") == "Real") ? EEthernetMode.Real : EEthernetMode.Virtual;

                string block       = server.Ini.GetString(section, "block");
                int    blockLength = server.Ini.GetInteger(section, "blocklength");

                UlMasterKEthernetClient client = new UlMasterKEthernetClient(name, ip, port, block, blockLength, scan);
                client.Mode     = mode;
                client.Logging  = logging;
                client.LogPath  = logPath;
                client.LogFName = $"{logName}.{i:d2}";
                Plc.Add(client);

                CreatePlcValues(i, blockLength);

                i++;
                section = $"Plc.{i:d2}";
                ip      = server.Ini.GetString(section, "ip");
            }

            Bytes = new byte[length * 4 + PlcLength * 2];
        }