{"id":10,"date":"2007-03-04T07:56:20","date_gmt":"2007-03-04T12:56:20","guid":{"rendered":"http:\/\/www.tigoe.com\/pcomp\/code2\/unixlinux\/10"},"modified":"2007-08-06T23:11:50","modified_gmt":"2007-08-07T04:11:50","slug":"writing-serial-port-data-to-a-text-file","status":"publish","type":"post","link":"https:\/\/www.tigoe.com\/pcomp\/code\/OSX\/10\/","title":{"rendered":"Writing Serial Port Data to a Text File"},"content":{"rendered":"<p>Need to write incoming bytes from a serial port to a text file?  On a Unix or Linux machine (or OSX), you can do the following:\n<\/p>\n<p><!--more--><\/p>\n<p>Open the Terminal Program (usually under \/Applications\/Utilities\/Terminal)\n<\/p>\n<p>Get the name of the serial port by typing <tt>ls \/dev\/tty.*<\/tt> You should get a list like this:\n<\/p>\n<pre>\n\/dev\/tty.Bluetooth-Modem                \/dev\/tty.Keyserial1\n\/dev\/tty.Bluetooth-PDA-Sync             \/dev\/tty.usbserial-A10015y4\n<\/pre>\n<p>Make sure you know what directory you&#8217;re in.  You might want to change directories to the desktop like this: <tt>cd Desktop<\/tt>\n<\/p>\n<p>To start sending serial data into a file called datafile.txt, type screen -L (serial port name).  For example, if you&#8217;re using the serial port \/dev\/tty.usbserial-A10015y4 above, you&#8217;d type:  <tt>screen -L \/dev\/tty.usbserial-A10015y4<\/tt>  Anything coming in the serial port will automatically get written toa file called screen.0, in the current working directory. To stop sending, type control-C.\n<\/p>\n<p><strong>A few suggestions to make this go smoother:<\/strong>\n<\/p>\n<p>Send your data in ASCII rather than raw binary format. That way you can read it yourself, in addition to having a program parse it.\n<\/p>\n<p>Consider how much data you&#8217;re writing to a file.  Sending every 10 milliseconds or less will fill the file very quickly.  Your maximum file size under OSX is 2 gigabytes.  That&#8217;s 2 billion bytes. If you&#8217;re sending three ten-bit sensor readings, comma-delimited, with a newline and carriage return at the end:<\/p>\n<pre>\n1023,1023,1023\\r\\n\n<\/pre>\n<p>That&#8217;s 16 bytes.  If you&#8217;re sending that every 10 milliseconds, that&#8217;s 1600 bytes a second.  That&#8217;ll take about 173.6 hours to fill 2GB.  That&#8217;s about a week. <\/p>\n<p> Inspired by Adams: Simon and Parrish. Thanks to Kate Hartman and Rob Faludi for the updates.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Need to write incoming bytes from a serial port to a text file?<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-10","post","type-post","status-publish","format-standard","hentry","category-OSX"],"_links":{"self":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/posts\/10","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/comments?post=10"}],"version-history":[{"count":0,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/posts\/10\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/media?parent=10"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/categories?post=10"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/tags?post=10"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}