-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.json
More file actions
162 lines (162 loc) · 53.5 KB
/
index.json
File metadata and controls
162 lines (162 loc) · 53.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
{
"api/MAS.Communication.CommProtocol.html": {
"href": "api/MAS.Communication.CommProtocol.html",
"title": "Enum CommProtocol | MAS.Communication API Reference",
"summary": "Enum CommProtocol Namespace MAS.Communication Assembly MAS.Communication.dll 通讯协议枚举 public enum CommProtocol Fields MC = 1 三菱 MC协议 ModbusTcp = 2 Modbus TCP 协议 S7 = 0 西门子 S7 协议"
},
"api/MAS.Communication.CommunicationConfigExtensions.html": {
"href": "api/MAS.Communication.CommunicationConfigExtensions.html",
"title": "Class CommunicationConfigExtensions | MAS.Communication API Reference",
"summary": "Class CommunicationConfigExtensions Namespace MAS.Communication Assembly MAS.Communication.dll 通讯配置扩展方法 public static class CommunicationConfigExtensions Inheritance object CommunicationConfigExtensions Inherited Members object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Methods GetInstanceKey(ICommunicationConfig) 获取通讯实例键 public static string GetInstanceKey(this ICommunicationConfig config) Parameters config ICommunicationConfig 通讯配置 Returns string 唯一实例键 Exceptions NotSupportedException"
},
"api/MAS.Communication.ConnectionException.html": {
"href": "api/MAS.Communication.ConnectionException.html",
"title": "Class ConnectionException | MAS.Communication API Reference",
"summary": "Class ConnectionException Namespace MAS.Communication Assembly MAS.Communication.dll 连接错误异常 public class ConnectionException : Exception, ISerializable Inheritance object Exception ConnectionException Implements ISerializable Inherited Members Exception.GetBaseException() Exception.GetType() Exception.ToString() Exception.Data Exception.HelpLink Exception.HResult Exception.InnerException Exception.Message Exception.Source Exception.StackTrace Exception.TargetSite Exception.SerializeObjectState object.Equals(object) object.Equals(object, object) object.GetHashCode() object.MemberwiseClone() object.ReferenceEquals(object, object) Constructors ConnectionException(string) 初始化 ConnectionException 新实例 public ConnectionException(string message) Parameters message string 异常消息 ConnectionException(string, Exception) 初始化 ConnectionException 新实例 public ConnectionException(string message, Exception innerException) Parameters message string 异常消息 innerException Exception 内部异常"
},
"api/MAS.Communication.FixedStringAttribute.html": {
"href": "api/MAS.Communication.FixedStringAttribute.html",
"title": "Class FixedStringAttribute | MAS.Communication API Reference",
"summary": "Class FixedStringAttribute Namespace MAS.Communication Assembly MAS.Communication.dll 固定长度字符串字段特性(按字节长度) [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] public sealed class FixedStringAttribute : Attribute Inheritance object Attribute FixedStringAttribute Inherited Members Attribute.Equals(object) Attribute.GetCustomAttribute(Assembly, Type) Attribute.GetCustomAttribute(Assembly, Type, bool) Attribute.GetCustomAttribute(MemberInfo, Type) Attribute.GetCustomAttribute(MemberInfo, Type, bool) Attribute.GetCustomAttribute(Module, Type) Attribute.GetCustomAttribute(Module, Type, bool) Attribute.GetCustomAttribute(ParameterInfo, Type) Attribute.GetCustomAttribute(ParameterInfo, Type, bool) Attribute.GetCustomAttributes(Assembly) Attribute.GetCustomAttributes(Assembly, bool) Attribute.GetCustomAttributes(Assembly, Type) Attribute.GetCustomAttributes(Assembly, Type, bool) Attribute.GetCustomAttributes(MemberInfo) Attribute.GetCustomAttributes(MemberInfo, bool) Attribute.GetCustomAttributes(MemberInfo, Type) Attribute.GetCustomAttributes(MemberInfo, Type, bool) Attribute.GetCustomAttributes(Module) Attribute.GetCustomAttributes(Module, bool) Attribute.GetCustomAttributes(Module, Type) Attribute.GetCustomAttributes(Module, Type, bool) Attribute.GetCustomAttributes(ParameterInfo) Attribute.GetCustomAttributes(ParameterInfo, bool) Attribute.GetCustomAttributes(ParameterInfo, Type) Attribute.GetCustomAttributes(ParameterInfo, Type, bool) Attribute.GetHashCode() Attribute.IsDefaultAttribute() Attribute.IsDefined(Assembly, Type) Attribute.IsDefined(Assembly, Type, bool) Attribute.IsDefined(MemberInfo, Type) Attribute.IsDefined(MemberInfo, Type, bool) Attribute.IsDefined(Module, Type) Attribute.IsDefined(Module, Type, bool) Attribute.IsDefined(ParameterInfo, Type) Attribute.IsDefined(ParameterInfo, Type, bool) Attribute.Match(object) Attribute.TypeId object.Equals(object, object) object.GetType() object.ReferenceEquals(object, object) object.ToString() Constructors FixedStringAttribute(int) 固定长度字符串字段特性(按字节长度) public FixedStringAttribute(int length) Parameters length int Properties EncodingName 获取或设置编码方式 public string EncodingName { get; set; } Property Value string Remarks 默认值: \"ASCII\" Length 获取字符串字节长度 public int Length { get; } Property Value int PaddingChar 获取或设置填充字符 public char PaddingChar { get; set; } Property Value char Remarks 默认值: '\\0' TrimEndPadding 获取或设置是否去除末尾填充 public bool TrimEndPadding { get; set; } Property Value bool Remarks 默认值: true"
},
"api/MAS.Communication.ICommunicationConfig.html": {
"href": "api/MAS.Communication.ICommunicationConfig.html",
"title": "Interface ICommunicationConfig | MAS.Communication API Reference",
"summary": "Interface ICommunicationConfig Namespace MAS.Communication Assembly MAS.Communication.dll 通讯协议的基本参数配置接口 public interface ICommunicationConfig : ICloneable Inherited Members ICloneable.Clone() Extension Methods CommunicationConfigExtensions.GetInstanceKey(ICommunicationConfig) Properties Ip 获取或设置 Ip 地址 string Ip { get; set; } Property Value string MaxRetries 获取或设置连接失败时的重试次数上限 int MaxRetries { get; set; } Property Value int ProtocolName 获取协议名称 string ProtocolName { get; } Property Value string ReadTimeout 获取或设置读取超时时间(ms) int ReadTimeout { get; set; } Property Value int WriteTimeout 获取或设置写入超时时间(ms) int WriteTimeout { get; set; } Property Value int Methods Clone<T>() 泛型克隆方法,返回指定类型的克隆实例 T Clone<T>() where T : ICommunicationConfig Returns T 克隆后的实例 Type Parameters T 克隆实例的类型,必须实现 ICommunicationConfig 接口"
},
"api/MAS.Communication.IProtocol.html": {
"href": "api/MAS.Communication.IProtocol.html",
"title": "Interface IProtocol | MAS.Communication API Reference",
"summary": "Interface IProtocol Namespace MAS.Communication Assembly MAS.Communication.dll 所有通信协议的统一接口 public interface IProtocol : IDisposable Inherited Members IDisposable.Dispose() Properties Configuration 获取通讯配置 ICommunicationConfig Configuration { get; } Property Value ICommunicationConfig ProtocolType 获取协议类型 CommProtocol ProtocolType { get; } Property Value CommProtocol Methods CheckConnection() 检查设备连接状态 bool CheckConnection() Returns bool 连接活跃返回true,否则返回false Remarks 部分协议中的实现只能作为快速判断 ConnectAsync(CancellationToken) 异步建立与设备的连接 Task ConnectAsync(CancellationToken cts = default) Parameters cts CancellationToken 取消令牌 Returns Task 表示一个异步操作任务 Exceptions OperationCanceledException ConnectionException Disconnect() 关闭设备连接 void Disconnect() ProbeConnectionAsync(CancellationToken) 异步测试设备连接,成功后自动关闭 Task<bool> ProbeConnectionAsync(CancellationToken cts = default) Parameters cts CancellationToken 取消令牌 Returns Task<bool> 一个异步操作任务,成功返回 true,否则返回 false Exceptions OperationCanceledException TryReconnectAsync(int, int, CancellationToken) 异步尝试重新连接到设备 Task<bool> TryReconnectAsync(int maxAttempts, int retryDelay = 1000, CancellationToken cts = default) Parameters maxAttempts int 最多尝试次数 retryDelay int 重试等待时间(毫秒) cts CancellationToken 取消令牌 Returns Task<bool> 一个异步操作任务,成功连接则返回 true,否则返回 false Remarks 在中途断线时调用此方法将尝试重新连接 Exceptions OperationCanceledException Events Disposed 当实例被释放后触发 event EventHandler? Disposed Event Type EventHandler"
},
"api/MAS.Communication.IProtocolManager.html": {
"href": "api/MAS.Communication.IProtocolManager.html",
"title": "Interface IProtocolManager | MAS.Communication API Reference",
"summary": "Interface IProtocolManager Namespace MAS.Communication Assembly MAS.Communication.dll 通讯协议实例管理器接口 public interface IProtocolManager : IDisposable Inherited Members IDisposable.Dispose() Properties Count 获取当前已缓存的协议实例数量 int Count { get; } Property Value int Methods Contains(IProtocol) 判断指定协议实例是否已存在于缓存中 bool Contains(IProtocol protocol) Parameters protocol IProtocol 协议实例 Returns bool 存在返回 true,否则返回 false Contains(string) 判断指定实例标识是否已存在于缓存中 bool Contains(string instanceId) Parameters instanceId string 实例标识 Returns bool 存在返回 true,否则返回 false Get(string) 根据实例标识获取已缓存的协议实例 IProtocol? Get(string instanceId) Parameters instanceId string 实例标识 Returns IProtocol 协议实例;不存在时返回 null GetInstanceIds() 获取当前所有实例标识 IReadOnlyCollection<string> GetInstanceIds() Returns IReadOnlyCollection<string> 实例标识集合快照 GetOrCreate(ICommunicationConfig) 根据配置获取协议实例;如果实例不存在,则创建并缓存 IProtocol GetOrCreate(ICommunicationConfig config) Parameters config ICommunicationConfig 通讯配置实例 Returns IProtocol 协议实例 Exceptions NotSupportedException 不支持的通讯配置类型时抛出 ObjectDisposedException 对象已被释放时抛出 GetOrCreate<TProtocol>(ICommunicationConfig) 根据配置获取指定类型的协议实例;如果实例不存在,则创建并缓存 TProtocol GetOrCreate<TProtocol>(ICommunicationConfig config) where TProtocol : class, IProtocol Parameters config ICommunicationConfig 通讯配置实例 Returns TProtocol 指定类型的协议实例 Type Parameters TProtocol 协议类型 Exceptions InvalidCastException 创建的协议实例与指定类型不匹配时抛出 NotSupportedException 不支持的通讯配置类型时抛出 ObjectDisposedException 对象已被释放时抛出 Get<TProtocol>(string) 根据实例标识获取已缓存的指定类型协议实例 TProtocol? Get<TProtocol>(string instanceId) where TProtocol : class, IProtocol Parameters instanceId string 实例标识 Returns TProtocol 指定类型协议实例;不存在或类型不匹配时返回 null Type Parameters TProtocol 协议类型 Remove(IProtocol) 移除并释放指定实例 bool Remove(IProtocol protocol) Parameters protocol IProtocol 通讯实例 Returns bool 移除成功返回 true,否则返回 false Exceptions ObjectDisposedException 对象已被释放时抛出 Remove(string) 移除并释放指定标识的协议实例 bool Remove(string instanceId) Parameters instanceId string 实例标识 Returns bool 移除成功返回 true,否则返回 false Exceptions ObjectDisposedException 对象已被释放时抛出 Events ProtocolCreated 当协议实例被创建时触发的事件 event EventHandler<ProtocolCreatedEventArgs>? ProtocolCreated Event Type EventHandler<ProtocolCreatedEventArgs> ProtocolRemoved 当协议实例被移除时触发的事件 event EventHandler<ProtocolRemovedEventArgs>? ProtocolRemoved Event Type EventHandler<ProtocolRemovedEventArgs>"
},
"api/MAS.Communication.McProtocol.IMcCommunicationConfig.html": {
"href": "api/MAS.Communication.McProtocol.IMcCommunicationConfig.html",
"title": "Interface IMcCommunicationConfig | MAS.Communication API Reference",
"summary": "Interface IMcCommunicationConfig Namespace MAS.Communication.McProtocol Assembly MAS.Communication.dll MC 协议参数配置接口 public interface IMcCommunicationConfig : ICommunicationConfig, ICloneable Inherited Members ICommunicationConfig.ProtocolName ICommunicationConfig.Ip ICommunicationConfig.MaxRetries ICommunicationConfig.ReadTimeout ICommunicationConfig.WriteTimeout ICommunicationConfig.Clone<T>() ICloneable.Clone() Extension Methods CommunicationConfigExtensions.GetInstanceKey(ICommunicationConfig) Properties Port 获取或设置端口 int Port { get; set; } Property Value int ProtocolFrame 获取或设置协议帧 McFrame ProtocolFrame { get; set; } Property Value McFrame"
},
"api/MAS.Communication.McProtocol.IMcProtocol.html": {
"href": "api/MAS.Communication.McProtocol.IMcProtocol.html",
"title": "Interface IMcProtocol | MAS.Communication API Reference",
"summary": "Interface IMcProtocol Namespace MAS.Communication.McProtocol Assembly MAS.Communication.dll 与三菱 MC 协议的 PLC 设备进行通信的接口 public interface IMcProtocol : IProtocol, IDisposable Inherited Members IProtocol.Disposed IProtocol.ProtocolType IProtocol.Configuration IProtocol.ConnectAsync(CancellationToken) IProtocol.ProbeConnectionAsync(CancellationToken) IProtocol.CheckConnection() IProtocol.TryReconnectAsync(int, int, CancellationToken) IProtocol.Disconnect() IDisposable.Dispose() Methods ReadBitsAsync(string, int, int, CancellationToken) 异步从PLC读取位数据 Task<bool[]> ReadBitsAsync(string deviceType, int startAddress, int length, CancellationToken cts = default) Parameters deviceType string 指定设备类型 startAddress int 起始地址 length int 要读取的位的数量 cts CancellationToken 取消令牌 Returns Task<bool[]> 异步操作任务结果,包含读取位状态的布尔值数组 Exceptions OperationCanceledException ReadErrorException ReadStructAsync<T>(string, int, CancellationToken) 异步从 PLC 读取结构体数据 Task<T> ReadStructAsync<T>(string deviceType, int startAddress, CancellationToken cts = default) where T : struct Parameters deviceType string 指定设备类型 startAddress int 起始地址 cts CancellationToken 取消令牌 Returns Task<T> 读取到的结构体实例 Type Parameters T 结构体类型 Exceptions OperationCanceledException ReadErrorException ReadWordsAsync(string, int, int, CancellationToken) 异步从PLC读取字数据 Task<short[]> ReadWordsAsync(string deviceType, int startAddress, int length, CancellationToken cts = default) Parameters deviceType string 指定设备类型 startAddress int 起始地址 length int 要读取的数据长度 cts CancellationToken 取消令牌 Returns Task<short[]> 异步操作任务结果,包含读取值的整数数组 Exceptions OperationCanceledException ReadErrorException ReadWordsAsync<T>(string, int, int, CancellationToken) 异步从PLC读取字数据 Task<T[]> ReadWordsAsync<T>(string deviceType, int startAddress, int length, CancellationToken cts = default) Parameters deviceType string 指定设备类型 startAddress int 起始地址 length int 要读取的数据长度 cts CancellationToken 取消令牌 Returns Task<T[]> 异步操作任务结果,包含读取值的泛型数组 Type Parameters T 数据类型: short、int、float、double Exceptions OperationCanceledException ReadErrorException WriteBitsAsync(string, int, bool[], CancellationToken) 异步写入位数据到PLC Task WriteBitsAsync(string deviceType, int startAddress, bool[] values, CancellationToken cts = default) Parameters deviceType string 指定设备类型 startAddress int 起始地址 values bool[] 要写入的布尔值数组,表示位状态 cts CancellationToken 取消令牌 Returns Task 异步操作任务结果 Exceptions OperationCanceledException WriteErrorException WriteStructAsync<T>(string, int, T, CancellationToken) 异步写入结构体数据到 PLC Task WriteStructAsync<T>(string deviceType, int startAddress, T value, CancellationToken cts = default) where T : struct Parameters deviceType string 指定设备类型 startAddress int 起始地址 value T 结构体实例 cts CancellationToken 取消令牌 Returns Task 异步操作任务 Type Parameters T 结构体类型 Exceptions OperationCanceledException WriteErrorException WriteWordsAsync(string, int, short[], CancellationToken) 异步写入字数据到PLC Task WriteWordsAsync(string deviceType, int startAddress, short[] values, CancellationToken cts = default) Parameters deviceType string 指定设备类型 startAddress int 起始地址 values short[] 要写入的整数数组 cts CancellationToken 取消令牌 Returns Task 异步操作任务结果 Exceptions OperationCanceledException WriteErrorException WriteWordsAsync<T>(string, int, T[], CancellationToken) 异步写入字数据到PLC Task WriteWordsAsync<T>(string deviceType, int startAddress, T[] values, CancellationToken cts = default) Parameters deviceType string 指定设备类型 startAddress int 起始地址 values T[] 要写入的数据数组 cts CancellationToken 取消令牌 Returns Task 异步操作任务结果 Type Parameters T 数据类型: short、int、float、double Exceptions OperationCanceledException WriteErrorException"
},
"api/MAS.Communication.McProtocol.McFrame.html": {
"href": "api/MAS.Communication.McProtocol.McFrame.html",
"title": "Enum McFrame | MAS.Communication API Reference",
"summary": "Enum McFrame Namespace MAS.Communication.McProtocol Assembly MAS.Communication.dll 三菱 MC 协议帧类型 public enum McFrame Fields MC1E = 4 1E 帧(早期格式,报文短,功能受限) MC3E = 11 3E 帧(常用格式,支持以太网通信) MC4E = 15 4E 帧(扩展格式,支持更大数据长度)"
},
"api/MAS.Communication.McProtocol.html": {
"href": "api/MAS.Communication.McProtocol.html",
"title": "Namespace MAS.Communication.McProtocol | MAS.Communication API Reference",
"summary": "Namespace MAS.Communication.McProtocol Interfaces IMcCommunicationConfig MC 协议参数配置接口 IMcProtocol 与三菱 MC 协议的 PLC 设备进行通信的接口 Enums McFrame 三菱 MC 协议帧类型"
},
"api/MAS.Communication.ModbusProtocol.IModbusCommunicationConfig.html": {
"href": "api/MAS.Communication.ModbusProtocol.IModbusCommunicationConfig.html",
"title": "Interface IModbusCommunicationConfig | MAS.Communication API Reference",
"summary": "Interface IModbusCommunicationConfig Namespace MAS.Communication.ModbusProtocol Assembly MAS.Communication.dll Modbus 通信配置接口 public interface IModbusCommunicationConfig : ICommunicationConfig, ICloneable Inherited Members ICommunicationConfig.ProtocolName ICommunicationConfig.Ip ICommunicationConfig.MaxRetries ICommunicationConfig.ReadTimeout ICommunicationConfig.WriteTimeout ICommunicationConfig.Clone<T>() ICloneable.Clone() Extension Methods CommunicationConfigExtensions.GetInstanceKey(ICommunicationConfig) Properties ByteOrder 获取或设置字节序(Byte Order) ModbusByteOrder ByteOrder { get; set; } Property Value ModbusByteOrder Remarks 用于控制寄存器内字节的排列方式 Port 获取或设置 Modbus TCP 通信端口 short Port { get; set; } Property Value short Remarks 默认值为 502(标准 Modbus 端口) UnitId 获取或设置默认从站地址(Unit ID),取值范围通常为 1~247 byte UnitId { get; set; } Property Value byte UseOneBasedAddress 获取或设置是否使用“1-based”地址基准 bool UseOneBasedAddress { get; set; } Property Value bool Remarks 示例: - 若手册标注地址为 40001,对应协议实际地址为 0(0-based) - 启用 UseOneBasedAddress = true:调用时传 40001,内部自动转为 0 - 禁用 UseOneBasedAddress = false:调用时必须传 0 WordOrder 获取或设置字词序(Word Order) ModbusWordOrder WordOrder { get; set; } Property Value ModbusWordOrder Remarks 用于控制多寄存器数据(如浮点数、长整型)中寄存器的排列顺序"
},
"api/MAS.Communication.ModbusProtocol.IModbusProtocol.html": {
"href": "api/MAS.Communication.ModbusProtocol.IModbusProtocol.html",
"title": "Interface IModbusProtocol | MAS.Communication API Reference",
"summary": "Interface IModbusProtocol Namespace MAS.Communication.ModbusProtocol Assembly MAS.Communication.dll Modbus 协议通信接口 public interface IModbusProtocol : IProtocol, IDisposable Inherited Members IProtocol.Disposed IProtocol.ProtocolType IProtocol.Configuration IProtocol.ConnectAsync(CancellationToken) IProtocol.ProbeConnectionAsync(CancellationToken) IProtocol.CheckConnection() IProtocol.TryReconnectAsync(int, int, CancellationToken) IProtocol.Disconnect() IDisposable.Dispose() Methods ReadBitsAsync(ModbusDataArea, ushort, ushort, CancellationToken) 异步读取位变量区域 Task<bool[]> ReadBitsAsync(ModbusDataArea area, ushort startAddress, ushort count, CancellationToken cts = default) Parameters area ModbusDataArea 数据区域类型 startAddress ushort 起始地址 count ushort 读取的位数量 cts CancellationToken 取消令牌,用于取消异步操作 Returns Task<bool[]> 一个异步操作任务结果,布尔数组,表示各 bit 的值(true = 1, false = 0) Exceptions ReadErrorException OperationCanceledException TimeoutException ReadRegistersAsync(ModbusDataArea, ushort, ushort, CancellationToken) 异步读取 16 位寄存器区域 Task<ushort[]> ReadRegistersAsync(ModbusDataArea area, ushort startAddress, ushort count, CancellationToken cts = default) Parameters area ModbusDataArea 数据区域类型 startAddress ushort 起始地址 count ushort 读取的寄存器数量 cts CancellationToken 取消令牌 Returns Task<ushort[]> 一个异步操作任务结果,ushort数组,每个元素代表一个16位寄存器的值 Exceptions ReadErrorException OperationCanceledException TimeoutException ReadStructAsync<T>(ModbusDataArea, ushort, CancellationToken) 异步从寄存器区域读取结构体数据 Task<T> ReadStructAsync<T>(ModbusDataArea area, ushort startAddress, CancellationToken cts = default) where T : struct Parameters area ModbusDataArea 数据区域类型(通常为 HoldingRegisters / InputRegisters) startAddress ushort 起始地址(寄存器地址) cts CancellationToken 取消令牌 Returns Task<T> 结构体实例 Type Parameters T 结构体类型 Exceptions ReadErrorException OperationCanceledException TimeoutException WriteBitsAsync(ushort, bool[], CancellationToken) 异步写入位变量到线圈区域 Task WriteBitsAsync(ushort startAddress, bool[] values, CancellationToken cts = default) Parameters startAddress ushort 起始地址 values bool[] 要写入的布尔值数组(true = 置位,false = 复位) cts CancellationToken 取消令牌 Returns Task 表示一个异步操作任务 Exceptions WriteErrorException OperationCanceledException TimeoutException WriteRegistersAsync(ushort, ushort[], CancellationToken) 异步写入 16 位寄存器数据 Task WriteRegistersAsync(ushort startAddress, ushort[] values, CancellationToken cts = default) Parameters startAddress ushort 起始地址 values ushort[] 要写入的 16 位值数组 cts CancellationToken 取消令牌 Returns Task 表示一个异步操作任务 Exceptions WriteErrorException OperationCanceledException TimeoutException WriteStructAsync<T>(ushort, T, CancellationToken) 异步将结构体数据写入寄存器区域 Task WriteStructAsync<T>(ushort startAddress, T value, CancellationToken cts = default) where T : struct Parameters startAddress ushort 起始地址(寄存器地址) value T 结构体实例 cts CancellationToken 取消令牌 Returns Task 异步操作任务 Type Parameters T 结构体类型 Exceptions WriteErrorException OperationCanceledException TimeoutException"
},
"api/MAS.Communication.ModbusProtocol.ModbusByteOrder.html": {
"href": "api/MAS.Communication.ModbusProtocol.ModbusByteOrder.html",
"title": "Enum ModbusByteOrder | MAS.Communication API Reference",
"summary": "Enum ModbusByteOrder Namespace MAS.Communication.ModbusProtocol Assembly MAS.Communication.dll 16 位寄存器内部的字节顺序枚举 public enum ModbusByteOrder Fields BigEndian = 0 大端模式:高位字节在前,低位字节在后 LittleEndian = 1 小端模式:低位字节在前,高位字节在后"
},
"api/MAS.Communication.ModbusProtocol.ModbusDataArea.html": {
"href": "api/MAS.Communication.ModbusProtocol.ModbusDataArea.html",
"title": "Enum ModbusDataArea | MAS.Communication API Reference",
"summary": "Enum ModbusDataArea Namespace MAS.Communication.ModbusProtocol Assembly MAS.Communication.dll Modbus 数据区域类型枚举 public enum ModbusDataArea Fields Coils = 0 0x: 线圈,读写位变量,FC01/05/15 DiscreteInputs = 1 1x: 离散输入,只读位变量,FC02 HoldingRegisters = 2 4x: 保持寄存器,读写16位寄存器,FC03/06/16 InputRegisters = 3 3x: 输入寄存器,只读16位寄存器,FC04"
},
"api/MAS.Communication.ModbusProtocol.ModbusWordOrder.html": {
"href": "api/MAS.Communication.ModbusProtocol.ModbusWordOrder.html",
"title": "Enum ModbusWordOrder | MAS.Communication API Reference",
"summary": "Enum ModbusWordOrder Namespace MAS.Communication.ModbusProtocol Assembly MAS.Communication.dll 32/64位数据的“寄存器字序”(两个/四个寄存器的顺序) public enum ModbusWordOrder Fields Normal = 0 不交换(ABCD) Swap = 1 按 16 位寄存器交换(CDAB)"
},
"api/MAS.Communication.ModbusProtocol.html": {
"href": "api/MAS.Communication.ModbusProtocol.html",
"title": "Namespace MAS.Communication.ModbusProtocol | MAS.Communication API Reference",
"summary": "Namespace MAS.Communication.ModbusProtocol Interfaces IModbusCommunicationConfig Modbus 通信配置接口 IModbusProtocol Modbus 协议通信接口 Enums ModbusByteOrder 16 位寄存器内部的字节顺序枚举 ModbusDataArea Modbus 数据区域类型枚举 ModbusWordOrder 32/64位数据的“寄存器字序”(两个/四个寄存器的顺序)"
},
"api/MAS.Communication.ProtocolCreatedEventArgs.html": {
"href": "api/MAS.Communication.ProtocolCreatedEventArgs.html",
"title": "Class ProtocolCreatedEventArgs | MAS.Communication API Reference",
"summary": "Class ProtocolCreatedEventArgs Namespace MAS.Communication Assembly MAS.Communication.dll 协议实例创建事件参数 public sealed class ProtocolCreatedEventArgs : EventArgs Inheritance object EventArgs ProtocolCreatedEventArgs Inherited Members EventArgs.Empty object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.ReferenceEquals(object, object) object.ToString() Constructors ProtocolCreatedEventArgs(IProtocol) 协议实例创建事件参数 public ProtocolCreatedEventArgs(IProtocol protocol) Parameters protocol IProtocol Properties Config 获取该实例的通讯配置 public ICommunicationConfig Config { get; } Property Value ICommunicationConfig InstanceId 获取该实例标识 public string InstanceId { get; } Property Value string Protocol 获取该协议实例 public IProtocol Protocol { get; } Property Value IProtocol"
},
"api/MAS.Communication.ProtocolRemovedEventArgs.html": {
"href": "api/MAS.Communication.ProtocolRemovedEventArgs.html",
"title": "Class ProtocolRemovedEventArgs | MAS.Communication API Reference",
"summary": "Class ProtocolRemovedEventArgs Namespace MAS.Communication Assembly MAS.Communication.dll 协议实例移除事件参数 public sealed class ProtocolRemovedEventArgs : EventArgs Inheritance object EventArgs ProtocolRemovedEventArgs Inherited Members EventArgs.Empty object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.ReferenceEquals(object, object) object.ToString() Constructors ProtocolRemovedEventArgs(string) 协议实例移除事件参数 public ProtocolRemovedEventArgs(string instanceId) Parameters instanceId string Properties InstanceId 获取该实例标识 public string InstanceId { get; } Property Value string"
},
"api/MAS.Communication.ReadErrorException.html": {
"href": "api/MAS.Communication.ReadErrorException.html",
"title": "Class ReadErrorException | MAS.Communication API Reference",
"summary": "Class ReadErrorException Namespace MAS.Communication Assembly MAS.Communication.dll 读取数据错误异常 public class ReadErrorException : Exception, ISerializable Inheritance object Exception ReadErrorException Implements ISerializable Inherited Members Exception.GetBaseException() Exception.GetType() Exception.ToString() Exception.Data Exception.HelpLink Exception.HResult Exception.InnerException Exception.Message Exception.Source Exception.StackTrace Exception.TargetSite Exception.SerializeObjectState object.Equals(object) object.Equals(object, object) object.GetHashCode() object.MemberwiseClone() object.ReferenceEquals(object, object) Constructors ReadErrorException(string) 初始化 ReadErrorException 新实例 public ReadErrorException(string message) Parameters message string 异常消息 ReadErrorException(string, Exception) 初始化 ReadErrorException 新实例 public ReadErrorException(string message, Exception innerException) Parameters message string 异常消息 innerException Exception 内部异常"
},
"api/MAS.Communication.S7Protocol.IS7CommunicationConfig.html": {
"href": "api/MAS.Communication.S7Protocol.IS7CommunicationConfig.html",
"title": "Interface IS7CommunicationConfig | MAS.Communication API Reference",
"summary": "Interface IS7CommunicationConfig Namespace MAS.Communication.S7Protocol Assembly MAS.Communication.dll S7 通讯参数配置接口 public interface IS7CommunicationConfig : ICommunicationConfig, ICloneable Inherited Members ICommunicationConfig.ProtocolName ICommunicationConfig.Ip ICommunicationConfig.MaxRetries ICommunicationConfig.ReadTimeout ICommunicationConfig.WriteTimeout ICommunicationConfig.Clone<T>() ICloneable.Clone() Extension Methods CommunicationConfigExtensions.GetInstanceKey(ICommunicationConfig) Properties Rack 获取或设置机架 short Rack { get; set; } Property Value short Slot 获取或设置插槽 short Slot { get; set; } Property Value short Type 获取或设置型号 string Type { get; set; } Property Value string"
},
"api/MAS.Communication.S7Protocol.IS7Protocol.html": {
"href": "api/MAS.Communication.S7Protocol.IS7Protocol.html",
"title": "Interface IS7Protocol | MAS.Communication API Reference",
"summary": "Interface IS7Protocol Namespace MAS.Communication.S7Protocol Assembly MAS.Communication.dll 与西门子 S7 设备进行通信的接口 public interface IS7Protocol : IProtocol, IDisposable Inherited Members IProtocol.Disposed IProtocol.ProtocolType IProtocol.Configuration IProtocol.ConnectAsync(CancellationToken) IProtocol.ProbeConnectionAsync(CancellationToken) IProtocol.CheckConnection() IProtocol.TryReconnectAsync(int, int, CancellationToken) IProtocol.Disconnect() IDisposable.Dispose() Methods ReadAsync(DataType, int, int, VarType, int, CancellationToken) 异步读取解码 Task<object?> ReadAsync(DataType dataType, int db, int startByteAdr, VarType varType, int varCount, CancellationToken cts = default) Parameters dataType DataType 数据类型 db int 数据块编号 startByteAdr int 起始字节地址 varType VarType 要转换字节的数据类型 varCount int 要读取的变量数量 cts CancellationToken 取消令牌 Returns Task<object> 异步操作任务结果,读取的数据对象,由调用方处理可能发生的异常 Remarks 这个方法适用于需要根据特定的数据类型进行数据交换的场合,当需要读取特定类型的数据(整数、实数等)到PLC的数据块时,可以自动处理数据类型的转换 Exceptions OperationCanceledException 取消此操作时抛出此异常 ReadErrorException 读取异常 ReadBytesAsync(DataType, int, int, int, CancellationToken) 异步从PLC读取字数据 Task<byte[]> ReadBytesAsync(DataType dataType, int db, int startByteAdr, int count, CancellationToken cts = default) Parameters dataType DataType 数据类型 db int 数据块编号 startByteAdr int 起始字节地址 count int 读取的字节数 cts CancellationToken 取消令牌 Returns Task<byte[]> 异步操作任务结果,读取到的字节数组,由调用方处理可能发生的异常 Remarks 这个方法适用于当系统需要直接处理或分析来自特定PLC内存区域的字节流,或者处理未经封装的简单数据类型时使用 Exceptions OperationCanceledException 取消此操作时抛出此异常 ReadErrorException 读取异常 ReadClassAsync(object, int, int, CancellationToken) 异步从PLC读取数据到C#类的实例 Task ReadClassAsync(object sourceClass, int db, int startByteAdr = 0, CancellationToken cts = default) Parameters sourceClass object 要填充数据的类的实例 db int 数据块编号 startByteAdr int 起始字节地址,默认为0 cts CancellationToken 取消令牌 Returns Task 异步操作任务结果,由调用方处理可能发生的异常 Remarks 这个方法适用于将数据块中的数据直接读入一个已定义的C#类中,处理复杂的数据结构 Exceptions OperationCanceledException 取消此操作时抛出此异常 ReadErrorException 读取异常 ReadMultipleVarsAsync(List<DataItem>, CancellationToken) 异步从PLC读取多个变量 Task ReadMultipleVarsAsync(List<DataItem> dataItems, CancellationToken cts = default) Parameters dataItems List<DataItem> 包含要读取的所有数据项信息的列表 cts CancellationToken 取消令牌 Returns Task 异步操作任务结果,由调用方处理可能发生的异常 Remarks 这个方法适用于当需要在一个操作中读取多个不同的变量时使用,这些变量分布在不同的数据块或者地址,减少网络通信的次数 Exceptions OperationCanceledException 取消此操作时抛出此异常 ReadErrorException 读取异常 ReadStructAsync(Type, int, int, CancellationToken) 异步读取PLC中的结构体数据 Task<object?> ReadStructAsync(Type structType, int db, int startByteAdr = 0, CancellationToken cts = default) Parameters structType Type 结构体类型 db int 数据块编号 startByteAdr int 起始字节地址,默认为0 cts CancellationToken 取消令牌 Returns Task<object> 异步操作任务结果,读取的结构体数据,由调用方处理可能发生的异常 Remarks 这个方法适用于需要将PLC中的数据块映射到C#中的结构体 Exceptions OperationCanceledException 取消此操作时抛出此异常 ReadErrorException 读取异常 ReadStructAsync<T>(int, int, CancellationToken) 异步读取PLC中的结构体数据 Task<T?> ReadStructAsync<T>(int db, int startByteAdr = 0, CancellationToken cts = default) where T : struct Parameters db int 数据块编号 startByteAdr int 起始字节地址,默认为0 cts CancellationToken 取消令牌 Returns Task<T?> 异步操作任务结果,读取的结构体数据,由调用方处理可能发生的异常 Type Parameters T 结构体类型 Remarks 这个方法适用于需要将PLC中的数据块映射到C#中的结构体 Exceptions OperationCanceledException 取消此操作时抛出此异常 ReadErrorException 读取异常 WriteAsync(DataType, int, int, object, CancellationToken) 异步写入解码 Task WriteAsync(DataType dataType, int db, int startByteAdr, object value, CancellationToken cts = default) Parameters dataType DataType 数据类型 db int 数据块编号 startByteAdr int 起始字节地址 value object 要写入的数据对象,它可以是单个值或数组 cts CancellationToken 取消令牌 Returns Task 异步操作任务结果,由调用方处理可能发生的异常 Remarks 这个方法适用于需要根据特定的数据类型进行数据交换的场合,当需要写入特定类型的数据(整数、实数等)到PLC的数据块时,可以自动处理数据类型的转换 Exceptions OperationCanceledException 取消此操作时抛出此异常 WriteErrorException 读取异常 WriteBytesAsync(DataType, int, int, byte[], CancellationToken) 异步写入字数据到PLC Task WriteBytesAsync(DataType dataType, int db, int startByteAdr, byte[] value, CancellationToken cts = default) Parameters dataType DataType 数据类型 db int 数据块编号 startByteAdr int 起始字节地址 value byte[] 要写入的字节数组 cts CancellationToken 取消令牌 Returns Task 异步操作任务结果,由调用方处理可能发生的异常 Remarks 这个方法常用于低级别的数据写入操作,将字节数据直接写入PLC的指定数据块,设置PLC的配置参数或更新固件等 Exceptions OperationCanceledException 取消此操作时抛出此异常 WriteErrorException 写入异常 WriteClassAsync(object, int, int, CancellationToken) 异步将 C# 类的实例数据写入PLC Task WriteClassAsync(object classValue, int db, int startByteAdr = 0, CancellationToken cts = default) Parameters classValue object 包含数据的类的实例 db int 数据块编号 startByteAdr int 起始字节地址,默认为0 cts CancellationToken 取消令牌 Returns Task 异步操作任务结果,由调用方处理可能发生的异常 Remarks 这个方法适用于通过将C#类实例的数据写入到PLC,处理复杂的数据结构 Exceptions OperationCanceledException 取消此操作时抛出此异常 WriteErrorException 写入异常 WriteMultipleVarsAsync(List<DataItem>, CancellationToken) 异步向PLC写入多个变量 Task WriteMultipleVarsAsync(List<DataItem> dataItems, CancellationToken cts = default) Parameters dataItems List<DataItem> 包含要写入的所有数据项信息的列表 cts CancellationToken 取消令牌 Returns Task 异步操作任务结果,由调用方处理可能发生的异常 Remarks 这个方法适用于当需要在一个操作中写入多个不同的变量时使用,这些变量分布在不同的数据块或者地址,减少网络通信的次数 Exceptions WriteErrorException 写入异常 WriteStructAsync(object, int, int, CancellationToken) 异步向PLC写入结构体数据 Task WriteStructAsync(object structValue, int db, int startByteAdr = 0, CancellationToken cts = default) Parameters structValue object 要写入的结构体实例 db int 数据块编号 startByteAdr int 起始字节地址,默认为0 cts CancellationToken 取消令牌 Returns Task 异步操作任务结果,由调用方处理可能发生的异常 Remarks 这个方法适用于需要将C#中的结构体数据写入到PLC Exceptions OperationCanceledException 取消此操作时抛出此异常 WriteErrorException 写入异常 WriteStructAsync<T>(T, int, int, CancellationToken) 异步向PLC写入结构体数据 Task WriteStructAsync<T>(T structValue, int db, int startByteAdr = 0, CancellationToken cts = default) where T : struct Parameters structValue T 要写入的结构体实例 db int 数据块编号 startByteAdr int 起始字节地址,默认为0 cts CancellationToken 取消令牌 Returns Task 异步操作任务结果,由调用方处理可能发生的异常 Type Parameters T 结构体类型 Remarks 这个方法适用于需要将C#中的结构体数据写入到PLC Exceptions OperationCanceledException 取消此操作时抛出此异常 WriteErrorException 写入异常"
},
"api/MAS.Communication.S7Protocol.S7ProtocolHelper.html": {
"href": "api/MAS.Communication.S7Protocol.S7ProtocolHelper.html",
"title": "Class S7ProtocolHelper | MAS.Communication API Reference",
"summary": "Class S7ProtocolHelper Namespace MAS.Communication.S7Protocol Assembly MAS.Communication.dll Helper class for S7Protocols public static class S7ProtocolHelper Inheritance object S7ProtocolHelper Inherited Members object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Methods ParseCpuType(string) 将字符串解析为 CpuType 枚举 public static CpuType ParseCpuType(string cpuType) Parameters cpuType string CPU类型 Returns CpuType CpuType枚举 Exceptions PlcException CPU 不支持时抛出此异常"
},
"api/MAS.Communication.S7Protocol.html": {
"href": "api/MAS.Communication.S7Protocol.html",
"title": "Namespace MAS.Communication.S7Protocol | MAS.Communication API Reference",
"summary": "Namespace MAS.Communication.S7Protocol Classes S7ProtocolHelper Helper class for S7Protocols Interfaces IS7CommunicationConfig S7 通讯参数配置接口 IS7Protocol 与西门子 S7 设备进行通信的接口"
},
"api/MAS.Communication.ServiceCollectionExtensions.html": {
"href": "api/MAS.Communication.ServiceCollectionExtensions.html",
"title": "Class ServiceCollectionExtensions | MAS.Communication API Reference",
"summary": "Class ServiceCollectionExtensions Namespace MAS.Communication Assembly MAS.Communication.dll 提供扩展方法,用于在 IServiceCollection 中注册与通讯相关的服务 public static class ServiceCollectionExtensions Inheritance object ServiceCollectionExtensions Inherited Members object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Methods AddCommunication(IServiceCollection) 在指定的 IServiceCollection 中注册所有通讯相关的服务 public static IServiceCollection AddCommunication(this IServiceCollection services) Parameters services IServiceCollection 要添加服务的 IServiceCollection 实例 Returns IServiceCollection 已注册的服务集合"
},
"api/MAS.Communication.StructBinaryHelper.html": {
"href": "api/MAS.Communication.StructBinaryHelper.html",
"title": "Class StructBinaryHelper | MAS.Communication API Reference",
"summary": "Class StructBinaryHelper Namespace MAS.Communication Assembly MAS.Communication.dll 结构体与字节数组的通用编解码 public static class StructBinaryHelper Inheritance object StructBinaryHelper Inherited Members object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Methods BytesToStruct(byte[], Type) 将字节数组转换为结构体实例 public static object BytesToStruct(byte[] bytes, Type structType) Parameters bytes byte[] 源字节数组 structType Type 目标结构体类型 Returns object 结构体实例 BytesToStruct<T>(byte[]) 将字节数组转换为指定结构体类型的实例 public static T BytesToStruct<T>(byte[] bytes) where T : struct Parameters bytes byte[] 源字节数组 Returns T 结构体实例 Type Parameters T 结构体类型 CopyStructToBytes(object?, byte[], int, int) 将结构体复制到字节数组的指定区域(支持偏移和截断) public static void CopyStructToBytes(object? structValue, byte[] bytes, int offset, int size) Parameters structValue object 结构体实例,null 时清空目标区域 bytes byte[] 目标字节数组 offset int 起始偏移 size int 复制长度 GetBytes(object) 将值转换为字节数组 public static byte[] GetBytes(object value) Parameters value object 原始值 Returns byte[] 对应的字节数组 Exceptions NotSupportedException GetStructSize(Type) 获取结构体总大小 public static int GetStructSize(Type structType) Parameters structType Type 结构体类型 Returns int 所需字节数 GetTypeByteLength(Type) 获取基础类型的字节长度 public static int GetTypeByteLength(Type type) Parameters type Type 类型 Returns int 字节大小 Exceptions NotSupportedException GetValueFromBytes(byte[], Type, int) 从字节数组中提取指定类型的值 public static object GetValueFromBytes(byte[] bytes, Type targetType, int offset = 0) Parameters bytes byte[] 源字节数组 targetType Type 目标类型 offset int 起始偏移 Returns object 对应类型的值 Exceptions NotSupportedException StructToBytes(object) 将结构体实例序列化为字节数组 public static byte[] StructToBytes(object structValue) Parameters structValue object 结构体实例 Returns byte[] 字节数组"
},
"api/MAS.Communication.WriteErrorException.html": {
"href": "api/MAS.Communication.WriteErrorException.html",
"title": "Class WriteErrorException | MAS.Communication API Reference",
"summary": "Class WriteErrorException Namespace MAS.Communication Assembly MAS.Communication.dll 写数据错误异常 public class WriteErrorException : Exception, ISerializable Inheritance object Exception WriteErrorException Implements ISerializable Inherited Members Exception.GetBaseException() Exception.GetType() Exception.ToString() Exception.Data Exception.HelpLink Exception.HResult Exception.InnerException Exception.Message Exception.Source Exception.StackTrace Exception.TargetSite Exception.SerializeObjectState object.Equals(object) object.Equals(object, object) object.GetHashCode() object.MemberwiseClone() object.ReferenceEquals(object, object) Constructors WriteErrorException(string) 初始化 WriteErrorException 新实例 public WriteErrorException(string message) Parameters message string 异常消息 WriteErrorException(string, Exception) 初始化 WriteErrorException 新实例 public WriteErrorException(string message, Exception innerException) Parameters message string 异常消息 innerException Exception 内部异常"
},
"api/MAS.Communication.html": {
"href": "api/MAS.Communication.html",
"title": "Namespace MAS.Communication | MAS.Communication API Reference",
"summary": "Namespace MAS.Communication Classes CommunicationConfigExtensions 通讯配置扩展方法 ConnectionException 连接错误异常 FixedStringAttribute 固定长度字符串字段特性(按字节长度) ProtocolCreatedEventArgs 协议实例创建事件参数 ProtocolRemovedEventArgs 协议实例移除事件参数 ReadErrorException 读取数据错误异常 ServiceCollectionExtensions 提供扩展方法,用于在 IServiceCollection 中注册与通讯相关的服务 StructBinaryHelper 结构体与字节数组的通用编解码 WriteErrorException 写数据错误异常 Interfaces ICommunicationConfig 通讯协议的基本参数配置接口 IProtocol 所有通信协议的统一接口 IProtocolManager 通讯协议实例管理器接口 Enums CommProtocol 通讯协议枚举"
},
"content/MAS.Communication.McProtocol.html": {
"href": "content/MAS.Communication.McProtocol.html",
"title": "MAS.Communication.McProtocol | MAS.Communication API Reference",
"summary": "MAS.Communication.McProtocol 以下示例演示如何通过 IProtocolManager 获取 IMcProtocol 实例,并完成 MC 协议的常用读写操作 using MAS.Communication; using MAS.Communication.McProtocol; public sealed class MainViewModel { private readonly IProtocolManager _protocolManager; public MainViewModel(IProtocolManager protocolManager) { _protocolManager = protocolManager; } public async Task RunAsync() { // 1. 创建 MC 通信配置 IMcCommunicationConfig config = new McCommunicationConfig { Ip = \"192.168.0.10\", Port = 6000, ProtocolFrame = McFrame.MC3E }; // 2. 获取强类型协议实例 IMcProtocol protocol = _protocolManager.GetOrCreate<IMcProtocol>(config); // 3. 建立连接 await protocol.ConnectAsync(); // ========================= // 示例 1:读写字数据 // ========================= // 从 D100 开始读取 4 个字 short[] words = await protocol.ReadWordsAsync( deviceType: \"D\", startAddress: 100, length: 4); // 向 D100 开始写入 4 个字 await protocol.WriteWordsAsync( deviceType: \"D\", startAddress: 100, values: new short[] { 10, 20, 30, 40 }); // ========================= // 示例 2:读写位数据 // ========================= // 从 M100 开始读取 8 个位 bool[] bits = await protocol.ReadBitsAsync( deviceType: \"M\", startAddress: 100, length: 8); // 向 M100 开始写入 8 个位 await protocol.WriteBitsAsync( deviceType: \"M\", startAddress: 100, values: new bool[] { true, false, true, false, true, false, false, true }); } }"
},
"content/MAS.Communication.ModbusProtocol.html": {
"href": "content/MAS.Communication.ModbusProtocol.html",
"title": "MAS.Communication.ModbusProtocol | MAS.Communication API Reference",
"summary": "MAS.Communication.ModbusProtocol 以下示例演示如何通过 IProtocolManager 使用 Modbus TCP 协议完成连接、读取与写入操作 using MAS.Communication; using MAS.Communication.ModbusProtocol; public sealed class MainViewModel { private readonly IProtocolManager _protocolManager; public MainViewModel(IProtocolManager protocolManager) { _protocolManager = protocolManager; } public async Task RunAsync() { // 1. 创建 Modbus 通信配置 IModbusCommunicationConfig config = new ModbusCommunicationConfig { Ip = \"192.168.0.10\", Port = 502, UnitId = 1, // 地址是否按 1 开始 UseOneBasedAddress = false, // 根据设备实际字节序配置 ByteOrder = EndianType.BigEndian, WordOrder = WordOrderType.HighLow, // 超时时间(毫秒) ReadTimeout = 3000, WriteTimeout = 3000 }; // 2. 获取强类型协议实例 IModbusProtocol protocol = _protocolManager.GetOrCreate<IModbusProtocol>(config); // 3. 建立连接 await protocol.ConnectAsync(); // ========================= // 示例 1:读写保持寄存器 // ========================= // 从保持寄存器地址 0 开始读取 4 个寄存器 ushort[] registers = await protocol.ReadRegistersAsync( ModbusDataArea.HoldingRegisters, startAddress: 0, count: 4); // 向保持寄存器地址 0 开始写入 4 个寄存器 await protocol.WriteRegistersAsync( startAddress: 0, values: new ushort[] { 100, 200, 300, 400 }); // ========================= // 示例 2:读写线圈 // ========================= // 从线圈地址 0 开始读取 8 个布尔量 bool[] coils = await protocol.ReadBitsAsync( ModbusDataArea.Coils, startAddress: 0, count: 8); // 向线圈地址 0 开始写入布尔量 await protocol.WriteBitsAsync( startAddress: 0, values: new bool[] { true, false, true, false }); } }"
},
"content/MAS.Communication.S7Protocol.html": {
"href": "content/MAS.Communication.S7Protocol.html",
"title": "MAS.Communication.S7Protocol | MAS.Communication API Reference",
"summary": "MAS.Communication.S7Protocol 以下示例演示如何通过 IProtocolManager 获取 IS7Protocol 实例,并完成 S7 协议的常用读写操作 using MAS.Communication; using MAS.Communication.S7Protocol; using S7.Net; using S7.Net.Types; using System.Runtime.InteropServices; [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct ProductData { public short ProductId; public short Result; public int Count; } public sealed class MainViewModel { private readonly IProtocolManager _protocolManager; public MainViewModel(IProtocolManager protocolManager) { _protocolManager = protocolManager; } public async Task RunAsync() { // 1. 创建 S7 通信配置 IS7CommunicationConfig config = new S7CommunicationConfig { Ip = \"192.168.0.10\", Type = \"S1200\", Rack = 0, Slot = 1 }; // 2. 获取强类型协议实例 IS7Protocol protocol = _protocolManager.GetOrCreate<IS7Protocol>(config); // 3. 建立连接 await protocol.ConnectAsync(); // ========================= // 示例 1:普通变量读写 // ========================= // 从 DB1.DBW0 读取 1 个 Word object? readValue = await protocol.ReadAsync( dataType: DataType.DataBlock, db: 1, startByteAdr: 0, varType: VarType.Word, varCount: 1); // 向 DB1.DBW0 写入一个 Word 值 await protocol.WriteAsync( dataType: DataType.DataBlock, db: 1, startByteAdr: 0, value: (ushort)123); // ========================= // 示例 2:结构体读写 // ========================= // 从 DB10 起始地址 0 读取结构体 ProductData? product = await protocol.ReadStructAsync<ProductData>( db: 10, startByteAdr: 0); // 向 DB10 起始地址 0 写入结构体 await protocol.WriteStructAsync( structValue: new ProductData { ProductId = 1001, Result = 1, Count = 25 }, db: 10, startByteAdr: 0); } }"
},
"index.html": {
"href": "index.html",
"title": "MAS.Communication | MAS.Communication API Reference",
"summary": "面向工业自动化的统一通信框架 基于依赖注入(DI)使用,提供协议实例管理、连接复用与统一读写入口 ⚠️ 使用前提 在使用本项目之前,请确认你的应用满足以下条件: 目标框架支持 net10.0、net9.0、net8.0 或 net481 使用 Microsoft.Extensions.DependencyInjection 进行服务注册与解析 适合在 WPF、WinForms、WinUI、Worker、ASP.NET Core 等应用中集成 \uD83D\uDE80 快速开始 注册服务 在应用启动阶段注册通信服务: using Microsoft.Extensions.DependencyInjection; using MAS.Communication; IServiceCollection services = new ServiceCollection(); services.AddCommunication(); 通信配置 在使用具体协议前,需要先提供对应的通信配置对象。框架为不同协议提供了统一配置接口: 协议 配置接口 MC(Mitsubishi) IMcCommunicationConfig ModbusTCP IModbusCommunicationConfig S7(Siemens) IS7CommunicationConfig 以上接口均继承自 ICommunicationConfig,调用方需继承并实现它 使用方式 通信框架通过IProtocolManager提供统一入口,推荐通过依赖注入方式获取并使用: public class MainViewModel { private readonly IProtocolManager _protocolManager; public MainViewModel(IProtocolManager protocolManager) { _protocolManager = protocolManager; } public async Task RunAsync() { // 创建配置(示例:Modbus) IModbusCommunicationConfig config = new ModbusCommunicationConfig { // 填写你的实际配置 // 例如:Ip、Port、StationNumber 等 }; // 获取或创建协议实例 IProtocol protocol = _protocolManager.GetOrCreate(config); // 建立连接 await protocol.ConnectAsync(); // 示例:执行读写(具体方法见 API 文档) // await protocol.ReadAsync(...); // await protocol.WriteAsync(...); } } 所有协议实例生命周期由IProtocolManager统一管理 相同配置会自动复用已有连接实例(基于配置唯一标识) 支持创建多个不同配置的协议实例(例如多个 PLC) 当不再需要使用某个实例时,请调用IProtocolManager.Remove(IProtocol)或IProtocol.Dispose()方法释放资源 不建议多个线程高并发共享一个实例做高频通信,虽然目前来说它们都是暂时安全的"
}
}