{"id":630,"date":"2009-10-28T14:39:16","date_gmt":"2009-10-28T18:39:16","guid":{"rendered":"http:\/\/www.uvm.edu\/~waw\/blog\/?p=630"},"modified":"2009-10-28T14:39:16","modified_gmt":"2009-10-28T18:39:16","slug":"serial-interface-fun","status":"publish","type":"post","link":"https:\/\/blog.uvm.edu\/waw\/2009\/10\/28\/serial-interface-fun\/","title":{"rendered":"serial interface fun"},"content":{"rendered":"<p>Perl module Device::SerialPort is our friend.<\/p>\n<p>As is Clipboard, IO::All, Spiffy<\/p>\n<p>Trying to talk to a Sartorius precision balance. Speaks over Serial\/USB cable.<\/p>\n<p>Dang, there was supposed to be more here to serve as documentation. Now, months later, I have forgotten it all&#8230;<\/p>\n<p>Here is at least the shell of the code:<\/p>\n<p><code><br \/>\n#!\/usr\/bin\/perl<br \/>\nuse Data::Dumper;<br \/>\nuse DBI;<br \/>\nuse Device::SerialPort;<br \/>\nuse Time::HiRes qw(usleep);<br \/>\nuse CGI;<br \/>\n$query=new CGI;<br \/>\nprint $query-&gt;header;<br \/>\nuse Clipboard;<br \/>\nsub block_output {<br \/>\n\tmy $block=shift(@_);<br \/>\n\tprint \"blocking $blockn\";<br \/>\n\t@bytes = split (\/\/, $block);<br \/>\n\tforeach $byte (@bytes) {<br \/>\n\t\tsend_char($byte);<br \/>\n\t}<br \/>\n}<br \/>\nsub send_char {<br \/>\n\tmy $byte=shift(@_);<br \/>\n\tmy $char;<br \/>\n\tprint \"send byte $byten\";<br \/>\n\t$port-&gt;write(\"$byte\");<br \/>\n}<br \/>\n######################<br \/>\n#                    #<br \/>\n#  Program Main      #<br \/>\n#                    #<br \/>\n######################<br \/>\n# Set up the serial port<br \/>\n# 19200, 81N on the USB ftdi driver<br \/>\n$debug=shift(@ARGV);<br \/>\nprint \"debug=$debugn\";<br \/>\nif (!$debug) {<br \/>\n\t$port = Device::SerialPort-&gt;new(\"\/dev\/tty.usbserial-0000201A\");<br \/>\n\t$port-&gt;databits(7);<br \/>\n\t$port-&gt;baudrate(9600);<br \/>\n\t$port-&gt;parity(\"odd\");<br \/>\n\t$port-&gt;stopbits(1);<br \/>\n\t@handshake_opts = $port-&gt;handshake;<br \/>\n\tprint Dumper @handshake_opts;<br \/>\n\t$port-&gt;handshake(\"none\");<br \/>\n}<br \/>\n#block_output(chr(27).'P');<br \/>\nusleep(250000);<br \/>\n$count=0;<br \/>\nwhile (1) {<br \/>\n\tuntil ($count) {<br \/>\n\t\t($count,$char) = $port-&gt;read(16);<br \/>\n\t\tsleep 3;<br \/>\n\t}<br \/>\n\tprint \"count=$count char=$charn\";<br \/>\n\tif ($count == 16) {<br \/>\n\t\t$weight=substr($char,9,7);<br \/>\n\t\tClipboard-&gt;copy($weight);<br \/>\n\t}<br \/>\n\t$count=0;<br \/>\n}<br \/>\nprint \"count=$count char=$charn\";<br \/>\n$weight=substr($char,9,7);<br \/>\nClipboard-&gt;copy($weight);<br \/>\n$count=0;<br \/>\n#while ($count) {<br \/>\n#\t($count,$char) = $port-&gt;read(1);<br \/>\n#\tprint \"reply  char $char count=$countn\";<br \/>\n#}<br \/>\nexit;<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Perl module Device::SerialPort is our friend. As is Clipboard, IO::All, Spiffy Trying to talk to a Sartorius precision balance. Speaks over Serial\/USB cable. Dang, there was supposed to be more here to serve as documentation. Now, months later, I have &hellip; <a href=\"https:\/\/blog.uvm.edu\/waw\/2009\/10\/28\/serial-interface-fun\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6517,8025],"tags":[],"class_list":["post-630","post","type-post","status-publish","format-standard","hentry","category-projects","category-scriptingprogramming"],"_links":{"self":[{"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/posts\/630","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/comments?post=630"}],"version-history":[{"count":2,"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/posts\/630\/revisions"}],"predecessor-version":[{"id":632,"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/posts\/630\/revisions\/632"}],"wp:attachment":[{"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/media?parent=630"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/categories?post=630"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.uvm.edu\/waw\/wp-json\/wp\/v2\/tags?post=630"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}