other: 更新demo

This commit is contained in:
Diego
2024-06-21 18:10:13 +08:00
parent 119030f1a5
commit 643948331d
3 changed files with 80 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
//------------------------------------------------------------------------------
// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
// 此代码版权除特别声明外的代码归作者本人Diego所有
// 源代码使用协议遵循本仓库的开源协议及附加协议
// Gitee源代码仓库https://gitee.com/diego2098/ThingsGateway
// Github源代码仓库https://github.com/kimdiego2098/ThingsGateway
// 使用文档https://kimdiego2098.github.io/
// QQ群605534569
//------------------------------------------------------------------------------
using ThingsGateway.Foundation.Json.Extension;
using ThingsGateway.Foundation.Modbus;
using ThingsGateway.Foundation.SiemensS7;
using TouchSocket.Core;
namespace ThingsGateway.Foundation;
internal class S7MasterTest
{
private static SiemensS7Master GetMaster()
{
ConsoleLogger.Default.LogLevel = LogLevel.Trace;
var clientConfig = new TouchSocketConfig();
clientConfig.ConfigureContainer(a => a.AddConsoleLogger());
var clientChannel = clientConfig.GetTcpClientWithIPHost("127.0.0.1:102");
//clientChannel.Logger.LogLevel = LogLevel.Trace;
SiemensS7Master siemensS7Master = new(clientChannel)
{
SiemensS7Type = SiemensTypeEnum.S1500,
};
return siemensS7Master;
}
public static async Task Test()
{
using SiemensS7Master siemensS7Master = GetMaster();
//modbusMaster.HeartbeatHexString = "ccccdddd";//心跳
await siemensS7Master.ConnectAsync();
S7Variable s7Variable = new S7Variable(siemensS7Master, 200);
Console.ReadLine();
Console.WriteLine("批量读取");
await s7Variable.MultiReadAsync();
Console.WriteLine("写入");
await s7Variable.WriteData2Async(1, default);
Console.WriteLine("批量读取");
await s7Variable.MultiReadAsync();
Console.WriteLine(s7Variable.ToJsonString());
//执行连读
Console.ReadLine();
}
}

View File

@@ -0,0 +1,25 @@
//------------------------------------------------------------------------------
// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
// 此代码版权除特别声明外的代码归作者本人Diego所有
// 源代码使用协议遵循本仓库的开源协议及附加协议
// Gitee源代码仓库https://gitee.com/diego2098/ThingsGateway
// Github源代码仓库https://github.com/kimdiego2098/ThingsGateway
// 使用文档https://kimdiego2098.github.io/
// QQ群605534569
//------------------------------------------------------------------------------
namespace ThingsGateway.Foundation;
[GeneratorVariable]
public partial class S7Variable : VariableObject
{
[VariableRuntime(RegisterAddress = "DB1.48")]
public ushort Data1 { get; set; }
[VariableRuntime(RegisterAddress = "DB1.0")]
public uint Data2 { get; set; }
public S7Variable(IProtocol protocol, int maxPack) : base(protocol, maxPack)
{
}
}

View File

@@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="HslCommunication" Version="12.0.2" />
<PackageReference Include="NModbus" Version="3.0.81" />
<PackageReference Include="ThingsGateway.Foundation.SiemensS7" Version="6.0.3.32" />
<PackageReference Include="ThingsGateway.Foundation.Variable" Version="8.5.0" />
<PackageReference Include="ThingsGateway.Foundation.Modbus" Version="6.0.3.30" />
<PackageReference Include="TouchSocket.Modbus" Version="2.1.0-alpha.20" />