{"id":2140,"date":"2015-12-05T00:04:17","date_gmt":"2015-12-04T16:04:17","guid":{"rendered":"https:\/\/tomchun.tw\/tomchun\/?p=2140"},"modified":"2016-12-26T16:10:20","modified_gmt":"2016-12-26T08:10:20","slug":"1-457","status":"publish","type":"post","link":"https:\/\/tomchun.tw\/tomchun\/2015\/12\/05\/1-457\/","title":{"rendered":"\u3010\u6559\u5b78\u3011\u6a39\u8393\u6d3eRaspberry PI(RASPBIAN)\u6e2c\u8a66Console 115200\u529f\u80fd"},"content":{"rendered":"<p style=\"text-align: center;\"><strong><span style=\"color: #0000ff;\">\u767b\u5165SSH PI<br \/>\n<\/span><\/strong><!--more--><strong><span style=\"color: #0000ff;\">\u00a0<\/span><\/strong><strong><span style=\"color: #0000ff;\">\u64b0\u5beb\u6e2c\u8a66\u6587\u4ef6<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">nano 1.py<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">\u5beb\u5165\u4ee5\u4e0b\u7a0b\u5f0f\u78bc<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">import serial<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">import time<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">def readlineCR(port):<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">rv = &#8220;&#8221;<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">while True:<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">ch = port.read()<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">rv += ch<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">if ch==&#8217;\\r&#8217; or ch==&#8221;:<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">return rv<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">port = serial.Serial(&#8220;\/dev\/ttyAMA0&#8221;, baudrate=115200, timeout=3.0)<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">while True:<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">port.write(&#8220;\\r\\n123456&#8221;)<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">rcv = readlineCR(port)<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">port.write(&#8220;\\r\\nYou sent:&#8221; + repr(rcv))<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">\u00a0&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">\u6216\u662f\u7b2c\u4e8c\u7a2e<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">import datetime<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">import os<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">import time<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">import serial<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">ser = serial.Serial(&#8216;\/dev\/ttyAMA0&#8217;, 115200, timeout=1)<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">date = datetime.datetime.now().strftime( &#8220;%d\/%m\/%Y %H:%M.%s&#8221; )<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">ser.close()<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">ser.open()<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">print &#8220;Hit &#8216;Control C&#8217; to halt this program&#8221;<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">ser.write(&#8220;Starting \\n\\r&#8221;)<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">try:<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">while 1:<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">date = datetime.datetime.now().strftime( &#8220;%d\/%m\/%Y %H:%M.%S&#8221; )<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">response = ser.readline()<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\"># you can check your serial receive by uncommenting the above line <\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">#print response<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">ser.write(&#8220;Testing&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8221; + date +&#8221;\\n\\r&#8221;)<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">except KeyboardInterrupt:<\/span><\/strong><br \/>\n<strong><span style=\"color: #0000ff;\">ser.close()<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">ctrl+o\u5b58\u6a94 ctrl+z\u96e2\u958b<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">\u57f7\u884cpython 1.py<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">\u770b\u4f60\u7684console\u6709\u6c92\u6709\u6536\u5230\u8a0a\u865f<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">\u6e2c\u8a66\u7d50\u679c<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">\u00a0<img decoding=\"async\" title=\"1427251888484\" src=\"http:\/\/pic.pimg.tw\/trew780918\/1427252627-1051572588.jpg\" alt=\"1427251888484\" border=\"0\" \/><\/span><\/strong><\/p><div class=\"8174c08f3e8258bc782beea63dd170ee\" data-index=\"1\" style=\"float: none; margin:0px 0 0px 0; text-align:center;\">\n<br>\r\n<hr size=\"8px\" align=\"center\" width=\"100%\">\r\n<br>\r\n<!-- \u5167\u6587\u4e0a\u65b91 -->\r\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-1525485034639690\"\r\n     crossorigin=\"anonymous\"><\/script>\r\n<ins class=\"adsbygoogle\"\r\n     style=\"display:block\"\r\n     data-ad-client=\"ca-pub-1525485034639690\"\r\n     data-ad-slot=\"5744735635\"\r\n     data-ad-format=\"auto\"\r\n     data-full-width-responsive=\"true\"><\/ins>\r\n<script>\r\n     (adsbygoogle = window.adsbygoogle || []).push({});\r\n<\/script>\r\n<br>\r\n<hr size=\"8px\" align=\"center\" width=\"100%\">\r\n<br>\r\n<!-- \u5167\u6587\u4e2d1 -->\r\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-1525485034639690\"\r\n     crossorigin=\"anonymous\"><\/script>\r\n<ins class=\"adsbygoogle\"\r\n     style=\"display:block\"\r\n     data-ad-client=\"ca-pub-1525485034639690\"\r\n     data-ad-slot=\"6362030347\"\r\n     data-ad-format=\"auto\"\r\n     data-full-width-responsive=\"true\"><\/ins>\r\n<script>\r\n     (adsbygoogle = window.adsbygoogle || []).push({});\r\n<\/script>\r\n<br>\r\n<hr size=\"8px\" align=\"center\" width=\"100%\">\r\n<br>\n<\/div>\n\n<p style=\"text-align: center;\"><strong><span style=\"color: #0000ff;\">\u00a0<img decoding=\"async\" title=\"1427252347583\" src=\"http:\/\/pic.pimg.tw\/trew780918\/1427252627-2789820345_n.jpg?v=1427252629\" alt=\"1427252347583\" border=\"0\" \/><br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">\u5f8c\u4f86\u767c\u73fe\u7a7a\u683c\u6703\u5f71\u97ffpython<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">\u8acb\u4e0b\u8f09\u6587\u5b57\u6a94\u9032\u884c\u6e2c\u8a66<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\"><a style=\"color: #0000ff;\" href=\"ftp:\/\/122.146.248.162\/py.z\" target=\"_blank\">\u4e0b\u8f09\u9ede<\/a><\/span><\/strong><\/p>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>\u767b\u5165SSH PI<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2140","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"modified_by":"tomchun","_links":{"self":[{"href":"https:\/\/tomchun.tw\/tomchun\/wp-json\/wp\/v2\/posts\/2140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tomchun.tw\/tomchun\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tomchun.tw\/tomchun\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tomchun.tw\/tomchun\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tomchun.tw\/tomchun\/wp-json\/wp\/v2\/comments?post=2140"}],"version-history":[{"count":0,"href":"https:\/\/tomchun.tw\/tomchun\/wp-json\/wp\/v2\/posts\/2140\/revisions"}],"wp:attachment":[{"href":"https:\/\/tomchun.tw\/tomchun\/wp-json\/wp\/v2\/media?parent=2140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tomchun.tw\/tomchun\/wp-json\/wp\/v2\/categories?post=2140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tomchun.tw\/tomchun\/wp-json\/wp\/v2\/tags?post=2140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}