using HslCommunication;
|
using HslCommunication.ModBus;
|
using HslCommunication.Profinet.Melsec;
|
using HslCommunication.Profinet.Siemens;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Entity.DomainModels;
|
|
namespace WIDESEA_WCS.WCSClient
|
{
|
public class PLCClient
|
{
|
/// <summary>
|
/// PLC连接对象集合
|
/// </summary>
|
public static List<PLCClient> Clients = new List<PLCClient>();
|
|
|
#region 基础参数
|
/// <summary>
|
/// PLC名称
|
/// </summary>
|
public string PLCName { get; set; }
|
|
/// <summary>
|
/// PLC类型\协议类型
|
/// </summary>
|
public string PLCType { get; set; }
|
|
/// <summary>
|
/// Ip地址
|
/// </summary>
|
public string Ip { get; set; }
|
|
/// <summary>
|
/// Ip地址
|
/// </summary>
|
public int Port { get; set; }
|
|
/// <summary>
|
/// 插槽
|
/// </summary>
|
public int Slot { get; set; }
|
#endregion
|
|
#region 拓展属性
|
/// <summary>
|
/// 交互协议
|
/// </summary>
|
public List<DBItemGroup> itemGroups = new List<DBItemGroup>();
|
|
/// <summary>
|
/// 心跳
|
/// </summary>
|
public bool Heart { get; set; }
|
|
/// <summary>
|
/// 是否连接
|
/// </summary>
|
public bool IsConnected { get; set; }
|
#endregion
|
|
#region PLC对象
|
/// <summary>
|
/// 西门子 PLC
|
/// </summary>
|
public SiemensS7Net siemensPLCClient { get; set; }
|
|
public ModbusTcpNet modbusTcpNet { get; set; }
|
|
public MelsecMcNet melsecMcNet { get; set; }
|
#endregion
|
|
#region 公用方法
|
/// <summary>
|
/// 连接PLC
|
/// </summary>
|
/// <returns></returns>
|
public virtual string Connect()
|
{
|
throw new NotImplementedException();
|
}
|
|
/// <summary>
|
/// 断开PLC连接
|
/// </summary>
|
/// <returns></returns>
|
public virtual bool DisConnect()
|
{
|
throw new NotImplementedException();
|
}
|
|
/// <summary>
|
/// 读取数据,根据DB地址
|
/// </summary>
|
/// <typeparam name="DataType"></typeparam>
|
/// <param name="dbAddress"></param>
|
/// <param name="len"></param>
|
/// <returns></returns>
|
/// <exception cref="NotImplementedException"></exception>
|
public virtual DataType Read<DataType>(string dbAddress, int len = 1)
|
{
|
throw new NotImplementedException();
|
}
|
|
/// <summary>
|
/// 读取数据,根据数据库指令
|
/// </summary>
|
/// <typeparam name="DataType"></typeparam>
|
/// <param name="orderName"></param>
|
/// <returns></returns>
|
/// <exception cref="NotImplementedException"></exception>
|
public virtual DataType ReadByOrder<DataType>(string orderName, string Method = null)
|
{
|
throw new NotImplementedException();
|
}
|
|
public object ReadValues(string equipNum)
|
{
|
throw new NotImplementedException();
|
}
|
/// <summary>
|
/// 写入数据,根据DB地址
|
/// </summary>
|
/// <param name="dbAddress"></param>
|
/// <param name="value"></param>
|
/// <returns></returns>
|
/// <exception cref="NotImplementedException"></exception>
|
public virtual bool Write(string dbAddress, object value)
|
{
|
throw new NotImplementedException();
|
}
|
|
/// <summary>
|
/// 写入数据,根据数据库指令
|
/// </summary>
|
/// <param name="orderName"></param>
|
/// <param name="value"></param>
|
/// <returns></returns>
|
/// <exception cref="NotImplementedException"></exception>
|
public virtual bool WriteByOrder(string orderName, object value, string Method = null)
|
{
|
throw new NotImplementedException();
|
}
|
|
/// <summary>
|
/// 获取内容
|
/// </summary>
|
/// <param name="operateResult"></param>
|
/// <param name="item"></param>
|
public object GetContent<T>(OperateResult<T> operateResult, DBItemGroup item)
|
{
|
if (!operateResult.IsSuccess)
|
{
|
IsConnected = false;
|
throw new Exception($"【Error】数据读取失败,指令{item.name},DB地址{item.dbAddress}\n错误信息:{operateResult.Message}");
|
}
|
return operateResult.Content;
|
}
|
|
/// <summary>
|
/// 获取内容
|
/// </summary>
|
/// <typeparam name="T"></typeparam>
|
/// <param name="operateResult"></param>
|
/// <param name="dbAddress"></param>
|
/// <returns></returns>
|
public object GetContent<T>(OperateResult<T> operateResult, string dbAddress)
|
{
|
if (!operateResult.IsSuccess)
|
{
|
IsConnected = false;
|
throw new Exception($"【Error】数据读取失败,DB地址{dbAddress}\n错误信息:{operateResult.Message}");
|
}
|
return operateResult.Content;
|
}
|
|
#endregion
|
}
|
}
|