#!/usr/bin/perl -w # Program for connecting to MySmartUSB microntroller programmer # Copyright (C) 2008 Peter Stuifzand # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . use Device::SerialPort qw( :PARAM :STAT 0.07 ); my %commands = ( 'reset' => 'r', 'reset-programmer' => 'R', 'poweron' => '+', 'poweroff' => '-', 'program' => 'p', 'data' => 'd', 'quiet' => 'q', 'state' => 'i', ); sub usage { my $command = shift; if (defined $command) { print "Unknown command $command\nYou should use one of:\n " . join("\n ", keys %commands) . "\n"; } else { print "Missing command\nYou should use one of:\n " . join("\n ", keys %commands) . "\n"; } exit; } my $command = $ARGV[0] or usage(); if (!exists $commands{$ARGV[0]}) { usage($ARGV[0]); } my $PortName = '/dev/ttyUSB0'; my $port = Device::SerialPort->new($PortName, 0, undef) || die "Can't open $PortName: $!\n"; $port->baudrate(19200); $port->parity("none"); $port->databits(8); $port->stopbits(1); # POSIX does not support 1.5 stopbits $port->write(pack("C*", 0xE6, 0xB5, 0xBA, 0xB9, 0xB2, 0xB3, 0xA9, ord($commands{$command}))); sleep(1); $port->close();