echo 0015070400a4 | perl -ne 's/([0-9a-f]{2})/print chr hex $1/gie' | socat -t1 - /dev/ttyUSB-1-4,b2400
1
2
3
4
5
6
7
8
9
10
my $usb = '/dev/ttyUSB-1-4!
my $command = '0015070400a4' ;
&send ($command);
sub send
{
my $raw = shift;
$raw =~ s/([0-9a-f]{2})/chr hex $1/gie;
system ("echo ".$raw." | socat -t1 - ".$usb.",b2400");
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
my $usb = '/dev/ttyUSB-1-4'; my $command = '0015070400a4'; die("Error run 'send' ($!)") unless( send($usb, $command) ); sub send { my $usb = shift; my $raw = shift; $raw =~ s/([0-9a-f]{2})/chr( hex( $1 ) )/gie; open(my $fh,'|-',"socat -t1 - $usb,b2400") or return 0; binmode( $fh ); print $fh $raw; close( $fh ) or return 0; return 1; }
1 2 3 4 5
my $hexstr = '0015070400a4'; my $raw =pack('H*',$hexstr); $hexstr=unpack('H*',$raw);
2012-09-23T19:48:19 JuMi2006Nach der Substitution waren es doch lediglich die Klammern um $1 die das Script blockierten aber die Kommandozeile richtig interpretierte?