Browse Source

增加设备级参数

样式分支
applelon 2 years ago
parent
commit
c65bf2f2f7
4 changed files with 25 additions and 5 deletions
  1. +15
    -5
      BPASmartClient.Business/Plugin/ConfigMgr.cs
  2. +4
    -0
      BPASmartClient.Business/Plugin/DeviceMgr.cs
  3. +2
    -0
      BPASmartClient.Model/DeviceConfigModel.cs
  4. +4
    -0
      BPASmartClient/DeviceInfo.xml

+ 15
- 5
BPASmartClient.Business/Plugin/ConfigMgr.cs View File

@@ -33,8 +33,8 @@ namespace BPASmartClient.Business
{ {
ClientId = int.Parse(System.Configuration.ConfigurationManager.AppSettings["ClientId"]); ClientId = int.Parse(System.Configuration.ConfigurationManager.AppSettings["ClientId"]);
apolloUri = System.Configuration.ConfigurationManager.AppSettings["ApolloUri"].ToString(); apolloUri = System.Configuration.ConfigurationManager.AppSettings["ApolloUri"].ToString();
InternetInfo.OrderServer= System.Configuration.ConfigurationManager.AppSettings["OrderServiceUri"].ToString();
InternetInfo.StockServer= System.Configuration.ConfigurationManager.AppSettings["StockServiceUri"].ToString();
InternetInfo.OrderServer = System.Configuration.ConfigurationManager.AppSettings["OrderServiceUri"].ToString();
InternetInfo.StockServer = System.Configuration.ConfigurationManager.AppSettings["StockServiceUri"].ToString();


InitDeviceModel(); InitDeviceModel();
InitMQTT(); InitMQTT();
@@ -61,15 +61,25 @@ namespace BPASmartClient.Business
DeviceConfig deviceConfig = new DeviceConfig(); DeviceConfig deviceConfig = new DeviceConfig();
deviceConfig.Name = device.Attribute("Name").Value; deviceConfig.Name = device.Attribute("Name").Value;
deviceConfig.Module = device.Attribute("Module").Value; deviceConfig.Module = device.Attribute("Module").Value;
deviceConfig.DeviceId =int.Parse(device.Attribute("DeviceId").Value);
deviceConfig.DeviceId = int.Parse(device.Attribute("DeviceId").Value);
if (null != device.Element("Parameters"))
{
foreach (var deviceParameter in device.Element("Parameters").Elements())
{
deviceConfig.Parameters.Add(deviceParameter.Name.LocalName, deviceParameter.Value);
}
}


foreach (var peripheralEl in device.XPathSelectElements("//Peripheral")) foreach (var peripheralEl in device.XPathSelectElements("//Peripheral"))
{ {
BPASmartClient.Model.Peripheral peripheral = new BPASmartClient.Model.Peripheral(); BPASmartClient.Model.Peripheral peripheral = new BPASmartClient.Model.Peripheral();
peripheral.Module = peripheralEl.Attribute("Module").Value; peripheral.Module = peripheralEl.Attribute("Module").Value;
foreach (XElement parameter in peripheralEl.Element("Parameters").Elements())
if (null != peripheralEl.Element("Parameters"))
{ {
peripheral.Parameters.Add(parameter.Name.LocalName, parameter.Value);
foreach (XElement parameter in peripheralEl.Element("Parameters").Elements())
{
peripheral.Parameters.Add(parameter.Name.LocalName, parameter.Value);
}
} }
deviceConfig.Peripherals.Add(peripheral); deviceConfig.Peripherals.Add(peripheral);
} }


+ 4
- 0
BPASmartClient.Business/Plugin/DeviceMgr.cs View File

@@ -53,6 +53,10 @@ namespace BPASmartClient.Business
var deviceTemp = Assembly.Load(device.Module.Substring(0, device.Module.LastIndexOf('.'))).CreateInstance(device.Module) as IDevice; var deviceTemp = Assembly.Load(device.Module.Substring(0, device.Module.LastIndexOf('.'))).CreateInstance(device.Module) as IDevice;
deviceTemp.Name = device.Name; deviceTemp.Name = device.Name;
deviceTemp.DeviceId = device.DeviceId; deviceTemp.DeviceId = device.DeviceId;
foreach (var pars in device.Parameters)
{
deviceTemp.GetType().GetProperty(pars.Key).SetValue(deviceTemp, Convert.ChangeType(pars.Value, deviceTemp.GetType().GetProperty(pars.Key).PropertyType));
}


List<IPeripheral> peripherals = new List<IPeripheral>(); List<IPeripheral> peripherals = new List<IPeripheral>();
foreach (var peripheral in device.Peripherals) foreach (var peripheral in device.Peripherals)


+ 2
- 0
BPASmartClient.Model/DeviceConfigModel.cs View File

@@ -16,6 +16,8 @@ namespace BPASmartClient.Model
public string Name { get; set; } public string Name { get; set; }
public string Module { get; set; } public string Module { get; set; }
public int DeviceId { get; set; } public int DeviceId { get; set; }
public Dictionary<string, string> Parameters { get; set; } = new Dictionary<string, string>();

public List<Peripheral> Peripherals { get; set; } = new List<Peripheral>(); public List<Peripheral> Peripherals { get; set; } = new List<Peripheral>();
} }




+ 4
- 0
BPASmartClient/DeviceInfo.xml View File

@@ -20,6 +20,10 @@
</Device>--> </Device>-->


<Device Name="MorkS" Module="BPASmartClient.MorkS.Control" DeviceId="2"> <Device Name="MorkS" Module="BPASmartClient.MorkS.Control" DeviceId="2">
<Parameters>
<IpAddress>127.0.10.1</IpAddress>
<Port>11</Port>
</Parameters>
<Peripherals> <Peripherals>
<Peripheral Module="BPASmartClient.PLC.MorksMachine"> <Peripheral Module="BPASmartClient.PLC.MorksMachine">
<Parameters> <Parameters>


Loading…
Cancel
Save