|
@@ -10,13 +10,14 @@ using static YSAI.Core.reflection.ReflectionData;
|
|
|
using static YSAI.Core.reflection.ReflectionData.Basics.DllData.NamespaceData;
|
|
using static YSAI.Core.reflection.ReflectionData.Basics.DllData.NamespaceData;
|
|
|
using YSAI.Core.@interface.only;
|
|
using YSAI.Core.@interface.only;
|
|
|
using YSAI.Opc.ua.client;
|
|
using YSAI.Opc.ua.client;
|
|
|
|
|
+using YSAI.Modbus;
|
|
|
|
|
|
|
|
namespace YSAI.Test
|
|
namespace YSAI.Test
|
|
|
{
|
|
{
|
|
|
[TestClass]
|
|
[TestClass]
|
|
|
public class TestAll
|
|
public class TestAll
|
|
|
{
|
|
{
|
|
|
- //[TestMethod]
|
|
|
|
|
|
|
+ [TestMethod]
|
|
|
public void 反射与MQTT组合使用()
|
|
public void 反射与MQTT组合使用()
|
|
|
{
|
|
{
|
|
|
|
|
|
|
@@ -129,7 +130,6 @@ namespace YSAI.Test
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
[TestMethod]
|
|
[TestMethod]
|
|
|
public async Task OPCDA客户端测试()
|
|
public async Task OPCDA客户端测试()
|
|
|
{
|
|
{
|
|
@@ -237,17 +237,55 @@ namespace YSAI.Test
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- public async Task OPCUA客户端测试()
|
|
|
|
|
|
|
+ [TestMethod]
|
|
|
|
|
+ public void modbus测试()
|
|
|
{
|
|
{
|
|
|
- OpcUaClientOperate opcUaClient = OpcUaClientOperate.Instance(new OpcUaClientData.Basics());
|
|
|
|
|
|
|
+ Address address = new Address();
|
|
|
|
|
+ address.SN = Guid.NewGuid().ToString();
|
|
|
|
|
+ address.CreationTime = DateTime.Now;
|
|
|
|
|
+ address.AddressArray = new List<AddressDetails>();
|
|
|
|
|
+ address.AddressArray.Add(new AddressDetails
|
|
|
|
|
+ {
|
|
|
|
|
+ Address = "0,10" //从0开始往后读10位
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- opcUaClient.OnEvent += OpcUaClient_OnEvent;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ ConcurrentDictionary<ushort, ushort[]> wp=new ConcurrentDictionary<ushort, ushort[]>();
|
|
|
|
|
+ ushort[] ushorts=new ushort[16];
|
|
|
|
|
+ for (int i = 0; i < 16; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ ushorts[i] = (ushort)(i * new Random().NextDouble());
|
|
|
|
|
+ }
|
|
|
|
|
+ wp.TryAdd(0, ushorts);
|
|
|
|
|
+
|
|
|
|
|
+ ModbusOperate modbusOperate = ModbusOperate.Instance(new ModbusData.Basics()
|
|
|
|
|
+ {
|
|
|
|
|
+ ProtocolType = ModbusData.ProtocolType.Tcp,
|
|
|
|
|
+ TcpParam = new ModbusData.TcpParam()
|
|
|
|
|
+ {
|
|
|
|
|
+ Ip = "127.0.0.1"
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ OperateResult operateResult = modbusOperate.On();
|
|
|
|
|
+ Console.WriteLine(operateResult.Message);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ operateResult= modbusOperate.WriteMultipleRegisters(wp);
|
|
|
|
|
+ Console.WriteLine(operateResult.Message);
|
|
|
|
|
+
|
|
|
|
|
+ operateResult = modbusOperate.ReadCoils(address);
|
|
|
|
|
+ Console.WriteLine(operateResult.Message);
|
|
|
|
|
+
|
|
|
|
|
+ operateResult = modbusOperate.ReadHoldingRegisters(address);
|
|
|
|
|
+ Console.WriteLine(operateResult.Message);
|
|
|
|
|
+
|
|
|
|
|
+ operateResult = modbusOperate.ReadInputRegisters(address);
|
|
|
|
|
+ Console.WriteLine(operateResult.Message);
|
|
|
|
|
+
|
|
|
|
|
+ operateResult = modbusOperate.ReadInputs(address);
|
|
|
|
|
+ Console.WriteLine(operateResult.Message);
|
|
|
|
|
|
|
|
- private void OpcUaClient_OnEvent(object? sender, OpcUaClientData.Event e)
|
|
|
|
|
- {
|
|
|
|
|
- throw new NotImplementedException();
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|