|
@@ -1,6 +1,7 @@
|
|
|
using MessagePack.Formatters;
|
|
|
using Shaker.Models;
|
|
|
using ShakerService.Tools;
|
|
|
+using ShakerService.ViewModel;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
@@ -21,7 +22,6 @@ namespace ShakerService.OilSource
|
|
|
[AllowNull]
|
|
|
private IPLCConnect.IPLCConnect _PLCConnect;
|
|
|
private static string PluginPath = System.AppDomain.CurrentDomain.BaseDirectory + "PLCConnect";
|
|
|
- private OilSourceConfig oilSourceConfig = new OilSourceConfig();
|
|
|
public OilSourceStatusModel OilSourceStatus { get; } = new OilSourceStatusModel();
|
|
|
public static OilSource Default { get; } = new OilSource();
|
|
|
private object locker = new object();
|
|
@@ -31,8 +31,7 @@ namespace ShakerService.OilSource
|
|
|
private System.Timers.Timer _timer = new System.Timers.Timer(5000);
|
|
|
public void Init()
|
|
|
{
|
|
|
- oilSourceConfig = OilSourceConfig.ReadConfig();
|
|
|
- var analog = oilSourceConfig.AnalogAddress.Where(x => !string.IsNullOrEmpty(x.ValueAddress) && !string.IsNullOrEmpty(x.Name)).ToList();
|
|
|
+ var analog = ServiceOilSourceConfigViewModel.Instance.AnalogAddress.Where(x => !string.IsNullOrEmpty(x.ValueAddress) && !string.IsNullOrEmpty(x.Name)).ToList();
|
|
|
if (analog.Count > 0)
|
|
|
{
|
|
|
OilSourceStatus.OilSourceAnalogs.AddRange(analog.Select(x=>new OilSourceAnalogModel()
|
|
@@ -41,8 +40,7 @@ namespace ShakerService.OilSource
|
|
|
Unit = x.Unit,
|
|
|
}));
|
|
|
}
|
|
|
- oilSourceConfig.AnalogAddress = analog;
|
|
|
- var mainpump = oilSourceConfig.MainPumpAddress.Where(x => !string.IsNullOrEmpty(x.Address) && x.IsEnabled).ToList();
|
|
|
+ var mainpump = ServiceOilSourceConfigViewModel.Instance.MainPumpAddress.Where(x => !string.IsNullOrEmpty(x.Address) && x.IsEnabled).ToList();
|
|
|
if (mainpump.Count > 0)
|
|
|
{
|
|
|
OilSourceStatus.Circuit.AddRange(mainpump.Select(x=>new CircuitModel()
|
|
@@ -53,32 +51,30 @@ namespace ShakerService.OilSource
|
|
|
IsEnablePressure= x.IsPressureEnabled,
|
|
|
}));
|
|
|
}
|
|
|
- oilSourceConfig.MainPumpAddress = mainpump;
|
|
|
- OilSourceStatus.Circulate.Name = oilSourceConfig.CirculateAddress.Name;
|
|
|
- OilSourceStatus.Circulate.IsEnableLoad = oilSourceConfig.CirculateAddress.IsLoadEnabled;
|
|
|
- OilSourceStatus.Circulate.IsEnable= oilSourceConfig.CirculateAddress.IsEnabled;
|
|
|
- OilSourceStatus.Circulate.IsEnablePressure = oilSourceConfig.CirculateAddress.IsPressureEnabled;
|
|
|
+ OilSourceStatus.Circulate.Name = ServiceOilSourceConfigViewModel.Instance.CirculateAddress.Name;
|
|
|
+ OilSourceStatus.Circulate.IsEnableLoad = ServiceOilSourceConfigViewModel.Instance.CirculateAddress.IsLoadEnabled;
|
|
|
+ OilSourceStatus.Circulate.IsEnable= ServiceOilSourceConfigViewModel.Instance.CirculateAddress.IsEnabled;
|
|
|
+ OilSourceStatus.Circulate.IsEnablePressure = ServiceOilSourceConfigViewModel.Instance.CirculateAddress.IsPressureEnabled;
|
|
|
|
|
|
|
|
|
- OilSourceStatus.Forerunner.Name = oilSourceConfig.ForerunnerAddress.Name;
|
|
|
- OilSourceStatus.Forerunner.IsEnableLoad = oilSourceConfig.ForerunnerAddress.IsLoadEnabled;
|
|
|
- OilSourceStatus.Forerunner.IsEnable = oilSourceConfig.ForerunnerAddress.IsEnabled;
|
|
|
- OilSourceStatus.Forerunner.IsEnablePressure = oilSourceConfig.ForerunnerAddress.IsPressureEnabled;
|
|
|
+ OilSourceStatus.Forerunner.Name = ServiceOilSourceConfigViewModel.Instance.ForerunnerAddress.Name;
|
|
|
+ OilSourceStatus.Forerunner.IsEnableLoad = ServiceOilSourceConfigViewModel.Instance.ForerunnerAddress.IsLoadEnabled;
|
|
|
+ OilSourceStatus.Forerunner.IsEnable = ServiceOilSourceConfigViewModel.Instance.ForerunnerAddress.IsEnabled;
|
|
|
+ OilSourceStatus.Forerunner.IsEnablePressure = ServiceOilSourceConfigViewModel.Instance.ForerunnerAddress.IsPressureEnabled;
|
|
|
|
|
|
- OilSourceStatus.Assistant.Name = oilSourceConfig.AssistantAddress.Name;
|
|
|
- OilSourceStatus.Assistant.IsEnableLoad = oilSourceConfig.AssistantAddress.IsLoadEnabled;
|
|
|
- OilSourceStatus.Assistant.IsEnable = oilSourceConfig.AssistantAddress.IsEnabled;
|
|
|
- OilSourceStatus.Assistant.IsEnablePressure = oilSourceConfig.AssistantAddress.IsPressureEnabled;
|
|
|
+ OilSourceStatus.Assistant.Name = ServiceOilSourceConfigViewModel.Instance.AssistantAddress.Name;
|
|
|
+ OilSourceStatus.Assistant.IsEnableLoad = ServiceOilSourceConfigViewModel.Instance.AssistantAddress.IsLoadEnabled;
|
|
|
+ OilSourceStatus.Assistant.IsEnable = ServiceOilSourceConfigViewModel.Instance.AssistantAddress.IsEnabled;
|
|
|
+ OilSourceStatus.Assistant.IsEnablePressure = ServiceOilSourceConfigViewModel.Instance.AssistantAddress.IsPressureEnabled;
|
|
|
|
|
|
- oilSourceConfig.ErrorAddress = oilSourceConfig.ErrorAddress.Where(x => !string.IsNullOrEmpty(x.Address)).ToList();
|
|
|
- if (oilSourceConfig.ErrorAddress.Count > 0)
|
|
|
+ if (ServiceOilSourceConfigViewModel.Instance.ErrorAddress.Count > 0)
|
|
|
{
|
|
|
- OilSourceStatus.OilErrors.AddRange(Enumerable.Repeat(new ErrorInfoModel(), oilSourceConfig.ErrorAddress.Count));
|
|
|
+ OilSourceStatus.OilErrors.AddRange(Enumerable.Repeat(new ErrorInfoModel(), ServiceOilSourceConfigViewModel.Instance.ErrorAddress.Count));
|
|
|
}
|
|
|
- OilSourceStatus.IsEnabled = oilSourceConfig.IsEnabled;
|
|
|
+ OilSourceStatus.IsEnabled = ServiceOilSourceConfigViewModel.Instance.IsEnabled;
|
|
|
if (!IsEnabled) return;
|
|
|
var plcs = Tools.PluginsLoader.Defalut.Load<IPLCConnect.IPLCConnect>(PluginPath);
|
|
|
- _PLCConnect = plcs.FirstOrDefault(x => x.Protocol == oilSourceConfig.Protocol);
|
|
|
+ _PLCConnect = plcs.FirstOrDefault(x => x.Protocol == ServiceOilSourceConfigViewModel.Instance.Protocol);
|
|
|
if (_PLCConnect == null)
|
|
|
{
|
|
|
OilSourceStatus.IsEnabled = false;
|
|
@@ -86,7 +82,7 @@ namespace ShakerService.OilSource
|
|
|
}
|
|
|
try
|
|
|
{
|
|
|
- _PLCConnect.Init(oilSourceConfig.IP, oilSourceConfig.Port);
|
|
|
+ _PLCConnect.Init(ServiceOilSourceConfigViewModel.Instance.IP, ServiceOilSourceConfigViewModel.Instance.Port);
|
|
|
_PLCConnect.StatusChanged += PLCConnect_StatusChanged;
|
|
|
_PLCConnect.Connect();
|
|
|
}
|
|
@@ -100,6 +96,41 @@ namespace ShakerService.OilSource
|
|
|
RepeatConnectPLC();
|
|
|
}
|
|
|
}
|
|
|
+ public void ChangedPLCConfig()
|
|
|
+ {
|
|
|
+ if(_PLCConnect.Protocol == ServiceOilSourceConfigViewModel.Instance.Protocol)
|
|
|
+ {
|
|
|
+ Connect();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (_PLCConnect != null)
|
|
|
+ {
|
|
|
+ _PLCConnect.StatusChanged -= PLCConnect_StatusChanged;
|
|
|
+ _PLCConnect.Dispose();
|
|
|
+ }
|
|
|
+ var plcs = Tools.PluginsLoader.Defalut.Load<IPLCConnect.IPLCConnect>(PluginPath);
|
|
|
+ _PLCConnect = plcs.FirstOrDefault(x => x.Protocol == ServiceOilSourceConfigViewModel.Instance.Protocol);
|
|
|
+ if (_PLCConnect == null)
|
|
|
+ {
|
|
|
+ OilSourceStatus.IsEnabled = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ _PLCConnect.Init(ServiceOilSourceConfigViewModel.Instance.IP, ServiceOilSourceConfigViewModel.Instance.Port);
|
|
|
+ _PLCConnect.StatusChanged += PLCConnect_StatusChanged;
|
|
|
+ _PLCConnect.Connect();
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ OilSourceStatus.IsConnect = _PLCConnect.IsConnected;
|
|
|
+ if (!_PLCConnect.IsConnected)
|
|
|
+ {
|
|
|
+ RepeatConnectPLC();
|
|
|
+ }
|
|
|
+ }
|
|
|
private void RepeatConnectPLC()
|
|
|
{
|
|
|
_timer.Enabled = true;
|
|
@@ -116,22 +147,22 @@ namespace ShakerService.OilSource
|
|
|
{
|
|
|
if(args.Data.Length>=2 && args.Data[0] is int index && args.Data[1] is float pressure)
|
|
|
{
|
|
|
- if (!oilSourceConfig.MainPumpAddress[index].IsPressureEnabled) return;
|
|
|
- _PLCConnect?.Write(oilSourceConfig.MainPumpAddress[index].Address, pressure);
|
|
|
+ if (!ServiceOilSourceConfigViewModel.Instance.MainPumpAddress[index].IsPressureEnabled) return;
|
|
|
+ _PLCConnect?.Write(ServiceOilSourceConfigViewModel.Instance.MainPumpAddress[index].Address, pressure);
|
|
|
}
|
|
|
});
|
|
|
Communication.Instance.Context.GetEvent(Topic.CircuitStart)?.Subscrip((sender, args) =>
|
|
|
{
|
|
|
if (args.Data.Length >= 2 && args.Data[0] is int index && args.Data[1] is bool state)
|
|
|
{
|
|
|
- if (!oilSourceConfig.MainPumpAddress[index].IsEnabled) return;
|
|
|
+ if (!ServiceOilSourceConfigViewModel.Instance.MainPumpAddress[index].IsEnabled) return;
|
|
|
if (state)
|
|
|
{
|
|
|
- SetLevel(oilSourceConfig.MainPumpAddress[index].StartAddress, oilSourceConfig.MainPumpAddress[index].StartBitIndex, true);
|
|
|
+ SetLevel(ServiceOilSourceConfigViewModel.Instance.MainPumpAddress[index].StartAddress, ServiceOilSourceConfigViewModel.Instance.MainPumpAddress[index].StartBitIndex, true);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- SetLevel(oilSourceConfig.MainPumpAddress[index].StopAddress, oilSourceConfig.MainPumpAddress[index].StopBitIndex, true);
|
|
|
+ SetLevel(ServiceOilSourceConfigViewModel.Instance.MainPumpAddress[index].StopAddress, ServiceOilSourceConfigViewModel.Instance.MainPumpAddress[index].StopBitIndex, true);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -139,14 +170,14 @@ namespace ShakerService.OilSource
|
|
|
{
|
|
|
if (args.Data.Length >= 2 && args.Data[0] is int index && args.Data[1] is bool state)
|
|
|
{
|
|
|
- if (!oilSourceConfig.MainPumpAddress[index].IsLoadEnabled) return;
|
|
|
+ if (!ServiceOilSourceConfigViewModel.Instance.MainPumpAddress[index].IsLoadEnabled) return;
|
|
|
if (state)
|
|
|
{
|
|
|
- SetLevel(oilSourceConfig.MainPumpAddress[index].LoadAddress, oilSourceConfig.MainPumpAddress[index].LoadBitIndex, true);
|
|
|
+ SetLevel(ServiceOilSourceConfigViewModel.Instance.MainPumpAddress[index].LoadAddress, ServiceOilSourceConfigViewModel.Instance.MainPumpAddress[index].LoadBitIndex, true);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- SetLevel(oilSourceConfig.MainPumpAddress[index].UnLoadAddress, oilSourceConfig.MainPumpAddress[index].UnLoadBitIndex, true);
|
|
|
+ SetLevel(ServiceOilSourceConfigViewModel.Instance.MainPumpAddress[index].UnLoadAddress, ServiceOilSourceConfigViewModel.Instance.MainPumpAddress[index].UnLoadBitIndex, true);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -155,22 +186,22 @@ namespace ShakerService.OilSource
|
|
|
{
|
|
|
if (args.Data.Length >= 1 && args.Data[0] is float pressure)
|
|
|
{
|
|
|
- if (!oilSourceConfig.ForerunnerAddress.IsPressureEnabled) return;
|
|
|
- _PLCConnect?.Write(oilSourceConfig.ForerunnerAddress.Address, pressure);
|
|
|
+ if (!ServiceOilSourceConfigViewModel.Instance.ForerunnerAddress.IsPressureEnabled) return;
|
|
|
+ _PLCConnect?.Write(ServiceOilSourceConfigViewModel.Instance.ForerunnerAddress.Address, pressure);
|
|
|
}
|
|
|
});
|
|
|
Communication.Instance.Context.GetEvent(Topic.ForerunnerStart)?.Subscrip((sender, args) =>
|
|
|
{
|
|
|
if (args.Data.Length >= 1 && args.Data[0] is bool state)
|
|
|
{
|
|
|
- if (!oilSourceConfig.ForerunnerAddress.IsEnabled) return;
|
|
|
+ if (!ServiceOilSourceConfigViewModel.Instance.ForerunnerAddress.IsEnabled) return;
|
|
|
if (state)
|
|
|
{
|
|
|
- SetLevel(oilSourceConfig.ForerunnerAddress.StartAddress, oilSourceConfig.ForerunnerAddress.StartBitIndex, true);
|
|
|
+ SetLevel(ServiceOilSourceConfigViewModel.Instance.ForerunnerAddress.StartAddress, ServiceOilSourceConfigViewModel.Instance.ForerunnerAddress.StartBitIndex, true);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- SetLevel(oilSourceConfig.ForerunnerAddress.StopAddress, oilSourceConfig.ForerunnerAddress.StopBitIndex, true);
|
|
|
+ SetLevel(ServiceOilSourceConfigViewModel.Instance.ForerunnerAddress.StopAddress, ServiceOilSourceConfigViewModel.Instance.ForerunnerAddress.StopBitIndex, true);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -178,14 +209,14 @@ namespace ShakerService.OilSource
|
|
|
{
|
|
|
if (args.Data.Length >= 1 && args.Data[0] is bool state)
|
|
|
{
|
|
|
- if (!oilSourceConfig.ForerunnerAddress.IsLoadEnabled) return;
|
|
|
+ if (!ServiceOilSourceConfigViewModel.Instance.ForerunnerAddress.IsLoadEnabled) return;
|
|
|
if (state)
|
|
|
{
|
|
|
- SetLevel(oilSourceConfig.ForerunnerAddress.LoadAddress, oilSourceConfig.ForerunnerAddress.LoadBitIndex, true);
|
|
|
+ SetLevel(ServiceOilSourceConfigViewModel.Instance.ForerunnerAddress.LoadAddress, ServiceOilSourceConfigViewModel.Instance.ForerunnerAddress.LoadBitIndex, true);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- SetLevel(oilSourceConfig.ForerunnerAddress.UnLoadAddress, oilSourceConfig.ForerunnerAddress.UnLoadBitIndex, true);
|
|
|
+ SetLevel(ServiceOilSourceConfigViewModel.Instance.ForerunnerAddress.UnLoadAddress, ServiceOilSourceConfigViewModel.Instance.ForerunnerAddress.UnLoadBitIndex, true);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -194,22 +225,22 @@ namespace ShakerService.OilSource
|
|
|
{
|
|
|
if (args.Data.Length >= 1 && args.Data[0] is float pressure)
|
|
|
{
|
|
|
- if (!oilSourceConfig.AssistantAddress.IsPressureEnabled) return;
|
|
|
- _PLCConnect?.Write(oilSourceConfig.AssistantAddress.Address, pressure);
|
|
|
+ if (!ServiceOilSourceConfigViewModel.Instance.AssistantAddress.IsPressureEnabled) return;
|
|
|
+ _PLCConnect?.Write(ServiceOilSourceConfigViewModel.Instance.AssistantAddress.Address, pressure);
|
|
|
}
|
|
|
});
|
|
|
Communication.Instance.Context.GetEvent(Topic.AssistantStart)?.Subscrip((sender, args) =>
|
|
|
{
|
|
|
if (args.Data.Length >= 1 && args.Data[0] is bool state)
|
|
|
{
|
|
|
- if (!oilSourceConfig.AssistantAddress.IsEnabled) return;
|
|
|
+ if (!ServiceOilSourceConfigViewModel.Instance.AssistantAddress.IsEnabled) return;
|
|
|
if (state)
|
|
|
{
|
|
|
- SetLevel(oilSourceConfig.AssistantAddress.StartAddress, oilSourceConfig.AssistantAddress.StartBitIndex, true);
|
|
|
+ SetLevel(ServiceOilSourceConfigViewModel.Instance.AssistantAddress.StartAddress, ServiceOilSourceConfigViewModel.Instance.AssistantAddress.StartBitIndex, true);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- SetLevel(oilSourceConfig.AssistantAddress.StopAddress, oilSourceConfig.AssistantAddress.StopBitIndex, true);
|
|
|
+ SetLevel(ServiceOilSourceConfigViewModel.Instance.AssistantAddress.StopAddress, ServiceOilSourceConfigViewModel.Instance.AssistantAddress.StopBitIndex, true);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -217,14 +248,14 @@ namespace ShakerService.OilSource
|
|
|
{
|
|
|
if (args.Data.Length >= 1 && args.Data[0] is bool state)
|
|
|
{
|
|
|
- if (!oilSourceConfig.AssistantAddress.IsLoadEnabled) return;
|
|
|
+ if (!ServiceOilSourceConfigViewModel.Instance.AssistantAddress.IsLoadEnabled) return;
|
|
|
if (state)
|
|
|
{
|
|
|
- SetLevel(oilSourceConfig.AssistantAddress.LoadAddress, oilSourceConfig.AssistantAddress.LoadBitIndex, true);
|
|
|
+ SetLevel(ServiceOilSourceConfigViewModel.Instance.AssistantAddress.LoadAddress, ServiceOilSourceConfigViewModel.Instance.AssistantAddress.LoadBitIndex, true);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- SetLevel(oilSourceConfig.AssistantAddress.UnLoadAddress, oilSourceConfig.AssistantAddress.UnLoadBitIndex, true);
|
|
|
+ SetLevel(ServiceOilSourceConfigViewModel.Instance.AssistantAddress.UnLoadAddress, ServiceOilSourceConfigViewModel.Instance.AssistantAddress.UnLoadBitIndex, true);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -233,22 +264,22 @@ namespace ShakerService.OilSource
|
|
|
{
|
|
|
if (args.Data.Length >= 1 && args.Data[0] is float pressure)
|
|
|
{
|
|
|
- if (!oilSourceConfig.CirculateAddress.IsPressureEnabled) return;
|
|
|
- _PLCConnect?.Write(oilSourceConfig.CirculateAddress.Address, pressure);
|
|
|
+ if (!ServiceOilSourceConfigViewModel.Instance.CirculateAddress.IsPressureEnabled) return;
|
|
|
+ _PLCConnect?.Write(ServiceOilSourceConfigViewModel.Instance.CirculateAddress.Address, pressure);
|
|
|
}
|
|
|
});
|
|
|
Communication.Instance.Context.GetEvent(Topic.CirculateStart)?.Subscrip((sender, args) =>
|
|
|
{
|
|
|
if (args.Data.Length >= 1 && args.Data[0] is bool state)
|
|
|
{
|
|
|
- if (!oilSourceConfig.CirculateAddress.IsEnabled) return;
|
|
|
+ if (!ServiceOilSourceConfigViewModel.Instance.CirculateAddress.IsEnabled) return;
|
|
|
if (state)
|
|
|
{
|
|
|
- SetLevel(oilSourceConfig.CirculateAddress.StartAddress, oilSourceConfig.CirculateAddress.StartBitIndex, true);
|
|
|
+ SetLevel(ServiceOilSourceConfigViewModel.Instance.CirculateAddress.StartAddress, ServiceOilSourceConfigViewModel.Instance.CirculateAddress.StartBitIndex, true);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- SetLevel(oilSourceConfig.CirculateAddress.StopAddress, oilSourceConfig.CirculateAddress.StopBitIndex, true);
|
|
|
+ SetLevel(ServiceOilSourceConfigViewModel.Instance.CirculateAddress.StopAddress, ServiceOilSourceConfigViewModel.Instance.CirculateAddress.StopBitIndex, true);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -256,14 +287,14 @@ namespace ShakerService.OilSource
|
|
|
{
|
|
|
if (args.Data.Length >= 1 && args.Data[0] is bool state)
|
|
|
{
|
|
|
- if (!oilSourceConfig.CirculateAddress.IsLoadEnabled) return;
|
|
|
+ if (!ServiceOilSourceConfigViewModel.Instance.CirculateAddress.IsLoadEnabled) return;
|
|
|
if (state)
|
|
|
{
|
|
|
- SetLevel(oilSourceConfig.CirculateAddress.LoadAddress, oilSourceConfig.CirculateAddress.LoadBitIndex, true);
|
|
|
+ SetLevel(ServiceOilSourceConfigViewModel.Instance.CirculateAddress.LoadAddress, ServiceOilSourceConfigViewModel.Instance.CirculateAddress.LoadBitIndex, true);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- SetLevel(oilSourceConfig.CirculateAddress.UnLoadAddress, oilSourceConfig.CirculateAddress.UnLoadBitIndex, true);
|
|
|
+ SetLevel(ServiceOilSourceConfigViewModel.Instance.CirculateAddress.UnLoadAddress, ServiceOilSourceConfigViewModel.Instance.CirculateAddress.UnLoadBitIndex, true);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -274,11 +305,11 @@ namespace ShakerService.OilSource
|
|
|
{
|
|
|
if (state)
|
|
|
{
|
|
|
- SetLevel(oilSourceConfig.EmergencyStopAddress.Address, oilSourceConfig.EmergencyStopAddress.BitIndex, true);
|
|
|
+ SetLevel(ServiceOilSourceConfigViewModel.Instance.EmergencyStopAddress.Address, ServiceOilSourceConfigViewModel.Instance.EmergencyStopAddress.BitIndex, true);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- SetLevel(oilSourceConfig.EmergencyStopAddress.Address, oilSourceConfig.EmergencyStopAddress.BitIndex, true);
|
|
|
+ SetLevel(ServiceOilSourceConfigViewModel.Instance.EmergencyStopAddress.Address, ServiceOilSourceConfigViewModel.Instance.EmergencyStopAddress.BitIndex, true);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -290,7 +321,7 @@ namespace ShakerService.OilSource
|
|
|
try
|
|
|
{
|
|
|
Ping ping = new Ping();
|
|
|
- if(ping.Send(oilSourceConfig.IP).Status == IPStatus.Success)
|
|
|
+ if(ping.Send(ServiceOilSourceConfigViewModel.Instance.IP).Status == IPStatus.Success)
|
|
|
{
|
|
|
//_PLCConnect.Init(oilSourceConfig.IP, oilSourceConfig.Port);
|
|
|
lock (locker)
|
|
@@ -307,14 +338,14 @@ namespace ShakerService.OilSource
|
|
|
|
|
|
private async void SetLevel(string address ,byte bitindex,bool value)
|
|
|
{
|
|
|
- if(oilSourceConfig.LevelLogic == LevelLogic.Level)
|
|
|
+ if(ServiceOilSourceConfigViewModel.Instance.LevelLogic == LevelLogic.Level)
|
|
|
{
|
|
|
_PLCConnect?.Writebit(address, bitindex, value);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_PLCConnect?.Writebit(address, bitindex, !value);
|
|
|
- await Task.Delay(oilSourceConfig.LevelTime);
|
|
|
+ await Task.Delay(ServiceOilSourceConfigViewModel.Instance.LevelTime);
|
|
|
_PLCConnect?.Writebit(address, bitindex, value);
|
|
|
}
|
|
|
}
|
|
@@ -358,30 +389,30 @@ namespace ShakerService.OilSource
|
|
|
}
|
|
|
for (int i = 0; i < OilSourceStatus.Circuit.Count; i++)
|
|
|
{
|
|
|
- OilSourceStatus.Circuit[i].IsStart = _PLCConnect.ReadBit(oilSourceConfig.MainPumpAddress[i].IsStartAddress, oilSourceConfig.MainPumpAddress[i].IsStartBitIndex);
|
|
|
+ OilSourceStatus.Circuit[i].IsStart = _PLCConnect.ReadBit(ServiceOilSourceConfigViewModel.Instance.MainPumpAddress[i].IsStartAddress, ServiceOilSourceConfigViewModel.Instance.MainPumpAddress[i].IsStartBitIndex);
|
|
|
//OilSourceStatus.Circuit[i].Pressure = _PLCConnect.Read<float>(oilSourceConfig.MainPumpAddress[i].Address);
|
|
|
- OilSourceStatus.Circuit[i].IsLoadPressure = _PLCConnect.ReadBit(oilSourceConfig.MainPumpAddress[i].IsLoadAddress, oilSourceConfig.MainPumpAddress[i].IsLoadBitIndex);
|
|
|
+ OilSourceStatus.Circuit[i].IsLoadPressure = _PLCConnect.ReadBit(ServiceOilSourceConfigViewModel.Instance.MainPumpAddress[i].IsLoadAddress, ServiceOilSourceConfigViewModel.Instance.MainPumpAddress[i].IsLoadBitIndex);
|
|
|
}
|
|
|
|
|
|
- OilSourceStatus.Circulate.IsLoadPressure = _PLCConnect.ReadBit(oilSourceConfig.CirculateAddress.IsLoadAddress, oilSourceConfig.CirculateAddress.IsLoadBitIndex);
|
|
|
+ OilSourceStatus.Circulate.IsLoadPressure = _PLCConnect.ReadBit(ServiceOilSourceConfigViewModel.Instance.CirculateAddress.IsLoadAddress, ServiceOilSourceConfigViewModel.Instance.CirculateAddress.IsLoadBitIndex);
|
|
|
|
|
|
- OilSourceStatus.Circulate.IsStart = _PLCConnect.ReadBit(oilSourceConfig.CirculateAddress.IsStartAddress, oilSourceConfig.CirculateAddress.IsStartBitIndex);
|
|
|
+ OilSourceStatus.Circulate.IsStart = _PLCConnect.ReadBit(ServiceOilSourceConfigViewModel.Instance.CirculateAddress.IsStartAddress, ServiceOilSourceConfigViewModel.Instance.CirculateAddress.IsStartBitIndex);
|
|
|
|
|
|
|
|
|
- OilSourceStatus.Forerunner.IsStart = _PLCConnect.ReadBit(oilSourceConfig.ForerunnerAddress.IsStartAddress, oilSourceConfig.ForerunnerAddress.IsStartBitIndex);
|
|
|
- OilSourceStatus.Forerunner.IsLoadPressure = _PLCConnect.ReadBit(oilSourceConfig.ForerunnerAddress.IsLoadAddress, oilSourceConfig.ForerunnerAddress.IsLoadBitIndex);
|
|
|
+ OilSourceStatus.Forerunner.IsStart = _PLCConnect.ReadBit(ServiceOilSourceConfigViewModel.Instance.ForerunnerAddress.IsStartAddress, ServiceOilSourceConfigViewModel.Instance.ForerunnerAddress.IsStartBitIndex);
|
|
|
+ OilSourceStatus.Forerunner.IsLoadPressure = _PLCConnect.ReadBit(ServiceOilSourceConfigViewModel.Instance.ForerunnerAddress.IsLoadAddress, ServiceOilSourceConfigViewModel.Instance.ForerunnerAddress.IsLoadBitIndex);
|
|
|
for (int i = 0; i < OilSourceStatus.OilErrors.Count; i++)
|
|
|
{
|
|
|
- OilSourceStatus.OilErrors[i].Status = _PLCConnect.ReadBit(oilSourceConfig.ErrorAddress[i].Address, oilSourceConfig.ErrorAddress[i].BitIndex);
|
|
|
+ OilSourceStatus.OilErrors[i].Status = _PLCConnect.ReadBit(ServiceOilSourceConfigViewModel.Instance.ErrorAddress[i].Address, ServiceOilSourceConfigViewModel.Instance.ErrorAddress[i].BitIndex);
|
|
|
}
|
|
|
- OilSourceStatus.IsRemote = _PLCConnect.ReadBit(oilSourceConfig.IsRemoteAddress.Address, oilSourceConfig.IsRemoteAddress.BitIndex);
|
|
|
+ OilSourceStatus.IsRemote = _PLCConnect.ReadBit(ServiceOilSourceConfigViewModel.Instance.IsRemoteAddress.Address, ServiceOilSourceConfigViewModel.Instance.IsRemoteAddress.BitIndex);
|
|
|
for (int i = 0; i < OilSourceStatus.OilSourceAnalogs.Count; i++)
|
|
|
{
|
|
|
- OilSourceStatus.OilSourceAnalogs[i].Value = _PLCConnect.Read<float>(oilSourceConfig.AnalogAddress[i].ValueAddress);
|
|
|
- OilSourceStatus.OilSourceAnalogs[i].IsLowerError = _PLCConnect.ReadBit(oilSourceConfig.AnalogAddress[i].LowerErrorAddress, oilSourceConfig.AnalogAddress[i].LowerErrorBitIndex);
|
|
|
- OilSourceStatus.OilSourceAnalogs[i].IsLowerWarn = _PLCConnect.ReadBit(oilSourceConfig.AnalogAddress[i].LowerWarnAddress, oilSourceConfig.AnalogAddress[i].LowerWarnBitIndex);
|
|
|
- OilSourceStatus.OilSourceAnalogs[i].IsUpperError = _PLCConnect.ReadBit(oilSourceConfig.AnalogAddress[i].UpperErrorAddress, oilSourceConfig.AnalogAddress[i].UpperErrorBitIndex);
|
|
|
- OilSourceStatus.OilSourceAnalogs[i].IsUpperWarn = _PLCConnect.ReadBit(oilSourceConfig.AnalogAddress[i].UpperWarnAddress, oilSourceConfig.AnalogAddress[i].UpperWarnBitIndex);
|
|
|
+ OilSourceStatus.OilSourceAnalogs[i].Value = _PLCConnect.Read<float>(ServiceOilSourceConfigViewModel.Instance.AnalogAddress[i].ValueAddress);
|
|
|
+ OilSourceStatus.OilSourceAnalogs[i].IsLowerError = _PLCConnect.ReadBit(ServiceOilSourceConfigViewModel.Instance.AnalogAddress[i].LowerErrorAddress, ServiceOilSourceConfigViewModel.Instance.AnalogAddress[i].LowerErrorBitIndex);
|
|
|
+ OilSourceStatus.OilSourceAnalogs[i].IsLowerWarn = _PLCConnect.ReadBit(ServiceOilSourceConfigViewModel.Instance.AnalogAddress[i].LowerWarnAddress, ServiceOilSourceConfigViewModel.Instance.AnalogAddress[i].LowerWarnBitIndex);
|
|
|
+ OilSourceStatus.OilSourceAnalogs[i].IsUpperError = _PLCConnect.ReadBit(ServiceOilSourceConfigViewModel.Instance.AnalogAddress[i].UpperErrorAddress, ServiceOilSourceConfigViewModel.Instance.AnalogAddress[i].UpperErrorBitIndex);
|
|
|
+ OilSourceStatus.OilSourceAnalogs[i].IsUpperWarn = _PLCConnect.ReadBit(ServiceOilSourceConfigViewModel.Instance.AnalogAddress[i].UpperWarnAddress, ServiceOilSourceConfigViewModel.Instance.AnalogAddress[i].UpperWarnBitIndex);
|
|
|
}
|
|
|
Communication.Instance.Context.GetEvent<OilSourceStatusModel>()?.Publish(this, OilSourceStatus);
|
|
|
}
|