other: 更新demo
This commit is contained in:
54
src/adapter/ThingsGateway.Foundation.Demo/S7MasterTest.cs
Normal file
54
src/adapter/ThingsGateway.Foundation.Demo/S7MasterTest.cs
Normal 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();
|
||||
}
|
||||
}
|
25
src/adapter/ThingsGateway.Foundation.Demo/S7Variable.cs
Normal file
25
src/adapter/ThingsGateway.Foundation.Demo/S7Variable.cs
Normal 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)
|
||||
{
|
||||
}
|
||||
}
|
@@ -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" />
|
||||
|
Reference in New Issue
Block a user