|
|
|
@ -1,9 +1,15 @@
|
|
|
|
|
using Masuit.Tools;
|
|
|
|
|
using PVDEMCS.Common;
|
|
|
|
|
using PVDEMCS.Common.Devices.Impl;
|
|
|
|
|
using PVDEMCS.Devices;
|
|
|
|
|
using PVDEMCS.Services.Models;
|
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
|
|
|
|
|
namespace PVDEMCS.Common.Devices.Impl
|
|
|
|
|
namespace PVDEMCS.Devices.Impl
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 控制器点位监控
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class DeviceMonitor
|
|
|
|
|
{
|
|
|
|
|
private DeviceInfo deviceInfo;
|
|
|
|
@ -14,7 +20,7 @@ namespace PVDEMCS.Common.Devices.Impl
|
|
|
|
|
public DeviceMonitor(DeviceInfo deviceInfo)
|
|
|
|
|
{
|
|
|
|
|
this.deviceInfo = deviceInfo;
|
|
|
|
|
this.devicePoints = new List<DevicePoint>();
|
|
|
|
|
devicePoints = new List<DevicePoint>();
|
|
|
|
|
PointMonitor();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
@ -30,10 +36,10 @@ namespace PVDEMCS.Common.Devices.Impl
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 控制器编号
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string DeviceCode
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
public string DeviceCode
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return deviceInfo.DeviceCode;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -53,7 +59,7 @@ namespace PVDEMCS.Common.Devices.Impl
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 连接状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Boolean isConnected
|
|
|
|
|
public bool isConnected
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
@ -64,7 +70,7 @@ namespace PVDEMCS.Common.Devices.Impl
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 监控是否运行
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Boolean IsRun
|
|
|
|
|
public bool IsRun
|
|
|
|
|
{
|
|
|
|
|
get { return IsRun; }
|
|
|
|
|
}
|
|
|
|
@ -85,8 +91,8 @@ namespace PVDEMCS.Common.Devices.Impl
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Init(string address, int port = 0)
|
|
|
|
|
{
|
|
|
|
|
this.deviceInfo.Host = address;
|
|
|
|
|
this.deviceInfo.Port = port;
|
|
|
|
|
deviceInfo.Host = address;
|
|
|
|
|
deviceInfo.Port = port;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -131,11 +137,11 @@ namespace PVDEMCS.Common.Devices.Impl
|
|
|
|
|
{
|
|
|
|
|
if (plcCommunicationService == null)
|
|
|
|
|
{
|
|
|
|
|
plcCommunicationService = new S7CommunicationService(this.deviceInfo.Protocol);
|
|
|
|
|
plcCommunicationService = new S7CommunicationService(deviceInfo.Protocol);
|
|
|
|
|
}
|
|
|
|
|
if (!plcCommunicationService.isConnected)
|
|
|
|
|
{
|
|
|
|
|
var result = await plcCommunicationService.ConnectionAsync(this.deviceInfo.Host, this.deviceInfo.Port);
|
|
|
|
|
var result = await plcCommunicationService.ConnectionAsync(deviceInfo.Host, deviceInfo.Port);
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
ErrorMessage?.Invoke(this, "开始PLC连接失败:" + result.Message);
|
|
|
|
@ -197,42 +203,42 @@ namespace PVDEMCS.Common.Devices.Impl
|
|
|
|
|
var type = point.DataType;
|
|
|
|
|
var plcService = plcCommunicationService;
|
|
|
|
|
//Boolean
|
|
|
|
|
if (type.Equals(typeof(Boolean)))
|
|
|
|
|
if (type.Equals(typeof(bool)))
|
|
|
|
|
{
|
|
|
|
|
var result = await plcService.ReadBoolAsync(point.Address);
|
|
|
|
|
GetReturnValue(point, result);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//Byte
|
|
|
|
|
if (type.Equals(typeof(Byte)))
|
|
|
|
|
if (type.Equals(typeof(byte)))
|
|
|
|
|
{
|
|
|
|
|
var result = await plcService.ReadByteAsync(point.Address);
|
|
|
|
|
GetReturnValue(point, result);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//Byte
|
|
|
|
|
if (type.Equals(typeof(Byte)))
|
|
|
|
|
if (type.Equals(typeof(byte)))
|
|
|
|
|
{
|
|
|
|
|
var result = await plcService.ReadByteAsync(point.Address);
|
|
|
|
|
GetReturnValue(point, result);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//Int16
|
|
|
|
|
if (type.Equals(typeof(Int16)))
|
|
|
|
|
if (type.Equals(typeof(short)))
|
|
|
|
|
{
|
|
|
|
|
var result = await plcService.ReadInt16Async(point.Address);
|
|
|
|
|
GetReturnValue(point, result);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//Int32
|
|
|
|
|
if (type.Equals(typeof(Int32)))
|
|
|
|
|
if (type.Equals(typeof(int)))
|
|
|
|
|
{
|
|
|
|
|
var result = await plcService.ReadInt32Async(point.Address);
|
|
|
|
|
GetReturnValue(point, result);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//Int64
|
|
|
|
|
if (type.Equals(typeof(Int64)))
|
|
|
|
|
if (type.Equals(typeof(long)))
|
|
|
|
|
{
|
|
|
|
|
var result = await plcService.ReadLongAsync(point.Address);
|
|
|
|
|
GetReturnValue(point, result);
|
|
|
|
@ -246,7 +252,7 @@ namespace PVDEMCS.Common.Devices.Impl
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//double
|
|
|
|
|
if (type.Equals(typeof(Double)))
|
|
|
|
|
if (type.Equals(typeof(double)))
|
|
|
|
|
{
|
|
|
|
|
var result = await plcService.ReadDoubleAsync(point.Address);
|
|
|
|
|
GetReturnValue(point, result);
|