{"id":191,"date":"2021-11-21T13:03:26","date_gmt":"2021-11-21T13:03:26","guid":{"rendered":"http:\/\/47.103.123.166\/?p=191"},"modified":"2021-11-21T13:19:56","modified_gmt":"2021-11-21T13:19:56","slug":"c_8-%e5%bc%80%e6%ba%90%e4%b8%b2%e5%8f%a3%e5%ba%93","status":"publish","type":"post","link":"http:\/\/47.103.123.166\/?p=191","title":{"rendered":"C++_8\u2014\u2014\u5f00\u6e90\u4e32\u53e3\u5e93"},"content":{"rendered":"<h3>For Linux<\/h3>\n<h4>CppLinuxSerial<\/h4>\n<p>\u4e00\u4e2a\u7b80\u5355\u597d\u7528\u7684serial\u5e93  <a href=\"https:\/\/github.com\/gbmhunter\/CppLinuxSerial\"><a href=\"https:\/\/github.com\/gbmhunter\/CppLinuxSerial\">https:\/\/github.com\/gbmhunter\/CppLinuxSerial<\/a><\/a><\/p>\n<ol>\n<li>\u4e0b\u8f7d\u3001\u7f16\u8bd1\u3001\u5b89\u88c5\u5982\u4e0b\n<pre><code class=\"language-shell\">git clone https:\/\/github.com\/gbmhunter\/CppLinuxSerial.git\ncd CppLinuxSerial\/ &amp;&amp; mkdir build &amp;&amp; cd build \ncmake ..\nmake\nsudo make install<\/code><\/pre>\n<\/li>\n<li>\u5b89\u88c5\u4f4d\u7f6e\u5982\u4e0b\uff0c\u751f\u6210\u4e86\u4e00\u4e2a\u9759\u6001\u5e93\uff0c\u5934\u6587\u4ef6\u4e5f\u53ea\u6709\u4fe9\n<pre><code class=\"language-bash\">Installing: \/usr\/local\/lib\/libCppLinuxSerial.a\nInstalling: \/usr\/local\/include\/CppLinuxSerial\nInstalling: \/usr\/local\/include\/CppLinuxSerial\/SerialPort.hpp\nInstalling: \/usr\/local\/include\/CppLinuxSerial\/Exception.hpp<\/code><\/pre>\n<\/li>\n<li>\n<p>\u6d4b\u8bd5<\/p>\n<pre><code class=\"language-cpp\">\/\/ serial\u5e93\u7684\u5934\u6587\u4ef6\uff0c\u9700\u8981\u5728CmakeLists.txt\u91cc\u9762\u6dfb\u52a0\u5e93\uff0c\u6216\u8fd9\u5728\u7f16\u8bd1\u65f6\u6dfb\u52a0\u5e93\n#include &lt;CppLinuxSerial\/SerialPort.hpp&gt;\nusing namespace mn::CppLinuxSerial;\nint main() {\n\/\/ \u521b\u5efa\u5bf9\u8c61\n\/\/ \u81ea\u5b9a\u4e49\u6ce2\u7279\u7387 SerialPort serialPort(\"\/dev\/ttyACM0\", 13000);\nSerialPort serialPort(\"\/dev\/ttyUSB0\", BaudRate::B_57600);\n\n\/\/ \u63a5\u6536\u8d85\u65f6\u65f6\u95f4\n\/\/ \u963b\u585e\u63a5\u6536\uff1a        \u8f93\u5165\u4e3a0\uff0c\u4ee3\u8868\u975e\u963b\u585e\uff1b \u8f93\u5165\u4e3a-1\u4ee3\u8868\u963b\u585e\u63a5\u6536\nserialPort.SetTimeout(-1); \/\/ Block when reading until any data is received\n\n\/\/ \u6253\u5f00\nserialPort.Open();\n\n\/\/ \u53d1\u9001\nserialPort.Write(\"Hello\");\n\n\/\/ \u63a5\u6536\nstd::string readData;\nserialPort.Read(readData);\n\n\/\/ \u5173\u95ed\nserialPort.Close();\n}<\/code><\/pre>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>For Linux CppLinuxSerial \u4e00\u4e2a\u7b80\u5355\u597d\u7528\u7684serial\u5e93 https:\/\/github.com\/gbmhunter\/CppLinuxSerial \u4e0b\u8f7d\u3001\u7f16\u8bd1\u3001\u5b89\u88c5\u5982\u4e0b git clone https:\/\/github.com\/gbmhunter\/CppLinuxSerial.git cd CppLinuxSerial\/ &amp;&amp; mkdir build &amp;&amp; cd build cmake .. make sudo make install \u5b89\u88c5\u4f4d\u7f6e\u5982\u4e0b\uff0c\u751f\u6210\u4e86\u4e00\u4e2a\u9759\u6001\u5e93\uff0c\u5934\u6587\u4ef6\u4e5f\u53ea\u6709\u4fe9 Installing: \/usr\/local\/lib\/libCppLinuxSerial.a Installing: \/usr\/local\/include\/CppLinuxSerial Installing: \/usr\/local\/include\/CppLinuxSerial\/SerialPort.hpp Installing: \/usr\/local\/include\/CppLinuxSerial\/Exception.hpp \u6d4b\u8bd5 \/\/ serial\u5e93\u7684\u5934\u6587\u4ef6\uff0c\u9700\u8981\u5728CmakeLists.txt\u91cc\u9762\u6dfb\u52a0\u5e93\uff0c\u6216\u8fd9\u5728\u7f16\u8bd1\u65f6\u6dfb\u52a0\u5e93 #include &lt;CppLinuxSerial\/SerialPort.hpp&gt; using namespace mn::CppLinuxSerial; int main() { \/\/ \u521b\u5efa\u5bf9\u8c61 \/\/ \u81ea\u5b9a\u4e49\u6ce2\u7279\u7387 SerialPort serialPort(&#8220;\/dev\/ttyACM0&#8221;, 13000); SerialPort serialPort(&#8220;\/dev\/ttyUSB0&#8221;, BaudRate::B_57600); \/\/ \u63a5\u6536\u8d85\u65f6\u65f6\u95f4 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"http:\/\/47.103.123.166\/index.php?rest_route=\/wp\/v2\/posts\/191"}],"collection":[{"href":"http:\/\/47.103.123.166\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/47.103.123.166\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/47.103.123.166\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/47.103.123.166\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=191"}],"version-history":[{"count":3,"href":"http:\/\/47.103.123.166\/index.php?rest_route=\/wp\/v2\/posts\/191\/revisions"}],"predecessor-version":[{"id":199,"href":"http:\/\/47.103.123.166\/index.php?rest_route=\/wp\/v2\/posts\/191\/revisions\/199"}],"wp:attachment":[{"href":"http:\/\/47.103.123.166\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/47.103.123.166\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=191"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/47.103.123.166\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}