1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| using System;
| using System.IO;
|
| namespace DIOController
| {
| public class DIOControllerCreator
| {
| public static IDIOController CreateController(string iniFile)
| {
| if (!File.Exists(iniFile)) throw new Exception("未找到配置文件");
| string type = IniFileHelper.ReadIniData("Config", "Type", "", iniFile);
| switch (type)
| {
| case "ModbusTcp":
| string ip = IniFileHelper.ReadIniData("Config", "Ip", "127.0.0.1", iniFile);
| string portStr = IniFileHelper.ReadIniData("Config", "Port", "502", iniFile);
| int port = int.Parse(portStr);
| return new ModBusTcpController
| {
| Ip = ip,
| Port = port
| };
| case "PCI_7432":
| string name = IniFileHelper.ReadIniData("Config", "Name", "PCI_7432", iniFile);
| return new PCIController { Name = name };
| default:
| throw new Exception("无效的控制器类型");
| }
| }
| }
| }
|
|