{"id":19992056,"url":"https://github.com/dathlin/SharpNodeSettings","last_synced_at":"2025-05-04T11:30:41.521Z","repository":{"id":50364219,"uuid":"143443236","full_name":"dathlin/SharpNodeSettings","owner":"dathlin","description":"一个设备及节点配置类库，基于HslCommunication.dll创建，方便的实现PLC根据配置文件动态创建，并支持自动写入相应的服务器对象。","archived":false,"fork":false,"pushed_at":"2019-03-07T13:36:38.000Z","size":5352,"stargazers_count":261,"open_issues_count":3,"forks_count":148,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-04-27T03:26:36.144Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dathlin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-03T15:21:23.000Z","updated_at":"2025-04-09T01:20:07.000Z","dependencies_parsed_at":"2022-09-09T16:01:32.609Z","dependency_job_id":null,"html_url":"https://github.com/dathlin/SharpNodeSettings","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dathlin%2FSharpNodeSettings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dathlin%2FSharpNodeSettings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dathlin%2FSharpNodeSettings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dathlin%2FSharpNodeSettings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dathlin","download_url":"https://codeload.github.com/dathlin/SharpNodeSettings/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252329105,"owners_count":21730549,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T04:52:01.523Z","updated_at":"2025-05-04T11:30:36.506Z","avatar_url":"https://github.com/dathlin.png","language":"C#","funding_links":[],"categories":["C\\#"],"sub_categories":[],"readme":"# SharpNodeSettings\n\n![Build status](https://img.shields.io/badge/Build-Success-green.svg) [![NuGet Status](https://img.shields.io/nuget/v/SharpNodeSettings.svg)](https://www.nuget.org/packages/SharpNodeSettings/) ![NuGet Download](https://img.shields.io/nuget/dt/SharpNodeSettings.svg) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](http://shang.qq.com/wpa/qunwpa?idkey=2278cb9c2e0c04fc305c43e41acff940499a34007dfca9e83a7291e726f9c4e8) [![NetFramework](https://img.shields.io/badge/Language-C%23%207.0-orange.svg)](https://blogs.msdn.microsoft.com/dotnet/2016/08/24/whats-new-in-csharp-7-0/) [![Visual Studio](https://img.shields.io/badge/Visual%20Studio-2017-red.svg)](https://www.visualstudio.com/zh-hans/) ![License status](https://img.shields.io/badge/License-LGPL3.0-yellow.svg) ![copyright status](https://img.shields.io/badge/CopyRight-Richard.Hu-brightgreen.svg) \n\n一个设备及节点配置类库，基于 [HslCommunication.dll](https://github.com/dathlin/HslCommunication) 深度整合创建，用来实现对PLC配置信息的存储和加载解析，同时支持可配置化的PLC数据读取，支持数据显示，其中服务器示例如下：\n* **SampleServer** 简单的演示了如何启动一个服务器程序，虽然示例是基于 **Console** 的应用程序，你也可以实现 **Winform** 或是 **Wpf** 应用程序，\n* **RedisServer** 演示了如果创建一个服务器，并且将读取到数据存入Redis的服务器，详细参照下文的说明。\n* **OpcUaServer** 由于OPC UA在工控界相当火爆，所以此处也集成了这个示例，采用最新的1.4.354.0版本的库实现，主要麻烦的地方在于数据解析，并创建节点，具体参照下文的说明。\n\n```\nInstall-Package SharpNodeSettings\n```\n\n## How to use\n包括服务器和客户端都是围绕配置的Xml文件创建的，示例的Xml文件内容如下：\n```\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cSettings\u003e\n  \u003cNodeClass Name=\"Devices\" Description=\"所有的设备的集合对象\"\u003e\n    \u003cNodeClass Name=\"分厂一\" Description=\"\"\u003e\n      \u003cNodeClass Name=\"车间一\" Description=\"\"\u003e\n        \u003cDeviceNode Name=\"测试空设备\" Description=\"此设备安装在角落，编号0001\" DeviceType=\"0\" ConnectTimeOut=\"2000\" CreateTime=\"2018/8/12 9:26:27\" InstallationDate=\"2018/8/12 9:26:27\"\u003e\n          \u003cDeviceRequest Name=\"数据请求\" Description=\"一次完整的数据请求\" Address=\"0\" Length=\"10\" CaptureInterval=\"1000\" PraseRegularCode=\"B\" /\u003e\n        \u003c/DeviceNode\u003e\n      \u003c/NodeClass\u003e\n      \u003cNodeClass Name=\"车间二\" Description=\"\"\u003e\n        \u003cDeviceNode Name=\"ModbusTcp客户端\" Description=\"这是描述\" DeviceType=\"10\" ConnectTimeOut=\"1000\" CreateTime=\"2018/8/9 19:58:49\" InstallationDate=\"2018/8/9 19:58:49\" IpAddress=\"127.0.0.1\" Port=\"502\" Station=\"1\" IsAddressStartWithZero=\"true\" IsWordReverse=\"false\" IsStringReverse=\"false\"\u003e\n          \u003cDeviceRequest Name=\"数据请求\" Description=\"一次完整的数据请求\" Address=\"0\" Length=\"30\" CaptureInterval=\"1000\" PraseRegularCode=\"ABCD\" /\u003e\n        \u003c/DeviceNode\u003e\n      \u003c/NodeClass\u003e\n    \u003c/NodeClass\u003e\n    \u003cNodeClass Name=\"分厂二\" Description=\"位于西南方\"\u003e\n      \u003cNodeClass Name=\"车间三\" Description=\"\"\u003e\n        \u003cDeviceNode Name=\"测试设备二\" Description=\"这是测试设备二的描述\" DeviceType=\"10\" ConnectTimeOut=\"1000\" CreateTime=\"2018/8/10 23:01:28\" InstallationDate=\"2018/8/10 23:01:28\" IpAddress=\"127.0.0.1\" Port=\"502\" Station=\"1\" IsAddressStartWithZero=\"true\" IsWordReverse=\"false\" IsStringReverse=\"false\"\u003e\n          \u003cDeviceRequest Name=\"数据请求\" Description=\"一次完整的数据请求\" Address=\"100\" Length=\"10\" CaptureInterval=\"500\" PraseRegularCode=\"B\" /\u003e\n        \u003c/DeviceNode\u003e\n      \u003c/NodeClass\u003e\n    \u003c/NodeClass\u003e\n  \u003c/NodeClass\u003e\n  \u003cNodeClass Name=\"Server\" Description=\"所有挂载的服务器\"\u003e\n    \u003cServerNode Name=\"异形服务器\" Description=\"这是一个异形服务器\" CreateTime=\"2018/8/8 13:29:30\" Port=\"1234\" ServerType=\"2\" Password=\"\" /\u003e\n  \u003c/NodeClass\u003e\n  \u003cNodeClass Name=\"Regular\" Description=\"所有的解析规则的信息\"\u003e\n    \u003cRegularNode Name=\"ABCD\" Description=\"\"\u003e\n      \u003cRegularItemNode Name=\"温度\" Description=\"\" Index=\"0\" TypeCode=\"3\" TypeLength=\"1\" /\u003e\n      \u003cRegularItemNode Name=\"风俗\" Description=\"\" Index=\"2\" TypeCode=\"9\" TypeLength=\"1\" /\u003e\n      \u003cRegularItemNode Name=\"转速\" Description=\"\" Index=\"14\" TypeCode=\"9\" TypeLength=\"1\" /\u003e\n      \u003cRegularItemNode Name=\"机器人关节\" Description=\"\" Index=\"18\" TypeCode=\"9\" TypeLength=\"6\" /\u003e\n      \u003cRegularItemNode Name=\"cvsdf\" Description=\"\" Index=\"42\" TypeCode=\"9\" TypeLength=\"1\" /\u003e\n      \u003cRegularItemNode Name=\"条码\" Description=\"条码信息\" Index=\"6\" TypeCode=\"11\" TypeLength=\"8\" /\u003e\n      \u003cRegularItemNode Name=\"开关量\" Description=\"设备的开关量信息\" Index=\"368\" TypeCode=\"1\" TypeLength=\"8\" /\u003e\n    \u003c/RegularNode\u003e\n    \u003cRegularNode Name=\"B\" Description=\"\"\u003e\n      \u003cRegularItemNode Name=\"温度\" Description=\"\" Index=\"0\" TypeCode=\"3\" TypeLength=\"1\" /\u003e\n      \u003cRegularItemNode Name=\"压力\" Description=\"\" Index=\"2\" TypeCode=\"3\" TypeLength=\"1\" /\u003e\n    \u003c/RegularNode\u003e\n  \u003c/NodeClass\u003e\n\u003c/Settings\u003e\n```\n只要创建好这个xml文件，就可以调用 **SharpNodeServer** 来创建服务器应用了，可以生成相应的节点信息，并且根据配置信息来请求设备，更新对应的数据。创建服务器的代码如下：\n```\nSharpNodeServer sharpNodeServer = new SharpNodeServer( );\nsharpNodeServer.LoadByXmlFile( \"settings.xml\" );\nsharpNodeServer.ServerStart( 12345 );\n```\n\n这样就启动了一个最简单的服务器，主要包含实例化，加载配置，启动服务器，注意：加载配置必须放置到服务器启动之前。\n\n\n怎样查看服务器的数据呢？内置了一个默认的 **SimplifyNet** 服务器，想要知道更多的这个服务器的内容，可以参照下面的博客：[https://www.cnblogs.com/dathlin/p/7697782.html](https://www.cnblogs.com/dathlin/p/7697782.html)\n\n基于 **NetSimplifyClient** 实现了一个通用的数据节点查看器，需要指定服务器的Ip地址和端口号：\n```\n SharpNodeSettings.View.FormNodeView form = new SharpNodeSettings.View.FormNodeView( \"127.0.0.1\",12345 )\n form.ShowDialog();\n```\n![Picture](https://raw.githubusercontent.com/dathlin/SharpNodeSettings/master/Imgs/NodeView.png)\n\n如果你想实现访问单个的数据，可以使用 **NetSimplifyClient** 创建的Demo来访问，需要注意的是，此处请求的数据都是序列化的JSON字符串。\n![Picture](https://raw.githubusercontent.com/dathlin/SharpNodeSettings/master/Imgs/SimplifyView.png)\n\n手动配置这样一张表的内容将是灾难性的，所以本库提供了一个可视化的界面配置，代码如下：\n```\nForm nodeSettings = new SharpNodeSettings.View.FormNodeSetting( \"settings.xml\" )\nnodeSettings.ShowDialog();\n```\n上面的代码的意思是显示一个配置创建，配置文件的路径是当前目录下的 **settings.xml** 文件。\n\n您也可以这么写，手动获取用户配置过的数据信息，这样可以实现远程的配置信息：\n```\nusing(SharpNodeSettings.View.FormNodeSetting form = new SharpNodeSettings.View.FormNodeSetting( XElement.Load( \"settings.xml\" ) ))\n{\n    if (form.ShowDialog( ) == DialogResult.OK)\n    {\n        // 配置好的数据信息，在这种方式下可以实现远程配置的操作。\n        XElement xElement = form.XmlSettings;\n        MessageBox.Show( \"success\" );\n    }\n    else\n    {\n        MessageBox.Show( \"failed\" );\n    }\n}\n```\n界面效果如下：\n![Picture](https://raw.githubusercontent.com/dathlin/SharpNodeSettings/master/Imgs/NodeSettings.png)\n\n在实际开发中，可能你不需要上述的配置功能，你就想实现某个PLC的设备信息是可配置的，那么也可以通过本组件实现：\n```\nSharpNodeSettings.View.FormSelectDevice selectDevice = new View.FormSelectDevice( );\nif (selectDevice.ShowDialog( ) == DialogResult.OK)\n{\n    XElement xmlDevice = selectDevice.DeviceXml;\n    // 设备的配置对象可用于存储，网络传输等等操作\n\n\n    // 如果想要通过xml信息创建设备\n    SharpNodeSettings.Device.DeviceCore deviceCore = SharpNodeSettings.Util.CreateFromXElement( xmlDevice );\n    // 演示读取数据，此处有个问题在于如果是相同种类的PLC，应用还是很方便的，如果是不同种类的，地址模型就比较麻烦。\n    HslCommunication.OperateResult\u003cshort\u003e read = deviceCore.ReadWriteDevice.ReadInt16( \"D100\" );\n}\n```\n\n## Quick Start\n按照如下的步骤走，就可以急速体验本项目所传达的核心功能价值，就可以明白本项目是否符合您的需求。启动测试之前，你需要准备个真实的设备：\n* 西门子PLC\n* 三菱PLC\n* 欧姆龙PLC\n* ModbusTcp设备\n\n如果您没有真实的设备，也可以从网上下载个Modbus服务器软件，这里也提供一个下载地址：[ModbusTcpServer.zip](https://github.com/dathlin/HslCommunication/raw/master/Download/ModbusTcpServer.zip)\n\n下载完成后启动服务器即可。\n\n### 配置Xml信息\n去本项目的目录下配置设备的信息: \\SharpNodeSettings\\XmlFile  运行 SharpNodeSettings.Tools.exe 进行配置，已经配置了一部分，如果想要快速开始，忽略本步骤也可以。\n\n### SampleServer\n本示例直接重新生成 **SampleServer** 项目，启动程序即可。如果想要看实际的数据信息，启动 **SharpNodeSettings.NodeView** 项目查看\n![Picture](https://raw.githubusercontent.com/dathlin/SharpNodeSettings/master/Imgs/SampleServer.png)\n\n### RedisServer\n本示例是在 **SampleServer** 的基础上添加了Redis服务器，所以需要先安装好Redis服务器，windows版本下载地址：\n[https://github.com/MicrosoftArchive/redis/releases](https://github.com/MicrosoftArchive/redis/releases)\n\n当然，最好再下载安装一个redis服务器的可视化工具，此处推荐 **RedisDesktopManager**\n[https://github.com/uglide/RedisDesktopManager/releases](https://github.com/uglide/RedisDesktopManager/releases)\n\n然后基于本项目，重新生成 **SharpNodeSettings.RedisServer** 项目，启动服务器\n\n上述的 **SharpNodeSettings.NodeView** 项目依然可以查看，然后下图演示Redis\n![Picture](https://raw.githubusercontent.com/dathlin/SharpNodeSettings/master/Imgs/RedisServer.png)\n\n\n### OpcUaServer\n本示例是演示从PLC采集数据并且写入到OPC UA服务器中的示例，重新生成 **SharpNodeSettings.OpcUaServer** 项目，启动它，如果显示是否增加信任证书时，选择是即可。\n\n然后再启动一个 OPC UA Client的示例项目\n![Picture](https://raw.githubusercontent.com/dathlin/SharpNodeSettings/master/Imgs/OpcUaServer.png)\n\n\n## License\n* OpcUa相关的组件的版权归 OPC 基金会所有，使用请遵循相关的协议\n* **SharpNodeSettings** 组件协议 LGPL3.0 商用需要向作者打赏，金额需要 50 RMB - 100 RMB\n* 示例项目（SampleServer,RedisServer,OpcUaServer,Tools）协议为MIT协议\n\n## Support\n![打赏](https://raw.githubusercontent.com/dathlin/HslCommunication/master/imgs/support.png)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdathlin%2FSharpNodeSettings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdathlin%2FSharpNodeSettings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdathlin%2FSharpNodeSettings/lists"}