コード例 #1
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];
        }