|
@@ -32,15 +32,16 @@ namespace xicheji
|
|
|
{
|
|
|
ServicePort = xdoc.Root!.Element("Service")?.Attribute("Port")?.Value ?? "9999",
|
|
|
|
|
|
- Server = xdoc.Root!.Element("Platform")?.Attribute("Server")?.Value ?? ""
|
|
|
+ Server = xdoc.Root!.Element("Platform")?.Attribute("Server")?.Value ?? "",
|
|
|
+ UploadInterval = int.Parse(xdoc.Root!.Element("Platform")?.Attribute("ReceiveInterval")?.Value ?? "2"),
|
|
|
};
|
|
|
|
|
|
var device = xdoc.Root!.Element("Device");
|
|
|
config.PLCIP = device?.Attribute("IP")?.Value ?? "";
|
|
|
config.PLCPort = device?.Attribute("Port")?.Value ?? "";
|
|
|
config.PLCType = Enum.Parse<CpuType>(device?.Attribute("Type")?.Value ?? "S7200");
|
|
|
- config.PLCMacAddress = device?.Attribute("MacAddress")?.Value ?? "";
|
|
|
config.PLCReceiveInterval = int.Parse(device?.Attribute("ReceiveInterval")?.Value ?? "2");
|
|
|
+ config.PLCMacAddress = device?.Attribute("MacAddress")?.Value ?? "";
|
|
|
|
|
|
var camera = xdoc.Root!.Element("Camera");
|
|
|
config.CameraIP = camera?.Attribute("IP")?.Value ?? "";
|
|
@@ -75,7 +76,28 @@ namespace xicheji
|
|
|
|
|
|
public static void SaveConfig(Config config)
|
|
|
{
|
|
|
- //TODO: 写入xml
|
|
|
+ var xdoc = XDocument.Load(configFileName);
|
|
|
+ var xService = xdoc.Root!.Element("Service");
|
|
|
+ xService?.SetAttributeValue("Port", config.ServicePort);
|
|
|
+
|
|
|
+ var xPlatform = xdoc.Root!.Element("Platform");
|
|
|
+ xPlatform?.SetAttributeValue("Server", config.Server);
|
|
|
+ xPlatform?.SetAttributeValue("UploadInterval", config.UploadInterval);
|
|
|
+
|
|
|
+ var xDevice = xdoc.Root!.Element("Device");
|
|
|
+ xDevice?.SetAttributeValue("IP", config.PLCIP);
|
|
|
+ xDevice?.SetAttributeValue("Port", config.PLCPort);
|
|
|
+ xDevice?.SetAttributeValue("Type", config.PLCType.ToString());
|
|
|
+ xDevice?.SetAttributeValue("ReceiveInterval", config.PLCReceiveInterval);
|
|
|
+ xDevice?.SetAttributeValue("MacAddress", config.PLCMacAddress);
|
|
|
+
|
|
|
+ var xCamera = xdoc.Root!.Element("Camera");
|
|
|
+ xCamera?.SetAttributeValue("IP", config.CameraIP);
|
|
|
+ xCamera?.SetAttributeValue("Port", config.CameraPort);
|
|
|
+ xCamera?.SetAttributeValue("UserName", config.CameraUserName);
|
|
|
+ xCamera?.SetAttributeValue("Password", config.CameraPassword);
|
|
|
+
|
|
|
+ xdoc.Save("config2.xml");
|
|
|
}
|
|
|
|
|
|
public static Variable? FindVariable(string variableName)
|
|
@@ -91,17 +113,22 @@ namespace xicheji
|
|
|
public class Config
|
|
|
{
|
|
|
public string ServicePort { get; set; } = string.Empty;
|
|
|
+
|
|
|
public string Server { get; set; } = string.Empty;
|
|
|
+ public int UploadInterval { get; internal set; }
|
|
|
+
|
|
|
public string PLCIP { get; set; } = string.Empty;
|
|
|
public string PLCPort { get; set; } = string.Empty;
|
|
|
public CpuType PLCType { get; set; } = CpuType.S7200;
|
|
|
public string PLCMacAddress { get; set; } = string.Empty;
|
|
|
public int PLCReceiveInterval { get; set; } = 2;
|
|
|
+
|
|
|
public string CameraIP { get; set; } = string.Empty;
|
|
|
public string CameraPort { get; set; } = string.Empty;
|
|
|
public string CameraUserName { get; set; } = string.Empty;
|
|
|
public string CameraPassword { get; set; } = string.Empty;
|
|
|
public string DBName { get; set; } = string.Empty;
|
|
|
+
|
|
|
public List<Variable> Variables { get; set; } = new();
|
|
|
}
|
|
|
|