{"id":171,"date":"2021-07-14T14:07:51","date_gmt":"2021-07-14T06:07:51","guid":{"rendered":"https:\/\/www.346pro.club\/?p=171"},"modified":"2021-07-14T14:07:53","modified_gmt":"2021-07-14T06:07:53","slug":"%e5%88%a9%e7%94%a8qt-c%e4%b8%b2%e5%8f%a3%e9%80%9a%e8%ae%af%e5%8d%8f%e8%ae%ae%e4%b8%8e%e4%b8%89%e8%8f%b1plc%e4%ba%92%e9%80%9a","status":"publish","type":"post","link":"https:\/\/www.346pro.club\/?p=171","title":{"rendered":"\u5229\u7528Qt\/C++\u4e32\u53e3\u901a\u8baf\u534f\u8bae\u4e0e\u4e09\u83f1PLC\u4e92\u901a"},"content":{"rendered":"\n<p>\u56e0\u5de5\u4f5c\u9700\u8981\uff0c\u7814\u7a76\u4e86\u4e00\u4e0b\u4e09\u83f1\u7684PLC\u901a\u4fe1\u534f\u8bae\uff0c\u5728\u8fd9\u91cc\u8bb0\u4e00\u4e0b\u4ee5\u9632\u81ea\u5df1\u5fd8\u8bb0<\/p>\n\n\n\n<p>\u4e09\u83f1PLC\u4e0d\u505a\u8fc7\u591a\u4ecb\u7ecd\uff0c\u5176\u901a\u8fc7\u4e00\u4e2aCH340 USBtoSerial\u82af\u7247\u8fde\u63a5\u5230\u4e0a\u4f4d\u673a\uff0cCH340\u5728win10\u53ef\u80fd\u9700\u8981\u4e0b\u8f7d\u9a71\u52a8\uff0c\u5728Jetson Ubuntu 18.04\u4e0a\u514d\u9a71\u6d4b\u8bd5\u901a\u8fc7\u3002<\/p>\n\n\n\n<p>\u9996\u5148\uff0c\u662f\u4e32\u53e3\u901a\u8baf\u534f\u8bae\uff0c\u6211\u7528\u4e86\u4e00\u4e2aQSerialPort\u7c7b\u6765\u5b9a\u4e49\u8fd9\u4e2a\u4e32\u53e3\uff0c\u6839\u636e\u4e09\u83f1\u6587\u6863\u7684PLC\u901a\u8baf\u534f\u8bae\u53ef\u5f97<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">QSerialPort* mySerialPort;<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"685\" height=\"999\" src=\"https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/1377717-20181217155520959-1624194723.png\" alt=\"\" class=\"wp-image-172\" srcset=\"https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/1377717-20181217155520959-1624194723.png 685w, https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/1377717-20181217155520959-1624194723-206x300.png 206w\" sizes=\"auto, (max-width: 685px) 100vw, 685px\" \/><\/figure>\n\n\n\n<p>\u901a\u8baf\u901f\u7387\u56fa\u5b9a\u4e3aBaud9600\uff0c1\u8d77\u59cb\u4f4d-7\u6570\u636e\u4f4d-\u5076\u6781\u6027-1\u505c\u6b62\u4f4d\uff0c\u8fd4\u56de\u503c\u4e3a15H\u65f6\u4ee3\u8868\u9519\u8bef\uff0c\u8fd4\u56de06H\u4ee3\u8868\u64cd\u4f5c\u6210\u529f<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">mySerialPort->setPortName(myPortName[PortNameIndex]);\nmySerialPort->setBaudRate(9600);\nmySerialPort->setDataBits(QSerialPort::Data7);\nmySerialPort->setParity(QSerialPort::EvenParity);\nmySerialPort->setFlowControl(QSerialPort::NoFlowControl);\nmySerialPort->setStopBits(QSerialPort::OneStop);\nmyLinkStatus = mySerialPort->open(QIODevice::ReadWrite);\nif (myLinkStatus)\n{\n\tmySerialPort->setDataTerminalReady(true);\n\tqDebug() &lt;&lt; mySerialPort->portName() + \" is open\";\n}\nelse\n{\n\tqDebug(\"Uart not exist or being occupied\");\n\treturn;\n}<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"678\" height=\"997\" src=\"https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/1377717-20181217155848149-2009770963.png\" alt=\"\" class=\"wp-image-173\" srcset=\"https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/1377717-20181217155848149-2009770963.png 678w, https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/1377717-20181217155848149-2009770963-204x300.png 204w\" sizes=\"auto, (max-width: 678px) 100vw, 678px\" \/><\/figure>\n\n\n\n<p>\u8fd9\u6bb5\u8bf4\u660e\u767d\u4e86\u53d1\u9001\u768416\u8fdb\u5236\u6570\u636e\u7c7b\u578b\uff0c\u7531\u4e00\u4e2a\u5934\u7801\uff0c\u4e00\u4e2a\u6307\u4ee4 \uff0c\u4efb\u610f\u4e2a\u8d44\u6599\u4f4d\uff0c\u4e00\u4e2a\u7ed3\u675f\u7801\uff0c\u4e24\u4e2a\u603b\u548c\u6821\u9a8c\u7801\u7ec4\u6210\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"658\" height=\"734\" src=\"https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/\u5c4f\u5e55\u622a\u56fe-2021-07-14-102605.png\" alt=\"\" class=\"wp-image-177\" srcset=\"https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/\u5c4f\u5e55\u622a\u56fe-2021-07-14-102605.png 658w, https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/\u5c4f\u5e55\u622a\u56fe-2021-07-14-102605-269x300.png 269w\" sizes=\"auto, (max-width: 658px) 100vw, 658px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"578\" height=\"922\" src=\"https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/\u5c4f\u5e55\u622a\u56fe-2021-07-14-110102.png\" alt=\"\" class=\"wp-image-179\" srcset=\"https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/\u5c4f\u5e55\u622a\u56fe-2021-07-14-110102.png 578w, https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/\u5c4f\u5e55\u622a\u56fe-2021-07-14-110102-188x300.png 188w\" sizes=\"auto, (max-width: 578px) 100vw, 578px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"655\" height=\"891\" src=\"https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/\u5c4f\u5e55\u622a\u56fe-2021-07-14-111543.png\" alt=\"\" class=\"wp-image-180\" srcset=\"https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/\u5c4f\u5e55\u622a\u56fe-2021-07-14-111543.png 655w, https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/\u5c4f\u5e55\u622a\u56fe-2021-07-14-111543-221x300.png 221w\" sizes=\"auto, (max-width: 655px) 100vw, 655px\" \/><\/figure>\n\n\n\n<p>\u63a5\u4e0b\u6765\u5c31\u662f\u5177\u4f53\u7684\u6307\u4ee4\uff0cCMD\u4ee3\u8868\u6307\u4ee4\u7801\uff0c\u6307\u4ee4\u7801\u4e3a0\u65f6\u662f\u8bfb\u53d6\u5730\u5740\u7684\u6307\u4ee4\uff0c\u8fd4\u56de15\u65f6\u4ee3\u8868\u6307\u4ee4\u9519\u8bef\uff0c\u4e00\u822c\u6765\u8bf4\u6709\u53ef\u80fd\u662f\u603b\u548c\u6821\u9a8c\u7801\u51fa\u9519\uff0c\u53ef\u4ee5\u91cd\u65b0\u8ba1\u7b97\u4e00\u4e0b\u3002<\/p>\n\n\n\n<p>\u7136\u540e\u5c31\u662f\u67e5\u8868\u7684\u5730\u5740<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1436\" height=\"1023\" src=\"https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/\u5c4f\u5e55\u622a\u56fe-2021-07-14-134920.png\" alt=\"\" class=\"wp-image-181\" srcset=\"https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/\u5c4f\u5e55\u622a\u56fe-2021-07-14-134920.png 1436w, https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/\u5c4f\u5e55\u622a\u56fe-2021-07-14-134920-300x214.png 300w, https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/\u5c4f\u5e55\u622a\u56fe-2021-07-14-134920-768x547.png 768w\" sizes=\"auto, (max-width: 1436px) 100vw, 1436px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1531\" height=\"1010\" src=\"https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/\u5c4f\u5e55\u622a\u56fe-2021-07-14-135130.png\" alt=\"\" class=\"wp-image-182\" srcset=\"https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/\u5c4f\u5e55\u622a\u56fe-2021-07-14-135130.png 1531w, https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/\u5c4f\u5e55\u622a\u56fe-2021-07-14-135130-300x198.png 300w, https:\/\/www.346pro.club\/wp-content\/uploads\/2021\/07\/\u5c4f\u5e55\u622a\u56fe-2021-07-14-135130-768x507.png 768w\" sizes=\"auto, (max-width: 1531px) 100vw, 1531px\" \/><\/figure>\n\n\n\n<p>\u63a5\u4e0b\u6765\u5c31\u5f88\u6e05\u695a\u4e86\uff0c\u67e5\u8868\u627e\u5230\u5730\u5740\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u8bfb\u5199\u76f8\u5bf9\u5e94\u7684\u5730\u5740\u7684\u6570\u636e\u4e86\u3002<\/p>\n\n\n\n<p>\u8bb0\u5f97\u8f6c\u6362\u621016\u8fdb\u5236\u53d1\u9001<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">char convertHexChart(char ch)\n{\n\tif ((ch >= '0') &amp;&amp; (ch &lt;= '9'))\n\t\treturn ch - 0x30; \/\/ 0x30 \u5bf9\u5e94 \u20180\u2019\n\tif ((ch >= 'A') &amp;&amp; (ch &lt;= 'F'))\n\t\treturn ch - 'A' + 10;\n\tif ((ch >= 'a') &amp;&amp; (ch &lt;= 'f'))\n\t\treturn ch - 'a' + 10;\n\t\/\/        else return (-1);\n\treturn ch - ch;\n\t\/\/\u4e0d\u57280-f\u8303\u56f4\u5185\u7684\u4f1a\u53d1\u9001\u62100\n}\n\nvoid StringToHex(QString str, QByteArray&amp; senddata)\n{\n\tint hexdata, lowhexdata;\n\tint hexdatalen = 0;\n\tint len = str.length();\n\tsenddata.resize(len \/ 2);\n\tchar lstr, hstr;\n\tfor (int i = 0; i &lt; len;)\n\t{\n\t\t\/\/char lstr,\n\t\thstr = str[i].toLatin1();\n\t\tif (hstr == ' ')\n\t\t{\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\t\ti++;\n\t\tif (i >= len)\n\t\t\tbreak;\n\t\tlstr = str[i].toLatin1();\n\t\thexdata = convertHexChart(hstr);\n\t\tlowhexdata = convertHexChart(lstr);\n\t\tif ((hexdata == 16) || (lowhexdata == 16))\n\t\t\tbreak;\n\t\thexdata = hexdata * 16 + lowhexdata;\n\t\ti++;\n\t\tsenddata[hexdatalen] = static_cast&lt;char>(hexdata);\n\t\thexdatalen++;\n\t}\n\tsenddata.resize(hexdatalen);\n}<\/pre>\n\n\n\n<p>\u5176\u5b9e\u5230\u8fd9\u91cc\u95ee\u9898\u90fd\u4e0d\u662f\u7279\u522b\u5927\u4e86\uff0c\u5c31\u53ea\u662f\u8981\u628a\u5e38\u7528\u7684\u8bfb\u5199\u547d\u4ee4\u8ba1\u7b97\u4e00\u4e0b\uff0c\u6bd4\u5982\u8bf4<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u8bfbD10\n02 30 31 30 31 34 30 32 03 35 42\n\/\/\u8bfbD20\n02 30 31 30 32 38 30 32 03 36 30\n\/\/\u8bfbD30\n02 30 31 30 33 43 30 32 03 36 43\n\/\/\u8bfbD40\n02 30 31 30 35 30 30 32 03 35 42\n\/\/\u5199D30=0002\n02 31 31 30 33 43 30 32 30 32 30 30 03 32 46\n\/\/\u5199D30=0001\n02 31 31 30 33 43 30 32 30 31 30 30 03 32 45\n\/\/\u5199D30=01\n02 31 31 30 33 43 30 31 30 31 03 43 46<\/code><\/pre>\n\n\n\n<p>TODO\uff1a\u4e4b\u540e\u6211\u4f1a\u5199\u4e00\u4e0b\u81ea\u52a8\u8ba1\u7b97\u8bfb\u5199\u547d\u4ee4\u7684\u51fd\u6570\uff0c\u8fd9\u6837\u53ea\u8981\u8f93\u5165D\u3001X\u7684\u5730\u5740\u5c31\u80fd\u81ea\u52a8\u751f\u6210\u8bfb\u5199\u768416\u8fdb\u5236\u547d\u4ee4\uff0c\u8fd9\u6837\u6613\u7528\u6027\u5f3a\u5f88\u591a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u56e0\u5de5\u4f5c\u9700\u8981\uff0c\u7814\u7a76\u4e86\u4e00\u4e0b\u4e09\u83f1\u7684PLC\u901a\u4fe1\u534f\u8bae\uff0c\u5728\u8fd9\u91cc&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/www.346pro.club\/?p=171\">Continue reading<span class=\"screen-reader-text\">\u5229\u7528Qt\/C++\u4e32\u53e3\u901a\u8baf\u534f\u8bae\u4e0e\u4e09\u83f1PLC\u4e92\u901a<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-171","post","type-post","status-publish","format-standard","hentry","category-technology","entry"],"_links":{"self":[{"href":"https:\/\/www.346pro.club\/index.php?rest_route=\/wp\/v2\/posts\/171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.346pro.club\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.346pro.club\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.346pro.club\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.346pro.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=171"}],"version-history":[{"count":0,"href":"https:\/\/www.346pro.club\/index.php?rest_route=\/wp\/v2\/posts\/171\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.346pro.club\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.346pro.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.346pro.club\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}