{"id":1042,"date":"2020-03-04T20:15:50","date_gmt":"2020-03-04T20:15:50","guid":{"rendered":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/?p=1042"},"modified":"2020-03-08T13:13:39","modified_gmt":"2020-03-08T13:13:39","slug":"working-with-the-economatics-smart-box-serial-interface-on-a-modern-computer","status":"publish","type":"post","link":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/?p=1042","title":{"rendered":"Working with the Economatics Smart Box Serial Interface on a Modern Computer"},"content":{"rendered":"\n<h2>Working with the Economatics Smart Box Serial Interface on a Modern Computer<\/h2>\n\n\n\n<p>Well, I had all sorts of fancy plans for how I would reverse engineer the serial protocol to control my ebay purchase &#8220;Smart Box&#8221; (some of which I will document at some point as they&#8217;re useful). Ultimately, I had so much difficulty installing MS .net 1.1 in Wine \/ PlayOnLinux that I went back to trawling the internet looking for alternative software to wire tap.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" src=\"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/03\/IMG_20200223_153013-1024x768.jpg\" alt=\"Smart Box\" class=\"wp-image-1058\" width=\"512\" height=\"384\" srcset=\"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/03\/IMG_20200223_153013-1024x768.jpg 1024w, https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/03\/IMG_20200223_153013-300x225.jpg 300w, https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/03\/IMG_20200223_153013-1536x1152.jpg 1536w, https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/03\/IMG_20200223_153013.jpg 1984w\" sizes=\"(max-width: 512px) 100vw, 512px\" \/><figcaption>Smart Box<\/figcaption><\/figure><\/div>\n\n\n\n<p>I struck gold when I found the following website :<\/p>\n\n\n\n<p><a href=\"http:\/\/old.ftcommunity.de\/ftComputingFinis\/smartboxe.html\">http:\/\/old.ftcommunity.de\/ftComputingFinis\/smartboxe.html<\/a><\/p>\n\n\n\n<p>The website includes a download of example code, the core of which is in VB6 and includes many serial commands for controlling the Smart Box (SB-04 version &#8211; I understand that older versions work differently, so be warned!), as well as an instruction manual that goes some way to explaining how the box data formats work.<\/p>\n\n\n\n<p>After a bit of messing about in Python, it was fairly trivial to test a number of commands and witness the results. The only major feature I&#8217;m not currently sure about is the Analogue Inputs &#8211; I don&#8217;t know what the pinout is of the 5 pin DIN sockets, and so can&#8217;t easily test them. Perhaps a bit of circuit board investigation will help with this.<\/p>\n\n\n\n<p>In summary, I have found the following :<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td><strong>Description<\/strong><\/td><td><strong>Command<\/strong><\/td><td><strong>Parameter<\/strong><\/td><td><strong>Response<\/strong><\/td><td><strong>Python Example<\/strong><\/td><\/tr><tr><td>Set All Motors<\/td><td>10<\/td><td>8 bit value. Note, each pair of bits represents a motor. 01=left, 10=right and 00=stop<\/td><td>n\/a<\/td><td>ser.write(chr(10)+chr(0b01010101)) # rotate all motors to the left<\/td><\/tr><tr><td>Motor &lt;x&gt; Left<\/td><td>12<\/td><td>1 to 4<\/td><td>n\/a<\/td><td>ser.write(chr(12)+chr(1)) # rotate motor &#8216;A&#8217; to the left<\/td><\/tr><tr><td>Motor &lt;x&gt; Right<\/td><td>13<\/td><td>1 to 4<\/td><td>n\/a<\/td><td>ser.write(chr(13)+chr(1)) # rotate motor &#8216;A&#8217; to the right<\/td><\/tr><tr><td>Motor &lt;x&gt; Stop<\/td><td>14<\/td><td>1 to 4<\/td><td>n\/a<\/td><td>ser.write(chr(14)+chr(1)) # stop motor &#8216;A&#8217;<\/td><\/tr><tr><td>Set All Digital Outputs<\/td><td>20<\/td><td>8 bit value<\/td><td>n\/a<\/td><td>ser.write(chr(20)+chr(0b11111111)) # turn all digital outputs on<\/td><\/tr><tr><td>Get Analogue &lt;x&gt;<\/td><td>40 (TBC)<\/td><td>1 to 4<\/td><td>8 bit value??<\/td><td>ser.write(chr(40)+chr(1)) # send me analogue input &#8216;A&#8217;<\/td><\/tr><tr><td>Set Low Resolution Analogue<\/td><td>45 (TBC)<\/td><td>n\/a<\/td><td>n\/a<\/td><td>ser.write(chr(45)) # set low resolution analogue mode<\/td><\/tr><tr><td>Get All Digital Inputs<\/td><td>90<\/td><td>n\/a<\/td><td>8 bit value. Note the command seems to respond with three bytes, although the first identifies the status of each input.<\/td><td>ser.write(chr(90)) # send me the status of the digital inputs<\/td><\/tr><tr><td>Get Digital Input &lt;x&gt;<\/td><td>91 (TBC)<\/td><td>1 to 8<\/td><td>0 or 1 (in 8 bit value)<\/td><td>ser.write(chr(45)+chr(1)) # send me the status of digital input 0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The following example switches on motor &#8216;A&#8217; for 5 seconds, stops it for 0.5 seconds, runs it backwards for 2 seconds and then stops it. Note the serial port will need setting &#8211; I have used &#8216;\/dev\/ttyUSB0&#8217; as this is the correct port for my USB to RS232 adapter on my Linux machine.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/python\n\n# https:\/\/elephantandchicken.co.uk\/stuffandnonsense\n# 04\/03\/2020\n\nimport time\nimport serial\n\n# This example tests motor output A\n\nser = serial.Serial('\/dev\/ttyUSB0', 9600, timeout=1)\n\nser.write(chr(12)+chr(1))\ntime.sleep(5)\nser.write(chr(14)+chr(1))\ntime.sleep(0.5)\nser.write(chr(13)+chr(1))\ntime.sleep(2)\nser.write(chr(14)+chr(1))\n\nser.close()<\/code><\/pre>\n\n\n\n<p>The following example reads the status of all digital inputs (aka &#8220;Digital Sensors&#8221;) 20 times.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/python\n\n# https:\/\/elephantandchicken.co.uk\/stuffandnonsense\n# 04\/03\/2020\n\nimport time\nimport serial\n\n# This example reads in the digital sensors and displays their status\n\nser = serial.Serial('\/dev\/ttyUSB0', 9600, timeout=1)\n\n# Flash Digital Outputs to show that the program is running\nser.write(chr(20)+chr(255)) # all on\ntime.sleep(0.1)\nser.write(chr(20)+chr(0)) # all off\ntime.sleep(0.1)\n\ni = 0\n\nwhile i &lt; 20:\n\tser.write(chr(90)+chr(1)) # request digital input status\n\ttime.sleep(1) # wait (ages) for the response\n\treadVal = 0 # clear variables\n\treadByte = 0\n\treadByte = ord(ser.read(1)) # read the first waiting byte in the buffer\n\twhile ser.inWaiting() > 0: # if there is more data in the buffer\n\t\treadVal = ord(ser.read(1)) # read it to clear it\n\tprint \"result : \",format(readByte, '08b') # print the first byte in boolean format\n\ti+=1 # increment counter for the while loop\nser.close()<\/code><\/pre>\n\n\n\n<p>I still have some more work to do, regarding confirming exactly how these commands work (for example, what are the second and third bytes from the digital read response?). Additionally, I suspect that it is possible to set the voltages, but don&#8217;t know how. I&#8217;m (absolutely) guessing that command 11 might be motor speed.<\/p>\n\n\n\n<p>Additionally, please contact me if you know any more details of the control scheme, or the analogue port pinout.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Working with the Economatics Smart Box Serial Interface on a Modern Computer Well, I had all sorts of fancy plans for how I would reverse engineer the serial protocol to control my ebay purchase &#8220;Smart Box&#8221; (some of which I will document at some point as they&#8217;re useful). Ultimately, I had so much difficulty installing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1046,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[6,13,169,42,12,152,153,260],"tags":[247,65,250,259,248],"jetpack_featured_media_url":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/wp-content\/uploads\/2020\/02\/IMG_20200223_150134.jpg","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7g9vY-gO","_links":{"self":[{"href":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/index.php?rest_route=\/wp\/v2\/posts\/1042"}],"collection":[{"href":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1042"}],"version-history":[{"count":9,"href":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/index.php?rest_route=\/wp\/v2\/posts\/1042\/revisions"}],"predecessor-version":[{"id":1074,"href":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/index.php?rest_route=\/wp\/v2\/posts\/1042\/revisions\/1074"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/index.php?rest_route=\/wp\/v2\/media\/1046"}],"wp:attachment":[{"href":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1042"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elephantandchicken.co.uk\/stuffandnonsense\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}