Files
ThingsGateway/framework/Plugin/ThingsGateway.Plugin.Siemens/Page/S7_1500DebugPage.razor.cs
2023-09-30 23:05:53 +08:00

93 lines
3.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#region copyright
//------------------------------------------------------------------------------
// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
// 此代码版权除特别声明外的代码归作者本人Diego所有
// 源代码使用协议遵循本仓库的开源协议及附加协议
// Gitee源代码仓库https://gitee.com/diego2098/ThingsGateway
// Github源代码仓库https://github.com/kimdiego2098/ThingsGateway
// 使用文档https://diego2098.gitee.io/thingsgateway-docs/
// QQ群605534569
//------------------------------------------------------------------------------
#endregion
using ThingsGateway.Foundation.Adapter.Siemens;
namespace ThingsGateway.Foundation.Demo;
/// <inheritdoc/>
public partial class S7_1500DebugPage
{
/// <summary>
/// SerialSessionPage
/// </summary>
private TcpClientPage TcpClientPage;
private DriverDebugUIPage driverDebugUIPage;
private ThingsGateway.Foundation.Adapter.Siemens.SiemensS7PLC _plc;
/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="firstRender"></param>
protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
_sections.Add((
"""
private static async Task ModbusClientAsync()
{
//链路基础配置项
var config = new TouchSocketConfig();
config
.SetRemoteIPHost(new IPHost("127.0.0.1:502"))//TCP/UDP链路才需要
var tcpClient1 = new TcpClient();//链路对象
tcpClient1.Setup(config);
//创建协议对象,构造函数需要传入对应链路对象
SiemensS7PLC plc = new(tcpClient1,SiemensEnum.S1500)
{
//协议配置
DataFormat = DataFormat.ABCD,
FrameTime = 0,
CacheTimeout = 1000,
ConnectTimeOut = 3000,
Station = 1,
TimeOut = 3000,
IsCheckMessageId = true
};
#region
var bytesResult = await plc.ReadAsync("400001", 20);
var int32sResult = await plc.ReadInt32Async("400001", 20);
#endregion
}
""", "csharp"));
if (TcpClientPage != null)
TcpClientPage.LogAction = driverDebugUIPage.LogOut;
_plc = new ThingsGateway.Foundation.Adapter.Siemens.SiemensS7PLC(TcpClientPage.GetTcpClient(), SiemensEnum.S1500);
driverDebugUIPage.Plc = _plc;
//初始化
driverDebugUIPage.Address = "M100";
int index = 0;
driverDebugUIPage.DeviceVariableRunTimes.ForEach(a => a.VariableAddress = "M" + (100 + index++));
TcpClientPage.Port = 102;
TcpClientPage.StateHasChangedAsync();
//载入配置
StateHasChanged();
}
base.OnAfterRender(firstRender);
}
}