Leser: 15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#!/usr/bin/perl # USB Dongle PX-1673-675 On|Off my $comport = "COM4"; ###################################################################### use strict; use warnings; use base qw(Win32::SerialPort); my $main = main->new($comport); ###################################################################### $main->baudrate(9600); $main->parity("none"); $main->databits(8); $main->stopbits(1); if(@ARGV){ my $code = $main->can($ARGV[0]) || die "Use On|Off as Argument!\n"; $main->$code; } sub On{ my $self = shift; my $cmd = 0xF0; my $chk = 255 - (0x1A + 0x85 + $cmd) % 256; my $payload = pack "C8", 0x1A,0x85,$cmd,$chk,0x20,0x0A,0x00,0x18; $self->load($payload) } sub Off{ my $self = shift; my $cmd = 0xE0; my $chk = 255 - (0x1A + 0x85 + $cmd) % 256; my $payload = pack "C8", 0x1A,0x85,$cmd,$chk,0x20,0x0A,0x00,0x18; $self->load($payload) } sub load{ my $self = shift; my $payload = shift; if($ARGV[1]){ print join " ", map{sprintf("%02X", $_)}unpack "C8", $payload; } else{ $self->write($payload) or die "Can't write: $^E"; } }