|
|
@@ -16,6 +16,8 @@ using YSAI.Mqtt.service.websocket;
|
|
|
using YSAI.Modbus.service;
|
|
|
using YSAI.Kafka;
|
|
|
using YSAI.RabbitMQ;
|
|
|
+using S7.Net;
|
|
|
+using YSAI.S7.client;
|
|
|
|
|
|
namespace YSAI.Test
|
|
|
{
|
|
|
@@ -159,7 +161,6 @@ namespace YSAI.Test
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
[TestMethod]
|
|
|
public async Task OPCDA客户端测试()
|
|
|
{
|
|
|
@@ -267,7 +268,6 @@ namespace YSAI.Test
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
[TestMethod]
|
|
|
public void modbus测试()
|
|
|
{
|
|
|
@@ -426,15 +426,12 @@ namespace YSAI.Test
|
|
|
Console.WriteLine(item.Value.Value);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
private static void OpcUaClientOperate_OnEvent(object? sender, OpcUaClientData.Event e)
|
|
|
{
|
|
|
Console.ForegroundColor = ConsoleColor.Green;
|
|
|
Console.WriteLine(e.Message);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
[TestMethod]
|
|
|
public void 创建反射配置()
|
|
|
{
|
|
|
@@ -901,5 +898,54 @@ namespace YSAI.Test
|
|
|
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ [TestMethod]
|
|
|
+ public void S7测试()
|
|
|
+ {
|
|
|
+ //对象实例
|
|
|
+ S7ClientOperate s7ClientOperate = S7ClientOperate.Instance(new S7ClientData.Basics()
|
|
|
+ {
|
|
|
+ Ip = "192.168.2.20",
|
|
|
+ Port = 102,
|
|
|
+ Rack = 0,
|
|
|
+ Slot = 1,
|
|
|
+ S7CpuType = CpuType.S71200,
|
|
|
+ SN = Guid.NewGuid().ToString()
|
|
|
+ });
|
|
|
+
|
|
|
+ //打开
|
|
|
+ OperateResult operateResult = s7ClientOperate.On();
|
|
|
+ Console.WriteLine(operateResult.Message);
|
|
|
+
|
|
|
+ //点位地址
|
|
|
+ Address address = new Address();
|
|
|
+ address.SN = Guid.NewGuid().ToString();
|
|
|
+ address.CreationTime = DateTime.Now.ToLocalTime();
|
|
|
+ address.AddressArray = new List<AddressDetails>();
|
|
|
+ address.AddressArray.Add(new AddressDetails()
|
|
|
+ {
|
|
|
+ AddressName = "DB71.DBD4",
|
|
|
+ AddressDataType = Core.@enum.DataType.Float,
|
|
|
+ AddressType = AddressType.Reality
|
|
|
+ });
|
|
|
+
|
|
|
+ //读取
|
|
|
+ operateResult = s7ClientOperate.Read(address);
|
|
|
+ Console.WriteLine(operateResult.Message);
|
|
|
+ if (operateResult.State)
|
|
|
+ {
|
|
|
+ foreach (var item in operateResult.RData as ConcurrentDictionary<string, AddressValue>)
|
|
|
+ {
|
|
|
+ Console.WriteLine(item.Key);
|
|
|
+ Console.WriteLine(item.Value.Value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //写入
|
|
|
+ ConcurrentDictionary<string, float> keyValuePairs = new ConcurrentDictionary<string, float>();
|
|
|
+ keyValuePairs.TryAdd("DB71.DBD4", 1.6666f);
|
|
|
+ operateResult = s7ClientOperate.Write(keyValuePairs);
|
|
|
+ Console.WriteLine(operateResult.Message);
|
|
|
+ }
|
|
|
}
|
|
|
}
|