{"id":11720,"date":"2023-02-12T10:36:18","date_gmt":"2023-02-12T02:36:18","guid":{"rendered":"https:\/\/www.modbus.cn\/?p=11720"},"modified":"2023-02-12T11:09:20","modified_gmt":"2023-02-12T03:09:20","slug":"ji-yu-easymodbustcp-udp-rtu-java-shi-li-dai-ma","status":"publish","type":"post","link":"https:\/\/www.modbus.cn\/en\/11720.html","title":{"rendered":"\u57fa\u4e8eEasyModbusTCP\/UDP\/RTU JAVA\u670d\u52a1\u7aef\u793a\u4f8b\u4ee3\u7801"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;TrpContentRestriction&quot;:{&quot;restriction_type&quot;:&quot;exclude&quot;,&quot;selected_languages&quot;:[],&quot;panel_open&quot;:true},&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">&lt;span class=&quot;n&quot;&gt;package&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;run&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;\/span&gt;\n&lt;span class=&quot;kn&quot;&gt;import&lt;\/span&gt; &lt;span class=&quot;nn&quot;&gt;de.re.easymodbus.server.&lt;\/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;\/span&gt;\n\n&lt;span class=&quot;n&quot;&gt;public&lt;\/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;\/span&gt; &lt;span class=&quot;nc&quot;&gt;run&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;\/span&gt;\n    &lt;span class=&quot;n&quot;&gt;public&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;static&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;void&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;\/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;\/span&gt;\n    &lt;span class=&quot;p&quot;&gt;{&lt;\/span&gt;\n        &lt;span class=&quot;n&quot;&gt;ModbusServer&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;modbusServer&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;new&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;ModbusServer&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;\/span&gt;\n        &lt;span class=&quot;n&quot;&gt;modbusServer&lt;\/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;\/span&gt;&lt;span class=&quot;n&quot;&gt;setPort&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;\/span&gt;&lt;span class=&quot;mi&quot;&gt;1522&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;\/span&gt;&lt;span class=&quot;o&quot;&gt;\/\/&lt;\/span&gt;&lt;span class=&quot;n&quot;&gt;Note&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;that&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;Standard&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;Port&lt;\/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;Modbus&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;TCP&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;communication&lt;\/span&gt; &lt;span class=&quot;ow&quot;&gt;is&lt;\/span&gt; &lt;span class=&quot;mi&quot;&gt;502&lt;\/span&gt;\n        &lt;span class=&quot;n&quot;&gt;modbusServer&lt;\/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;\/span&gt;&lt;span class=&quot;n&quot;&gt;coils&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;\/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;true&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;\/span&gt;\n        &lt;span class=&quot;n&quot;&gt;modbusServer&lt;\/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;\/span&gt;&lt;span class=&quot;n&quot;&gt;holdingRegisters&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;\/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;mi&quot;&gt;1234&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;\/span&gt;\n        &lt;span class=&quot;k&quot;&gt;try&lt;\/span&gt;\n        &lt;span class=&quot;p&quot;&gt;{&lt;\/span&gt;\n            &lt;span class=&quot;n&quot;&gt;modbusServer&lt;\/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;\/span&gt;&lt;span class=&quot;n&quot;&gt;Listen&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;\/span&gt;\n        &lt;span class=&quot;p&quot;&gt;}&lt;\/span&gt;\n        &lt;span class=&quot;n&quot;&gt;catch&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;\/span&gt;&lt;span class=&quot;n&quot;&gt;java&lt;\/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;\/span&gt;&lt;span class=&quot;n&quot;&gt;io&lt;\/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;\/span&gt;&lt;span class=&quot;n&quot;&gt;IOException&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;Exceptions&lt;\/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;\/span&gt;&lt;span class=&quot;n&quot;&gt;ModbusException&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;\/span&gt;\n        &lt;span class=&quot;p&quot;&gt;{&lt;\/span&gt;           \n        &lt;span class=&quot;p&quot;&gt;}&lt;\/span&gt;\n    &lt;span class=&quot;p&quot;&gt;}&lt;\/span&gt;\n&lt;span class=&quot;p&quot;&gt;}&lt;\/span&gt;<\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">JAVA\u5e93\u6587\u4ef6\u5728\u672c\u9875\u4e0b\u8f7d<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;TrpContentRestriction&quot;:{&quot;restriction_type&quot;:&quot;exclude&quot;,&quot;selected_languages&quot;:[],&quot;panel_open&quot;:true},&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">&lt;span class=&quot;n&quot;&gt;package&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;run&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;\/span&gt;\n&lt;span class=&quot;kn&quot;&gt;import&lt;\/span&gt; &lt;span class=&quot;nn&quot;&gt;de.re.easymodbus.server.&lt;\/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;\/span&gt;\n\n&lt;span class=&quot;n&quot;&gt;public&lt;\/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;\/span&gt; &lt;span class=&quot;nc&quot;&gt;run&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;\/span&gt;\n    &lt;span class=&quot;n&quot;&gt;public&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;static&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;void&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;\/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;\/span&gt;\n    &lt;span class=&quot;p&quot;&gt;{&lt;\/span&gt;\n        &lt;span class=&quot;n&quot;&gt;ModbusServer&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;modbusServer&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;new&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;ModbusServer&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;\/span&gt;\n        &lt;span class=&quot;n&quot;&gt;modbusServer&lt;\/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;\/span&gt;&lt;span class=&quot;n&quot;&gt;setPort&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;\/span&gt;&lt;span class=&quot;mi&quot;&gt;1522&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;\/span&gt;&lt;span class=&quot;o&quot;&gt;\/\/&lt;\/span&gt;&lt;span class=&quot;n&quot;&gt;Note&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;that&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;Standard&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;Port&lt;\/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;Modbus&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;TCP&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;communication&lt;\/span&gt; &lt;span class=&quot;ow&quot;&gt;is&lt;\/span&gt; &lt;span class=&quot;mi&quot;&gt;502&lt;\/span&gt;\n        &lt;span class=&quot;n&quot;&gt;modbusServer&lt;\/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;\/span&gt;&lt;span class=&quot;n&quot;&gt;coils&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;\/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;true&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;\/span&gt;\n        &lt;span class=&quot;n&quot;&gt;modbusServer&lt;\/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;\/span&gt;&lt;span class=&quot;n&quot;&gt;holdingRegisters&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;\/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;mi&quot;&gt;1234&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;\/span&gt;\n        &lt;span class=&quot;k&quot;&gt;try&lt;\/span&gt;\n        &lt;span class=&quot;p&quot;&gt;{&lt;\/span&gt;\n            &lt;span class=&quot;n&quot;&gt;modbusServer&lt;\/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;\/span&gt;&lt;span class=&quot;n&quot;&gt;Listen&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;\/span&gt;\n        &lt;span class=&quot;p&quot;&gt;}&lt;\/span&gt;\n        &lt;span class=&quot;n&quot;&gt;catch&lt;\/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;\/span&gt;&lt;span class=&quot;n&quot;&gt;java&lt;\/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;\/span&gt;&lt;span class=&quot;n&quot;&gt;io&lt;\/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;\/span&gt;&lt;span class=&quot;n&quot;&gt;IOException&lt;\/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;Exceptions&lt;\/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;\/span&gt;&lt;span class=&quot;n&quot;&gt;ModbusException&lt;\/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;\/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;\/span&gt;\n        &lt;span class=&quot;p&quot;&gt;{&lt;\/span&gt;           \n        &lt;span class=&quot;p&quot;&gt;}&lt;\/span&gt;\n    &lt;span class=&quot;p&quot;&gt;}&lt;\/span&gt;\n&lt;span class=&quot;p&quot;&gt;}&lt;\/span&gt;<\/pre><\/div>\n<span id=\"magicpostMarker\"><\/span>","protected":false},"excerpt":{"rendered":"<p>\u793a\u4f8b\u4ee3\u7801\uff1a JAVA\u5e93\u6587\u4ef6\u5728\u672c\u9875\u4e0b\u8f7d<\/p>","protected":false},"author":1,"featured_media":27977,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_members_access_role":[],"_members_access_error":""},"categories":[691],"tags":[1426,1462,1464,1461,1463,65],"class_list":["post-11720","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-modbus-code-base","tag-lt","tag-n","tag-p","tag-span-class","tag-span-lt","tag-65"],"_links":{"self":[{"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/posts\/11720","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/comments?post=11720"}],"version-history":[{"count":0,"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/posts\/11720\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/media\/27977"}],"wp:attachment":[{"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/media?parent=11720"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/categories?post=11720"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modbus.cn\/en\/wp-json\/wp\/v2\/tags?post=11720"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}