-
Notifications
You must be signed in to change notification settings - Fork 1
/
parselwrite.pl
executable file
·70 lines (52 loc) · 1.42 KB
/
parselwrite.pl
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/perl
use Data::Dumper ;
use Time::HiRes ;
# my $device="/dev/hidraw0" ;
my $device="../dev_infini_serial" ;
# $| = 1; # don't buffer output
my ($cmd, $cnt);
if ($#ARGV == 0) {
$cnt = shift @ARGV;
$cmd = 'P' ;
} elsif ($#ARGV == 1) {
($cmd , $cnt) = @ARGV;
} else {
die "usage: $0 [cmd = S|P] [content] ";
}
my $string = (sprintf "^%1s%03d%s", $cmd, (length ($cnt) +1), $cnt) ;
open HID, ">" . $device or die "cannot open $device - reason: $!" ;
# HID->autoflush(1);
# printf "%s|\n", $string;
printf HID "%s\r", $string;
# parsel_print ($string) ;
close HID;
exit;
#~~~~~~~~~~~~~~~~~~~~
#
# usb chunked_print (handle, string)
# don'oveerrun 2400 baud processor
#
sub parsel_print {
my $str = shift @_;
# $str .= "\r";
# while ($my chunk = substr($str,
my @chunks = unpack("(A4)*", $str);
push @chunks, "\r";
print Dumper (@chunks);
my $timestamp = Time::HiRes::time();
foreach my $chunk (@chunks) {
# my $nexdue = Time::HiRes::time() + 0.04 ; # wait one
# Time::HiRes::usleep (max(0, $timestamp +0.05));
my $timediff = 0.05 + ($timestamp - Time::HiRes::time()) ;
printf " >%f< ", $timediff ;
if ($timediff > 0) { print "#" ; Time::HiRes::sleep($timediff ) } ;
# sleep(1) ;
# $timestamp = Time::HiRes::time() ;
print $chunk, '|';
print HID $chunk;
# syswrite HID , $chunk;
$timestamp = Time::HiRes::time() ;
}
print "\n" ;
# die "======= DEBUG =========";
}