|
|
@@ -14,12 +14,12 @@ using System.Reflection.Metadata;
|
|
|
using TwinCAT.Ads.TypeSystem;
|
|
|
using TwinCAT;
|
|
|
|
|
|
-namespace YSAI.Beckhoff.client
|
|
|
+namespace YSAI.Beckhoff
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 倍福PLC
|
|
|
/// </summary>
|
|
|
- public class BeckhoffClientOperate : IBaseAbstract, IDaq
|
|
|
+ public class BeckhoffOperate : IBaseAbstract, IDaq
|
|
|
{
|
|
|
protected override string TAG => "BeckhoffOperate";
|
|
|
/// <summary>
|
|
|
@@ -29,19 +29,19 @@ namespace YSAI.Beckhoff.client
|
|
|
/// <summary>
|
|
|
/// 自身对象集合
|
|
|
/// </summary>
|
|
|
- private static List<BeckhoffClientOperate> ThisObjList = new List<BeckhoffClientOperate>();
|
|
|
+ private static List<BeckhoffOperate> ThisObjList = new List<BeckhoffOperate>();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 单例模式
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
- public static BeckhoffClientOperate Instance(BeckhoffClientData.Basics basics)
|
|
|
+ public static BeckhoffOperate Instance(BeckhoffData.Basics basics)
|
|
|
{
|
|
|
if (ThisObjList.Count >= MaxInstanceCount)
|
|
|
{
|
|
|
throw new Exception(ExceedMaxInstanceCountTips);
|
|
|
}
|
|
|
- BeckhoffClientOperate? exp = ThisObjList.FirstOrDefault(c => c.basics.Comparer(basics).result);
|
|
|
+ BeckhoffOperate? exp = ThisObjList.FirstOrDefault(c => c.basics.Comparer(basics).result);
|
|
|
if (exp == null)
|
|
|
{
|
|
|
lock (Lock)
|
|
|
@@ -52,7 +52,7 @@ namespace YSAI.Beckhoff.client
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- BeckhoffClientOperate exp2 = new BeckhoffClientOperate(basics);
|
|
|
+ BeckhoffOperate exp2 = new BeckhoffOperate(basics);
|
|
|
ThisObjList.Add(exp2);
|
|
|
return exp2;
|
|
|
}
|
|
|
@@ -65,7 +65,7 @@ namespace YSAI.Beckhoff.client
|
|
|
/// 构造函数
|
|
|
/// </summary>
|
|
|
/// <param name="basics"></param>
|
|
|
- public BeckhoffClientOperate(BeckhoffClientData.Basics basics)
|
|
|
+ public BeckhoffOperate(BeckhoffData.Basics basics)
|
|
|
{
|
|
|
this.basics = basics;
|
|
|
}
|
|
|
@@ -73,7 +73,7 @@ namespace YSAI.Beckhoff.client
|
|
|
/// <summary>
|
|
|
/// 基础数据
|
|
|
/// </summary>
|
|
|
- private BeckhoffClientData.Basics basics { get; set; }
|
|
|
+ private BeckhoffData.Basics basics { get; set; }
|
|
|
/// <summary>
|
|
|
/// 虚拟地址
|
|
|
/// </summary>
|
|
|
@@ -127,7 +127,7 @@ namespace YSAI.Beckhoff.client
|
|
|
//设置参数
|
|
|
ConcurrentDictionary<string, AddressValue> param = new ConcurrentDictionary<string, AddressValue>();
|
|
|
//处理数据
|
|
|
- AddressValue addressValue = YSAI.Core.handler.AddressHandler.ExecuteDispose(addressDetails, value); //数据
|
|
|
+ AddressValue addressValue = Core.handler.AddressHandler.ExecuteDispose(addressDetails, value); //数据
|
|
|
//添加或更新
|
|
|
param.AddOrUpdate(addressDetails.AddressName, addressValue, (k, v) => addressValue);
|
|
|
|
|
|
@@ -178,7 +178,7 @@ namespace YSAI.Beckhoff.client
|
|
|
/// <param name="e"></param>
|
|
|
//private void Symbol_ValueChanged(object? sender, ValueChangedEventArgs e)
|
|
|
//{
|
|
|
-
|
|
|
+
|
|
|
//}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -199,7 +199,7 @@ namespace YSAI.Beckhoff.client
|
|
|
/// <summary>
|
|
|
/// 当连接状态已更改时发生
|
|
|
/// </summary>
|
|
|
- private void AdsClient_ConnectionStateChanged(object? sender, TwinCAT.ConnectionStateChangedEventArgs e)
|
|
|
+ private void AdsClient_ConnectionStateChanged(object? sender, ConnectionStateChangedEventArgs e)
|
|
|
{
|
|
|
OnEventHandler(sender, new EventResult(true, "连接状态已改变", e, Core.@enum.ResultType.Object));
|
|
|
}
|
|
|
@@ -228,14 +228,14 @@ namespace YSAI.Beckhoff.client
|
|
|
{
|
|
|
if (adsClient != null && adsClient.IsConnected)
|
|
|
{
|
|
|
- return Break(Depart("GetStatus"),true,"已连接");
|
|
|
+ return Break(Depart("GetStatus"), true, "已连接");
|
|
|
}
|
|
|
return Break(Depart("GetStatus"), false, "未连接");
|
|
|
}
|
|
|
|
|
|
public Task<OperateResult> GetStatusAsync()
|
|
|
{
|
|
|
- return Task.Run(()=> GetStatus());
|
|
|
+ return Task.Run(() => GetStatus());
|
|
|
}
|
|
|
|
|
|
public OperateResult Off()
|
|
|
@@ -328,12 +328,12 @@ namespace YSAI.Beckhoff.client
|
|
|
adsClient.AdsNotificationError += AdsClient_AdsNotificationError;
|
|
|
adsClient.AdsNotificationEx += AdsClient_AdsNotificationEx;
|
|
|
adsClient.AdsNotificationsInvalidated += AdsClient_AdsNotificationsInvalidated;
|
|
|
- adsClient.AdsStateChanged+= AdsClient_AdsStateChanged;
|
|
|
- adsClient.AdsSymbolVersionChanged+= AdsClient_AdsSymbolVersionChanged;
|
|
|
- adsClient.ConnectionStateChanged+= AdsClient_ConnectionStateChanged;
|
|
|
+ adsClient.AdsStateChanged += AdsClient_AdsStateChanged;
|
|
|
+ adsClient.AdsSymbolVersionChanged += AdsClient_AdsSymbolVersionChanged;
|
|
|
+ adsClient.ConnectionStateChanged += AdsClient_ConnectionStateChanged;
|
|
|
adsClient.RouterStateChanged += AdsClient_RouterStateChanged;
|
|
|
|
|
|
- return Break(SN,true);
|
|
|
+ return Break(SN, true);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
@@ -405,11 +405,11 @@ namespace YSAI.Beckhoff.client
|
|
|
resultAnyValue = adsClient.ReadAnyAsync(handle.Handle, typeof(DateTime), Cts.Token).Result;
|
|
|
break;
|
|
|
case Core.@enum.DataType.Time:
|
|
|
- resultRead = adsClient.ReadAsync(handle.Handle, readBuffer.AsMemory(0, TIME.MarshalSize), Cts.Token).Result;
|
|
|
+ resultRead = adsClient.ReadAsync(handle.Handle, readBuffer.AsMemory(0, TimeBase.MarshalSize), Cts.Token).Result;
|
|
|
if (resultRead.Succeeded)
|
|
|
{
|
|
|
TIME plcTime = null;
|
|
|
- PrimitiveTypeMarshaler.Default.Unmarshal(readBuffer.AsSpan(0, TIME.MarshalSize), out plcTime);
|
|
|
+ PrimitiveTypeMarshaler.Default.Unmarshal(readBuffer.AsSpan(0, TimeBase.MarshalSize), out plcTime);
|
|
|
if (plcTime != null)
|
|
|
{
|
|
|
Value = plcTime.Time.ToString();
|
|
|
@@ -417,11 +417,11 @@ namespace YSAI.Beckhoff.client
|
|
|
}
|
|
|
break;
|
|
|
case Core.@enum.DataType.Date:
|
|
|
- resultRead = adsClient.ReadAsync(handle.Handle, readBuffer.AsMemory(0, TIME.MarshalSize), Cts.Token).Result;
|
|
|
+ resultRead = adsClient.ReadAsync(handle.Handle, readBuffer.AsMemory(0, TimeBase.MarshalSize), Cts.Token).Result;
|
|
|
if (resultRead.Succeeded)
|
|
|
{
|
|
|
DATE plcDate = null;
|
|
|
- PrimitiveTypeMarshaler.Default.Unmarshal(readBuffer.AsSpan(0, TIME.MarshalSize), out plcDate);
|
|
|
+ PrimitiveTypeMarshaler.Default.Unmarshal(readBuffer.AsSpan(0, TimeBase.MarshalSize), out plcDate);
|
|
|
if (plcDate != null)
|
|
|
{
|
|
|
Value = plcDate.ToString();
|
|
|
@@ -498,7 +498,7 @@ namespace YSAI.Beckhoff.client
|
|
|
switch (item.AddressDataType)
|
|
|
{
|
|
|
case Core.@enum.DataType.Bool:
|
|
|
- type = typeof(bool);
|
|
|
+ type = typeof(bool);
|
|
|
break;
|
|
|
case Core.@enum.DataType.String:
|
|
|
case Core.@enum.DataType.Char:
|
|
|
@@ -542,7 +542,7 @@ namespace YSAI.Beckhoff.client
|
|
|
return Break(SN, false, ex.Message, Exception: ex);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
public Task<OperateResult> SubscribeAsync(Address address)
|
|
|
{
|
|
|
@@ -662,7 +662,7 @@ namespace YSAI.Beckhoff.client
|
|
|
{
|
|
|
byte[] writeBuffer = new byte[8];
|
|
|
PrimitiveTypeMarshaler.Default.Marshal(Param.Value, writeBuffer.AsSpan());
|
|
|
- resultWrite = adsClient.WriteAsync(handle.Handle, writeBuffer.AsMemory(0, TIME.MarshalSize), Cts.Token).Result;
|
|
|
+ resultWrite = adsClient.WriteAsync(handle.Handle, writeBuffer.AsMemory(0, TimeBase.MarshalSize), Cts.Token).Result;
|
|
|
if (!resultWrite.Succeeded)
|
|
|
{
|
|
|
FailMessage.Add($"{Param.Key},写入失败,{resultWrite.ErrorCode}");
|