{"id":412,"date":"2009-09-18T02:03:42","date_gmt":"2009-09-17T18:03:42","guid":{"rendered":"http:\/\/www.tzlee.com\/blog\/?p=412"},"modified":"2009-10-14T03:42:17","modified_gmt":"2009-10-13T19:42:17","slug":"finally-a-real-serial-console-for-the-mac","status":"publish","type":"post","link":"https:\/\/tzlee.com\/blog\/2009\/09\/finally-a-real-serial-console-for-the-mac\/","title":{"rendered":"Finally, a Real Serial Console for the Mac"},"content":{"rendered":"<p>I&#8217;ve been searching high and low. ZTerm is extinct, screen kinda sucks with scrolling. So what do I have left?<\/p>\n<p>I attempted to write a script in Python to turn the serial port into a local socket so I could use Telnet but I couldn&#8217;t seem to get past opening the serial port.<\/p>\n<p>After some searching, I found <a href=\"http:\/\/members.iinet.net.au\/~mgl\/MartysPlace\/MultiCom.html\">MultiCom<\/a>. It does exactly what I wanted &#8211; turns my serial port into a local socket. Works prefect!<\/p>\n<p>Anyway, if you have time, help me with this script. It&#8217;s fairly simple and still incomplete, but I can&#8217;t get past fixing what blocks the open() calls to \/dev\/tty.PL2303-0000101D.<\/p>\n<p><em>Update: I managed to figure out why my script didn&#8217;t work; I should have used \/dev\/cu.* instead of \/dev\/tty.*. I also found that MultiCom doesn&#8217;t work with Cisco devices due to an odd Cisco behavior. Read <a href=\"http:\/\/www.tzlee.com\/blog\/?p=424\">this blog entry<\/a> for more info.<\/em><\/p>\n<p><!--more--><\/p>\n<pre>#!\/usr\/bin\/python\r\n\r\nimport os, socket\r\n\r\ndev = '\/dev\/tty.PL2303-0000101D'\r\nbind = '127.0.0.1'\r\nport = 8023\r\nbuff = 4096\r\n\r\nfr = open(dev, 'rb', 0)\r\nprint \"Read FD open\"\r\nfw = open(dev, 'wb', 0)\r\nprint \"Write FD open\"\r\n\r\nss = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\r\n\r\nprint \"Listening on port\", port\r\nss.bind((bind, port))\r\nss.listen(1)\r\n\r\nprint \"Waiting for socket\"\r\n(cs, ca) = ss.accept()\r\nprint \"Got socket\"\r\nss.close()\r\n\r\nprint \"Forking\"\r\npid = os.fork()\r\n\r\n# child\r\nif pid == 0:\r\n  print \"In child\"\r\n  while 1:\r\n    s = os.read(fr, buff)\r\n    if not s: break\r\n    print \"Read serial:\", s\r\n    cs.sendall(s)\r\n  close(fr)\r\n  exit(0)\r\n\r\n# parent\r\nelse:\r\n  print \"In parent\"\r\n  while 1:\r\n    s = cs.recv(buff)\r\n    if not s: break\r\n    print \"Read net:\", s\r\n    os.write(fw, s)\r\n  close(fw)\r\n  os.wait(pid)\r\n  cs.close()\r\n  exit(0)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been searching high and low. ZTerm is extinct, screen kinda sucks with scrolling. So what do I have left? I attempted to write a script in Python to turn the serial port into a local socket so I could&#8230; <a class=\"more-link\" href=\"https:\/\/tzlee.com\/blog\/2009\/09\/finally-a-real-serial-console-for-the-mac\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[8],"tags":[76,74,78,75,77],"class_list":["post-412","post","type-post","status-publish","format-standard","hentry","category-tech","tag-console","tag-mac","tag-multicom","tag-serial","tag-telnet"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tzlee.com\/blog\/wp-json\/wp\/v2\/posts\/412","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tzlee.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tzlee.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tzlee.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/tzlee.com\/blog\/wp-json\/wp\/v2\/comments?post=412"}],"version-history":[{"count":14,"href":"https:\/\/tzlee.com\/blog\/wp-json\/wp\/v2\/posts\/412\/revisions"}],"predecessor-version":[{"id":603,"href":"https:\/\/tzlee.com\/blog\/wp-json\/wp\/v2\/posts\/412\/revisions\/603"}],"wp:attachment":[{"href":"https:\/\/tzlee.com\/blog\/wp-json\/wp\/v2\/media?parent=412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tzlee.com\/blog\/wp-json\/wp\/v2\/categories?post=412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tzlee.com\/blog\/wp-json\/wp\/v2\/tags?post=412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}