Пример #1
0
        public void InitConfig(string type)
        {
            // 初始化配置文件信息
            foreach (string workType in InitConfigInfo.WorkGroups.Keys)
            {
                if (workType == type)
                {
                    WorkGroupElement workGroup = InitConfigInfo.WorkGroups[workType];
                    for (int i = 0; i < workGroup.Devices.Count; i++)
                    {
                        DeviceElement deviceElement = workGroup.Devices[i];
                        dictionaryDevices.Add(deviceElement.DeviceNumber, deviceElement);
                    }
                }
            }

            this.OPCServerIP   = ConfigurationManager.AppSettings["OPCServerIP"];
            this.OPCServerPort = ConfigurationManager.AppSettings["OPCServerPort"];
            this.localHostIP   = ConfigurationManager.AppSettings["LocalHostIP"];
            this.localHostPort = ConfigurationManager.AppSettings["LocalHostPort"];
            if (InitConfigInfo.PingIpOrDomainName(OPCServerIP, localHostIP, dictionaryDevices["1"].PLCip))
            {
                this.service = DeviceService.Register(1, localHostIP, int.Parse(localHostPort), OPCServerIP, int.Parse(OPCServerPort));
                this.device  = new PLCDevice(dictionaryDevices["1"].PLCip, DeviceType.Siemens_S7_1200);

                this.Title = string.Format("{0}             本机IP:{1}  本机端口:{2}             远程IP:{3}  远程端口:{4}          PLCIP地址:{5}", "PLC监听", localHostIP, localHostPort, OPCServerIP, OPCServerPort, dictionaryDevices["1"].PLCip);



                address = new PLCAddress[dictionaryDevices.Count];
                for (int i = 0; i < dictionaryDevices.Count; i++)
                {
                    address[i] = device.Add(dictionaryDevices[(i + 1).ToString()].PLCAddress);
                }
                CommandResult res = service.ListenDevice(device);
                ReadPLCValue();
            }
            else
            {
                MessageBox.Show("网络错误,请检查网络", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                this.Close();
            }
        }
Пример #2
0
        public static void Init(string sectionType)
        {
            if (sectionType == "groupSection")
            {
                WorkSection groupSection = (WorkSection)ConfigurationManager.GetSection("sntConfig/workGroups");

                workGroups = new Dictionary <string, WorkGroupElement>();
                for (int i = 0; i < groupSection.WorkGroups.Count; i++)
                {
                    WorkGroupElement element = groupSection.WorkGroups[i];
                    workGroups.Add(element.Type, element);
                }
            }
            if (sectionType == "taskSection")
            {
                TaskSection taskSection = (TaskSection)ConfigurationManager.GetSection("sntConfig/taskParameters");
                taskParameters = new Dictionary <string, TaskParameterElement>();
                for (int i = 0; i < taskSection.TaskParameters.Count; i++)
                {
                    TaskParameterElement element = taskSection.TaskParameters[i];
                    taskParameters.Add(element.Type, element);
                }
            }
        }