A:调整西门子PLC数据解析方式
This commit is contained in:
1 parent
30451cabbd
commit
2943485a2a
3 files changed
+20
-33
No files matched your search
@@ -55,7 +55,11 @@ public class ServiceChangedEventArgs<T> : EventArgs
|
||||
/// - 生命周期管理(Singleton/Transient)
|
||||
/// - 服务变更通知机制
|
||||
/// - 支持工厂方法注册
|
||||
///
|
||||
/// ⚠️ 注意:此类已标记为非首选使用,建议新项目使用 Microsoft.Extensions.DependencyInjection。
|
||||
/// 此类仅用于向后兼容和快速原型开发。
|
||||
/// </remarks>
|
||||
[Obsolete("不推荐使用Global容器。建议使用Microsoft.Extensions.DependencyInjection作为首选DI方案。此类保留用于向后兼容和快速原型开发。", false)]
|
||||
public static class Global
|
||||
{
|
||||
private class ServiceDescriptor
|
||||
|
||||
@@ -675,36 +675,3 @@ public class SecurePlcService : IPlcService
|
||||
- ✅ 自动重连
|
||||
|
||||
---
|
||||
|
||||
## 🤝 贡献
|
||||
|
||||
欢迎为西门子驱动贡献代码!
|
||||
|
||||
### 开发环境要求
|
||||
|
||||
- .NET 8.0 SDK
|
||||
- TIA Portal (用于测试)
|
||||
- 西门子PLC或PLCSim Advanced
|
||||
|
||||
### 测试清单
|
||||
|
||||
- [ ] 连接测试(真实PLC)
|
||||
- [ ] 地址解析测试(所有格式)
|
||||
- [ ] 数据类型测试(所有类型)
|
||||
- [ ] 批量优化测试
|
||||
- [ ] 性能测试
|
||||
- [ ] 错误处理测试
|
||||
|
||||
---
|
||||
|
||||
## 📄 许可证
|
||||
|
||||
MIT License - 详见 [LICENSE](../LICENSE) 文件
|
||||
|
||||
---
|
||||
|
||||
## 📞 技术支持
|
||||
|
||||
- 问题反馈: [GitHub Issues](https://github.com/yourcompany/plc/issues)
|
||||
- 西门子论坛: [Siemens Industry Online Support](https://support.industry.siemens.com/)
|
||||
- S7.Net Plus: [S7NetPlus Issues](https://github.com/S7NetPlus/s7netplus/issues)
|
||||
@@ -23,10 +23,26 @@ public static class SiemensAddressParser
|
||||
// Q匹配: Q0.0, QB0, QW0, QD0
|
||||
private static readonly Regex QRegex = new(@"^Q[B|W|D|X]?(\d+)(\.(\d+))?$", RegexOptions.IgnoreCase);
|
||||
|
||||
// V区域匹配: V100, V100.0 (S7-200 Smart特定,映射到DB1)
|
||||
private static readonly Regex VRegex = new(@"^V(\d+)(\.(\d+))?$", RegexOptions.IgnoreCase);
|
||||
|
||||
public static SiemensAddress Parse(string address)
|
||||
{
|
||||
address = address.Trim().ToUpper();
|
||||
|
||||
// 0. Try V Area (S7-200 Smart: V100 -> DB1.DBB100)
|
||||
var vMatch = VRegex.Match(address);
|
||||
if (vMatch.Success)
|
||||
{
|
||||
return new SiemensAddress
|
||||
{
|
||||
Area = SiemensMemoryArea.DataBlock,
|
||||
DbNumber = 1, // V区域映射到DB1
|
||||
ByteOffset = int.Parse(vMatch.Groups[1].Value),
|
||||
BitOffset = vMatch.Groups[3].Success ? int.Parse(vMatch.Groups[3].Value) : 0
|
||||
};
|
||||
}
|
||||
|
||||
// 1. Try DB
|
||||
var dbMatch = DbRegex.Match(address);
|
||||
if (dbMatch.Success)
|
||||
|
||||
Reference in new issue
Block a user