修改监控部分功能
This commit is contained in:
69
SamplePre.Communication/Communication/CommunicationBase.cs
Normal file
69
SamplePre.Communication/Communication/CommunicationBase.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SamplePre.Communication
|
||||
{
|
||||
public abstract class CommunicationBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 是否连接
|
||||
/// </summary>
|
||||
private bool _isConnected = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 连接状态变化事件
|
||||
/// </summary>
|
||||
public event Action<bool> ConnectionStatusChanged;
|
||||
|
||||
/// <summary>
|
||||
/// 是否连接
|
||||
/// </summary>
|
||||
public bool IsConnected
|
||||
{
|
||||
get => _isConnected;
|
||||
set
|
||||
{
|
||||
if (_isConnected != value)
|
||||
{
|
||||
_isConnected = value;
|
||||
ConnectionStatusChanged?.Invoke(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 下发下位机指令
|
||||
/// </summary>
|
||||
/// <param name="Dbno"></param>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="bytes"></param>
|
||||
/// <returns></returns>
|
||||
public abstract bool WriteArraysBtye<T>(int Dbno, int start, T[] bytes);
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 读取监控数据,读取数组
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public abstract ushort[] ReadArraysShort(int Dbno, int start, int lenth);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 写入数据
|
||||
/// </summary>
|
||||
/// <param name="address">地址(如"M0.0", "DB1.DBW2")</param>
|
||||
/// <param name="value">要写入的值</param>
|
||||
/// <returns>是否写入成功</returns>
|
||||
public abstract bool WriteSingleData(string address, object value);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SamplePre.Communication
|
||||
{
|
||||
public interface ICommunication
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 下发下位机指令
|
||||
/// </summary>
|
||||
/// <param name="Dbno"></param>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="bytes"></param>
|
||||
/// <returns></returns>
|
||||
bool WriteArraysBtye<T>(int Dbno, int start, T[] bytes);
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 读取监控数据,读取数组
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
ushort[] ReadArraysShort(int Dbno, int start, int lenth);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 写入数据
|
||||
/// </summary>
|
||||
/// <param name="address">地址(如"M0.0", "DB1.DBW2")</param>
|
||||
/// <param name="value">要写入的值</param>
|
||||
/// <returns>是否写入成功</returns>
|
||||
public bool WriteSingleData(string address, object value);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ using System.Threading.Tasks;
|
||||
namespace SamplePre.Communication.Communication
|
||||
{
|
||||
|
||||
public class ModbusTcpCommunicator : ICommunication, IDisposable
|
||||
public class ModbusTcpCommunicator : CommunicationBase, IDisposable
|
||||
{
|
||||
IModbusMaster _modbusMaster = null;
|
||||
TcpClient _tcpClient = null;
|
||||
@@ -19,31 +19,7 @@ namespace SamplePre.Communication.Communication
|
||||
private readonly int _port;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否连接
|
||||
/// </summary>
|
||||
private bool _isConnected = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否连接
|
||||
/// </summary>
|
||||
public bool IsConnected
|
||||
{
|
||||
get => _isConnected;
|
||||
set
|
||||
{
|
||||
if (_isConnected != value)
|
||||
{
|
||||
_isConnected = value;
|
||||
ConnectionStatusChanged?.Invoke(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接状态变化事件
|
||||
/// </summary>
|
||||
public event Action<bool> ConnectionStatusChanged;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
@@ -150,7 +126,7 @@ namespace SamplePre.Communication.Communication
|
||||
/// <param name="start"></param>
|
||||
/// <param name="bytes"></param>
|
||||
/// <returns></returns>
|
||||
public bool WriteArraysBtye<T>(int Dbno, int start, T[] data)
|
||||
public override bool WriteArraysBtye<T>(int Dbno, int start, T[] data)
|
||||
{
|
||||
|
||||
|
||||
@@ -184,7 +160,7 @@ namespace SamplePre.Communication.Communication
|
||||
/// 读取数组
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ushort[] ReadArraysShort(int Dbno, int start, int lenth)
|
||||
public override ushort[] ReadArraysShort(int Dbno, int start, int lenth)
|
||||
{
|
||||
|
||||
//try
|
||||
@@ -221,7 +197,7 @@ namespace SamplePre.Communication.Communication
|
||||
|
||||
}
|
||||
|
||||
public bool WriteSingleData(string address, object value)
|
||||
public override bool WriteSingleData(string address, object value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace SamplePre.Communication
|
||||
{
|
||||
public class S7PlcCommunicator : ICommunication, IDisposable
|
||||
public class S7PlcCommunicator : CommunicationBase, IDisposable
|
||||
{
|
||||
public Plc _plc;
|
||||
private readonly string _ipAddress;
|
||||
@@ -20,31 +20,31 @@ namespace SamplePre.Communication
|
||||
private readonly int _slot;
|
||||
private readonly CpuType _cpuType;
|
||||
|
||||
/// <summary>
|
||||
/// 是否连接
|
||||
/// </summary>
|
||||
private bool _isConnected = false;
|
||||
///// <summary>
|
||||
///// 是否连接
|
||||
///// </summary>
|
||||
//private bool _isConnected = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否连接
|
||||
/// </summary>
|
||||
public bool IsConnected
|
||||
{
|
||||
get => _isConnected;
|
||||
set
|
||||
{
|
||||
if (_isConnected != value)
|
||||
{
|
||||
_isConnected = value;
|
||||
ConnectionStatusChanged?.Invoke(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
///// <summary>
|
||||
///// 是否连接
|
||||
///// </summary>
|
||||
//public bool IsConnected
|
||||
//{
|
||||
// get => _isConnected;
|
||||
// set
|
||||
// {
|
||||
// if (_isConnected != value)
|
||||
// {
|
||||
// _isConnected = value;
|
||||
// ConnectionStatusChanged?.Invoke(value);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 连接状态变化事件
|
||||
/// </summary>
|
||||
public event Action<bool> ConnectionStatusChanged;
|
||||
///// <summary>
|
||||
///// 连接状态变化事件
|
||||
///// </summary>
|
||||
//public event Action<bool> ConnectionStatusChanged;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
@@ -127,7 +127,7 @@ namespace SamplePre.Communication
|
||||
/// <param name="start"></param>
|
||||
/// <param name="bytes"></param>
|
||||
/// <returns></returns>
|
||||
public bool WriteArraysBtye<T>(int Dbno, int start, T[] bytes)
|
||||
public override bool WriteArraysBtye<T>(int Dbno, int start, T[] bytes)
|
||||
{
|
||||
|
||||
try
|
||||
@@ -160,7 +160,7 @@ namespace SamplePre.Communication
|
||||
/// 读取数组
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ushort[] ReadArraysShort(int Dbno,int start,int lenth)
|
||||
public override ushort[] ReadArraysShort(int Dbno,int start,int lenth)
|
||||
{
|
||||
|
||||
try
|
||||
@@ -193,7 +193,7 @@ namespace SamplePre.Communication
|
||||
/// <param name="address">地址(如"M0.0", "DB1.DBW2")</param>
|
||||
/// <param name="value">要写入的值</param>
|
||||
/// <returns>是否写入成功</returns>
|
||||
public bool WriteSingleData(string address, object value)
|
||||
public override bool WriteSingleData(string address, object value)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user