乐于分享
好东西不私藏

PC与PLC重连机制详细说明

PC与PLC重连机制详细说明

目录

1. [重连机制概述](#重连机制概述)
2. [PLC通信架构](#plc通信架构)
3. [连接状态机](#连接状态机)
4. [重连策略设计](#重连策略设计)
5. [基于HslCommunication的完整实现](#基于hslcommunication的完整实现)
6. [三菱PLC重连实现](#三菱plc重连实现)
7. [欧姆龙PLC重连实现](#欧姆龙plc重连实现)
8. [西门子PLC重连实现](#西门子plc重连实现)
9. [监控与诊断](#监控与诊断)
10. [常见问题与解决方案](#常见问题与解决方案)
11. [最佳实践](#最佳实践)
---

## 重连机制概述

### 为什么需要PLC需要重连机制?

在工业自动化场景中,PC与PLC之间的通信面临以下挑战:
| 问题 | 说明 |
|------|------|
| **网络抖动** | 工业环境中电磁干扰导致短暂网络中断 |
| **设备重启** | PLC维护、升级或故障恢复 |
| **线缆故障** | 物理连接松动或损坏 |
| **PLC断电** | 电源波动或计划性停机 |
| **IP变更** | 网络配置调整 |
| **服务端过载** | PLC处理能力不足导致超时 |

### 重连机制的核心目标

1. **自动恢复** - 无需人工干预,自动重建连接
2. **状态保持** - 准确记录连接状态变化
3. **数据缓存** - 断线期间的数据保护
4. **平滑过渡** - 重连后无缝恢复业务
5. **故障诊断** - 提供断线原因分析
---

## PLC通信架构

### 典型的PC-PLC通信层次结构

```
┌─────────────────────────────────────────────────────────┐
│                    WPF应用程序层                        │
│  ┌───────────────────────────────────────────────────┐ │
│  │              业务逻辑层                          │ │
│  │  (数据采集、设备控制、报警处理)                │ │
│  └─────────────────────┬─────────────────────────────┘ │
│                    │                                │
│  ┌─────────────────▼─────────────────────────────┐ │
│  │          PLC连接管理器层                      │ │
│  │  - 连接池管理                                │ │
│  │  - 状态监控                                  │ │
│  │  - 重连策略引擎                              │ │
│  └─────────────────────┬─────────────────────────────┘ │
│                    │                                │
│  ┌─────────────────▼─────────────────────────────┐ │
│  │          协议抽象层                            │ │
│  │  ┌──────────────┐  ┌──────────────┐  ┌─────────┐ │ │
│  │  │ 三菱     │  │  欧姆龙     │  │ 西  │ │ │
│  │  │ 协议    │  │  协议      │  │ 门  │ │ │
│  │  └──────────────┘  └──────────────┘  └─────┘ │ │
│  └─────────────────────┬─────────────────────────────┘ │
└────────────────────────┼─────────────────────────────┘
│ 以太网
┌─────────────────────────────────────────────────────────┐
│                    PLC设备层                             │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐        │
│  │ 三菱FX  │  │ 欧姆龙CJ │  │ 西门子S7 │        │
│  │ 系列    │  │  系列     │  │  系列    │        │
│  └──────────┘  └──────────┘  └──────────┘        │
└─────────────────────────────────────────────────────────┘
```

### 核心组件设计

```csharp
///
/// PLC连接接口 - 定义所有PLC设备的统一接口
///
public interface IPlcDevice : IDisposable
{
/// 设备名称
string DeviceName { get; }
/// IP地址
string IpAddress { get; }
/// 端口号
int Port { get; }
/// 当前连接状态
PlcConnectionState ConnectionState { get; }
/// 是否已连接
bool IsConnected { get; }
/// 连接状态变化事件
event EventHandler ConnectionStateChanged;
/// 连接PLC
Task ConnectAsync(CancellationToken cancellationToken = default);
/// 断开连接
Task DisconnectAsync();
/// 重新连接
Task ReconnectAsync(CancellationToken cancellationToken = default);
/// 读取数据
Task> ReadAsync(string address);
/// 写入数据
Task WriteAsync(string address, T value);
/// 心跳检测
Task HeartbeatAsync();
}
///
/// PLC连接状态
///
public enum PlcConnectionState
{
/// 未连接
Disconnected,
/// 连接中
Connecting,
/// 已连接
Connected,
/// 重连中
Reconnecting,
/// 断开中
Disconnecting,
/// 连接失败
Failed
}
///
/// PLC连接状态变更事件参数
///
public class PlcConnectionStateEventArgs : EventArgs
{
public PlcConnectionState OldState { get; set; }
public PlcConnectionState NewState { get; set; }
public DisconnectReason? Reason { get; set; }
public string Message { get; set; }
public Exception Exception { get; set; }
public DateTime Timestamp { get; set; } = DateTime.Now;
}
///
/// 断线原因
///
public enum DisconnectReason
{
Unknown,
NetworkTimeout,
ConnectionRefused,
DeviceReset,
AuthenticationFailed,
ProtocolError,
UserInitiated,
HeartbeatFailed
}
///
/// 操作结果(通用类
///
public class OperateResult
{
public bool IsSuccess { get; set; }
public string Message { get; set; }
public int ErrorCode { get; set; }
public static OperateResult CreateSuccess() => new OperateResult { IsSuccess = true };
public static OperateResult CreateFailed(string message) => new OperateResult { IsSuccess = false, Message = message };
}
public class OperateResult : OperateResult
{
public T Content { get; set; }
public static new OperateResult CreateSuccess(T content) => new OperateResult { IsSuccess = true, Content = content };
public static new OperateResult CreateFailed(string message) => new OperateResult { IsSuccess = false, Message = message };
}
```
---

## 连接状态机

### 完整的状态转换图

```
┌──────────┐
│Disconnected│
└────┬───────┘
│ 调用ConnectAsync()
┌──────────────┐
│  Connecting  │
└────┬────────┘
├─成功→ ┌──────────┐
│          │ Connected │
│          └─────┬──────┘
│                │ 心跳失败/读写失败
│                ↓
│          ┌──────────────┐
│          │  Reconnecting │
│          └─────┬────────┘
│                │
│ 失败           ├─成功→ 返回Connected
│                │
│                │ 超过最大重试次数
↓                ↓
┌──────────┐       ┌──────────┐
│Disconnecting│    │  Failed  │
└──────────┘       └──────────┘
┌──────────┐
│Disconnected│
└──────────┘
```

### 状态机实现

```csharp
///
/// PLC连接基类 - 实现状态机
///
public abstract class PlcDeviceBase : IPlcDevice
{
protected readonly object _lockObject = new object();
protected PlcConnectionState _connectionState;
protected int _reconnectCount;
protected DateTime _lastConnectedTime;
protected DateTime _lastDisconnectedTime;
protected Timer _heartbeatTimer;
protected CancellationTokenSource _reconnectCts;
protected Task _reconnectTask;
protected readonly IPlcReconnectionStrategy _reconnectionStrategy;
protected readonly ILogger _logger;
public string DeviceName { get; }
public string IpAddress { get; }
public int Port { get; }
public PlcConnectionState ConnectionState
{
get => _connectionState;
protected set
{
lock (_lockObject)
{
if (_connectionState != value)
{
var oldState = _connectionState;
_connectionState = value;
OnConnectionStateChanged(oldState, value);
}
}
}
}
public bool IsConnected => ConnectionState == PlcConnectionState.Connected;
public DateTime? LastConnectedTime => _lastConnectedTime;
public DateTime? LastDisconnectedTime => _lastDisconnectedTime;
public int ReconnectCount => _reconnectCount;
public event EventHandler ConnectionStateChanged;
protected PlcDeviceBase(
string deviceName,
string ipAddress,
int port,
IPlcReconnectionStrategy reconnectionStrategy,
ILogger logger)
{
DeviceName = deviceName ?? throw new ArgumentNullException(nameof(deviceName));
IpAddress = ipAddress ?? throw new ArgumentNullException(nameof(ipAddress));
Port = port;
_reconnectionStrategy = reconnectionStrategy ?? new ExponentialBackoffStrategy();
_logger = logger ?? NullLogger.Instance;
_connectionState = PlcConnectionState.Disconnected;
}
public async Task ConnectAsync(CancellationToken cancellationToken = default)
{
lock (_lockObject)
{
if (ConnectionState == PlcConnectionState.Connected)
{
_logger.LogInformation("[{DeviceName}] 已经处于连接状态", DeviceName);
return true;
}
if (ConnectionState == PlcConnectionState.Connecting ||
ConnectionState == PlcConnectionState.Reconnecting)
{
_logger.LogInformation("[{DeviceName}] 连接操作正在进行中", DeviceName);
return false;
}
ConnectionState = PlcConnectionState.Connecting;
}
try
{
_logger.LogInformation("[{DeviceName}] 正在连接PLC: {Ip}:{Port}", DeviceName, IpAddress, Port);
bool connected = await DoConnectAsync(cancellationToken);
if (connected)
{
lock (_lockObject)
{
ConnectionState = PlcConnectionState.Connected;
_lastConnectedTime = DateTime.Now;
_reconnectCount = 0;
_reconnectionStrategy.Reset();
StopReconnection();
StartHeartbeat();
}
_logger.LogInformation("[{DeviceName}] PLC连接成功", DeviceName);
return true;
}
else
{
lock (_lockObject)
{
ConnectionState = PlcConnectionState.Disconnected;
_lastDisconnectedTime = DateTime.Now;
}
_logger.LogWarning("[{DeviceName}] PLC连接失败", DeviceName);
return false;
}
}
catch (Exception ex)
{
lock (_lockObject)
{
ConnectionState = PlcConnectionState.Disconnected;
_lastDisconnectedTime = DateTime.Now;
}
_logger.LogError(ex, "[{DeviceName}] PLC连接异常", DeviceName);
OnConnectionStateChanged(PlcConnectionState.Connecting, PlcConnectionState.Disconnected,
DisconnectReason.NetworkTimeout, $"连接异常: {ex.Message}", ex);
return false;
}
}
public async Task DisconnectAsync()
{
lock (_lockObject)
{
if (ConnectionState == PlcConnectionState.Disconnected)
{
return;
}
ConnectionState = PlcConnectionState.Disconnecting;
StopHeartbeat();
StopReconnection();
}
try
{
_logger.LogInformation("[{DeviceName}] 正在断开PLC连接", DeviceName);
await DoDisconnectAsync();
}
finally
{
lock (_lockObject)
{
ConnectionState = PlcConnectionState.Disconnected;
_lastDisconnectedTime = DateTime.Now;
}
_logger.LogInformation("[{DeviceName}] PLC断开连接成功", DeviceName);
OnConnectionStateChanged(PlcConnectionState.Disconnecting, PlcConnectionState.Disconnected,
DisconnectReason.UserInitiated, "用户主动断开");
}
}
public async Task ReconnectAsync(CancellationToken cancellationToken = default)
{
_logger.LogInformation("[{DeviceName}] 开始重新连接...", DeviceName);
await DisconnectAsync();
await Task.Delay(500, cancellationToken);
return await ConnectAsync(cancellationToken);
}
protected void StartReconnection()
{
if (_reconnectTask != null && !_reconnectTask.IsCompleted)
{
return;
}
_reconnectCts = new CancellationTokenSource();
_reconnectTask = Task.Run(() => ReconnectionLoop(_reconnectCts.Token));
}
protected void StopReconnection()
{
if (_reconnectCts != null)
{
_reconnectCts.Cancel();
_reconnectCts.Dispose();
_reconnectCts = null;
}
}
private async Task ReconnectionLoop(CancellationToken cancellationToken)
{
int attempt = 0;
while (!cancellationToken.IsCancellationRequested)
{
try
{
attempt++;
_reconnectCount = attempt;
var interval = _reconnectionStrategy.GetNextRetryInterval(attempt);
_logger.LogInformation("[{DeviceName}] 重连尝试 {Attempt}, 等待 {Delay:F1}秒...",
DeviceName, attempt, interval.TotalSeconds);
await Task.Delay(interval, cancellationToken);
bool connected = await ConnectAsync(cancellationToken);
if (connected)
{
break;
}
if (!_reconnectionStrategy.ShouldRetry(attempt, null))
{
lock (_lockObject)
{
ConnectionState = PlcConnectionState.Failed;
}
_logger.LogError("[{DeviceName}] 重连失败,已达到最大重试次数 {Attempt}", DeviceName, attempt);
break;
}
}
catch (OperationCanceledException)
{
break;
}
catch (Exception ex)
{
_logger.LogError(ex, "[{DeviceName}] 重连异常", DeviceName);
}
}
}
protected void StartHeartbeat()
{
StopHeartbeat();
_heartbeatTimer = new Timer(
HeartbeatCallback,
null,
TimeSpan.FromSeconds(5),
TimeSpan.FromSeconds(5));
}
protected void StopHeartbeat()
{
_heartbeatTimer?.Dispose();
_heartbeatTimer = null;
}
private async void HeartbeatCallback(object state)
{
if (!IsConnected)
{
return;
}
try
{
bool alive = await HeartbeatAsync();
if (!alive)
{
_logger.LogWarning("[{DeviceName}] 心跳检测失败", DeviceName);
await HandleConnectionErrorAsync(DisconnectReason.HeartbeatFailed, "心跳检测失败");
}
}
catch (Exception ex)
{
_logger.LogError(ex, "[{DeviceName}] 心跳检测异常", DeviceName);
await HandleConnectionErrorAsync(DisconnectReason.HeartbeatFailed, $"心跳异常: {ex.Message}");
}
}
protected async Task HandleConnectionErrorAsync(DisconnectReason reason, string message)
{
lock (_lockObject)
{
if (ConnectionState == PlcConnectionState.Disconnected)
{
return;
}
ConnectionState = PlcConnectionState.Disconnected;
_lastDisconnectedTime = DateTime.Now;
}
OnConnectionStateChanged(PlcConnectionState.Connected, PlcConnectionState.Disconnected, reason, message);
StartReconnection();
}
protected virtual void OnConnectionStateChanged(
PlcConnectionState oldState,
PlcConnectionState newState,
DisconnectReason? reason = null,
string message = null,
Exception exception = null)
{
ConnectionStateChanged?.Invoke(this, new PlcConnectionStateEventArgs
{
OldState = oldState,
NewState = newState,
Reason = reason,
Message = message,
Exception = exception
});
}
protected abstract Task DoConnectAsync(CancellationToken cancellationToken);
protected abstract Task DoDisconnectAsync();
public abstract Task> ReadAsync(string address);
public abstract Task WriteAsync(string address, T value);
public abstract Task HeartbeatAsync();
public virtual void Dispose()
{
StopHeartbeat();
StopReconnection();
DisconnectAsync().Wait(TimeSpan.FromSeconds(5));
}
}
```
---

## 重连策略设计

### 1. 指数退避策略(推荐)

```csharp
///
/// 重连策略接口
///
public interface IPlcReconnectionStrategy
{
TimeSpan GetNextRetryInterval(int attemptCount);
bool ShouldRetry(int attemptCount, Exception lastException);
void Reset();
}
///
/// 指数退避重连策略配置
///
public class ExponentialBackoffConfig
{
public int BaseRetryIntervalMs { get; set; } = 2000;
public int MaxRetryIntervalMs { get; set; } = 60000;
public double RetryMultiplier { get; set; } = 2.0;
public int MaxRetryCount { get; set; } = int.MaxValue;
public bool EnableJitter { get; set; } = true;
}
///
/// 指数退避重连策略
///
public class ExponentialBackoffStrategy : IPlcReconnectionStrategy
{
private readonly ExponentialBackoffConfig _config;
private readonly Random _random;
public ExponentialBackoffStrategy(ExponentialBackoffConfig config = null)
{
_config = config ?? new ExponentialBackoffConfig();
_random = new Random();
}
public TimeSpan GetNextRetryInterval(int attemptCount)
{
double interval = _config.BaseRetryIntervalMs * Math.Pow(_config.RetryMultiplier, attemptCount - 1);
interval = Math.Min(interval, _config.MaxRetryIntervalMs);
if (_config.EnableJitter)
{
double jitter = interval * 0.1 * (_random.NextDouble() * 2 - 1);
interval += jitter;
}
return TimeSpan.FromMilliseconds(Math.Max(1000, interval));
}
public bool ShouldRetry(int attemptCount, Exception lastException)
{
if (attemptCount >= _config.MaxRetryCount)
{
return false;
}
if (lastException != null)
{
if (IsNonRetryableException(lastException))
{
return false;
}
}
return true;
}
public void Reset()
{
}
private bool IsNonRetryableException(Exception ex)
{
if (ex.Message.Contains("认证失败") || ex.Message.Contains("Authentication failed"))
return true;
if (ex.Message.Contains("设备已停用") || ex.Message.Contains("Device disabled"))
return true;
return false;
}
}
///
/// 固定间隔重连策略
///
public class FixedIntervalStrategy : IPlcReconnectionStrategy
{
private readonly int _intervalMs;
private readonly int _maxRetryCount;
public FixedIntervalStrategy(int intervalMs = 5000, int maxRetryCount = int.MaxValue)
{
_intervalMs = intervalMs;
_maxRetryCount = maxRetryCount;
}
public TimeSpan GetNextRetryInterval(int attemptCount)
{
return TimeSpan.FromMilliseconds(_intervalMs);
}
public bool ShouldRetry(int attemptCount, Exception lastException)
{
return attemptCount < _maxRetryCount;
}
public void Reset()
{
}
}
///
/// 线性退避重连策略
///
public class LinearBackoffStrategy : IPlcReconnectionStrategy
{
private readonly int _baseIntervalMs;
private readonly int _incrementMs;
private readonly int _maxIntervalMs;
private readonly int _maxRetryCount;
public LinearBackoffStrategy(int baseIntervalMs = 2000, int incrementMs = 2000, int maxIntervalMs = 30000, int maxRetryCount = int.MaxValue)
{
_baseIntervalMs = baseIntervalMs;
_incrementMs = incrementMs;
_maxIntervalMs = maxIntervalMs;
_maxRetryCount = maxRetryCount;
}
public TimeSpan GetNextRetryInterval(int attemptCount)
{
int interval = _baseIntervalMs + (attemptCount - 1) * _incrementMs;
interval = Math.Min(interval, _maxIntervalMs);
return TimeSpan.FromMilliseconds(interval));
}
public bool ShouldRetry(int attemptCount, Exception lastException)
{
return attemptCount < _maxRetryCount;
}
public void Reset()
{
}
}
```

### 重连策略对比

| 策略类型 | 优点 | 缺点 | 适用场景 |
|---------|------|------|---------|
| 固定间隔 | 简单易实现 | 可能造成网络风暴 | 网络稳定,设备少 |
| 指数退避 | 避免网络风暴,智能调整 | 长时间断线后恢复慢 | 大多数工业场景,推荐使用 |
| 线性退避 | 平衡简单和智能 | 间隔增长均匀 | 中等网络环境 |
---

## 基于HslCommunication的完整实现

### 三菱PLC重连实现

```csharp
using HslCommunication;
using HslCommunication.Profinet.Melsec;
using Microsoft.Extensions.Logging;
namespace IndustrialPlc.PlcDevices
{
///
/// 三菱PLC设备
///
public class MelsecPlcDevice : PlcDeviceBase
{
private MelsecMcNet _plc;
private readonly string _plcType;
public MelsecPlcDevice(
string deviceName,
string ipAddress,
int port = 6000,
string plcType = "Q",
IPlcReconnectionStrategy reconnectionStrategy = null,
ILogger logger = null)
: base(deviceName, ipAddress, port, reconnectionStrategy, logger)
{
_plcType = plcType;
}
protected override Task DoConnectAsync(CancellationToken cancellationToken)
{
return Task.Run(() =>
{
try
{
_plc = new MelsecMcNet(IpAddress, Port)
{
ConnectTimeOut = 5000,
ReceiveTimeOut = 5000
};
if (_plcType == "FX")
{
_plc.Series = MelsecSeries.FX5U;
}
else if (_plcType == "Q")
{
_plc.Series = MelsecSeries.Q;
}
OperateResult connectResult = _plc.ConnectServer();
if (connectResult.IsSuccess)
{
_logger.LogInformation("[{DeviceName}] 三菱PLC连接成功", DeviceName);
return true;
}
else
{
_logger.LogWarning("[{DeviceName}] 三菱PLC连接失败: {Message}", DeviceName, connectResult.Message);
return false;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "[{DeviceName}] 三菱PLC连接异常", DeviceName);
return false;
}
}, cancellationToken);
}
protected override Task DoDisconnectAsync()
{
try
{
_plc?.ConnectClose();
_plc?.Dispose();
_plc = null;
}
catch (Exception ex)
{
_logger.LogError(ex, "[{DeviceName}] 断开三菱PLC连接异常", DeviceName);
}
return Task.CompletedTask;
}
public override Task> ReadAsync(string address)
{
return Task.Run(() =>
{
if (!IsConnected || _plc == null)
{
return OperateResult.CreateFailed("PLC未连接");
}
try
{
Type type = typeof(T);
OperateResult result;
if (type == typeof(short))
{
result = _plc.ReadInt16(address);
}
else if (type == typeof(ushort))
{
result = _plc.ReadUInt16(address);
}
else if (type == typeof(int))
{
result = _plc.ReadInt32(address);
}
else if (type == typeof(uint))
{
result = _plc.ReadUInt32(address);
}
else if (type == typeof(float))
{
result = _plc.ReadFloat(address);
}
else if (type == typeof(bool))
{
result = _plc.ReadBool(address);
}
else
{
return OperateResult.CreateFailed($"不支持的数据类型: {type.Name}");
}
if (result.IsSuccess)
{
return OperateResult.CreateSuccess((T)result.Content);
}
else
{
_ = HandleConnectionErrorAsync(DisconnectReason.ProtocolError, $"读取失败: {result.Message}");
return OperateResult.CreateFailed(result.Message);
}
}
catch (Exception ex)
{
_logger.LogError(ex, "[{DeviceName}] 读取数据异常", DeviceName);
_ = HandleConnectionErrorAsync(DisconnectReason.ProtocolError, $"读取异常: {ex.Message}");
return OperateResult.CreateFailed(ex.Message);
}
});
}
public override Task WriteAsync(string address, T value)
{
return Task.Run(() =>
{
if (!IsConnected || _plc == null)
{
return OperateResult.CreateFailed("PLC未连接");
}
try
{
OperateResult result;
Type type = typeof(T);
if (type == typeof(short))
{
result = _plc.Write(address, (short)(object)value);
}
else if (type == typeof(ushort))
{
result = _plc.Write(address, (ushort)(object)value);
}
else if (type == typeof(int))
{
result = _plc.Write(address, (int)(object)value);
}
else if (type == typeof(uint))
{
result = _plc.Write(address, (uint)(object)value);
}
else if (type == typeof(float))
{
result = _plc.Write(address, (float)(object)value);
}
else if (type == typeof(bool))
{
result = _plc.Write(address, (bool)(object)value);
}
else
{
return OperateResult.CreateFailed($"不支持的数据类型: {type.Name}");
}
if (result.IsSuccess)
{
return OperateResult.CreateSuccess();
}
else
{
_ = HandleConnectionErrorAsync(DisconnectReason.ProtocolError, $"写入失败: {result.Message}");
return OperateResult.CreateFailed(result.Message);
}
}
catch (Exception ex)
{
_logger.LogError(ex, "[{DeviceName}] 写入数据异常", DeviceName);
_ = HandleConnectionErrorAsync(DisconnectReason.ProtocolError, $"写入异常: {ex.Message}");
return OperateResult.CreateFailed(ex.Message);
}
});
}
public override Task HeartbeatAsync()
{
return Task.Run(() =>
{
if (_plc == null)
{
return false;
}
try
{
var result = _plc.ReadInt16("D0");
return result.IsSuccess;
}
catch
{
return false;
}
});
}
}
}
```

### 欧姆龙PLC重连实现

```csharp
using HslCommunication;
using HslCommunication.Profinet.Omron;
using Microsoft.Extensions.Logging;
namespace IndustrialPlc.PlcDevices
{
///
/// 欧姆龙PLC设备
///
public class OmronPlcDevice : PlcDeviceBase
{
private OmronFinsNet _plc;
private readonly byte _localNode;
private readonly byte _plcNode;
public OmronPlcDevice(
string deviceName,
string ipAddress,
int port = 9600,
byte localNode = 0,
byte plcNode = 0,
IPlcReconnectionStrategy reconnectionStrategy = null,
ILogger logger = null)
: base(deviceName, ipAddress, port, reconnectionStrategy, logger)
{
_localNode = localNode;
_plcNode = plcNode;
}
protected override Task DoConnectAsync(CancellationToken cancellationToken)
{
return Task.Run(() =>
{
try
{
_plc = new OmronFinsNet(IpAddress, Port)
{
ConnectTimeOut = 5000,
ReceiveTimeOut = 5000,
LocalNode = _localNode,
DestNode = _plcNode
};
OperateResult connectResult = _plc.ConnectServer();
if (connectResult.IsSuccess)
{

相关学习资料