Leser: 17
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; use Device::SerialPort ;#qw( :PARAM :STAT 0.07 ); my $PortObj ; use bytes; my $ezio = { cmd=> chr hex ( '0xFE' ), init=> chr hex ( '0x28' ), stopsend=>chr hex ( '0x37' ), cls=> chr ( 1 ) , home=> chr ( 2 ), blank=> chr ( 8 ), hide=>chr hex ( '0x0C' ), }; sub ShowMessage { my $text = shift; my $text2 = shift; use bytes ; my $textlength = length $text; my $textlength2 = length $text2; no bytes; my $textpos = 40 - $textlength; #print "$textpos\n"; $PortObj->write("$text"); $PortObj->write("$text,$textlength"); $PortObj->write(q{},$textpos); $PortObj->write($text2,$textlength2); #print FH $text,$textlength; #print FH q{},$textpos; #print FH $text2,$textlength2; return () } sub SerialInit { $PortObj = Device::SerialPort->new ( '/dev/cua01' ) || die "Can't open serialport: $!\n"; $PortObj->datatype('raw'); $PortObj->user_msg(1); # built-in instead of warn/die above $PortObj->error_msg(1); # translate error bitmasks and carp #$PortObj->debug(1); $PortObj->baudrate(2400); $PortObj->parity('none'); $PortObj->databits(8); $PortObj->stopbits(1); $PortObj->purge_all(); # $PortObj->dtr_active(1); # $PortObj->rts_active(0); # $PortObj->save('/tmp/settings.cua01'); # $PortObj->close(); return (); } sub Uninit_Serial { $PortObj->close(); return (); } sub Init { $PortObj->write("$ezio->{cmd}"); $PortObj->write("$ezio->{init}"); $PortObj->write("$ezio->{cmd}"); $PortObj->write("$ezio->{init}"); return (); } sub Cls { $PortObj->write("$ezio->{cmd}"); # initial prompt $PortObj->write("$ezio->{cls}"); # initial prompt return (); } SerialInit ; Uninit_Serial(); SerialInit(); Init(); Cls(); ShowMessage('*Portwell EZIO *','****************'); Uninit_Serial(); 1;
2011-11-03T16:19:43 GwenDragonWo wird denn die Schnittstelle (Hardware, API) zu dem System (ich nehme an es handelt sich um einen Embedded Controler) beschrieben. Bitte um Link zu der Seite.
1 2 3 4 5 6 7 8 9
my $ezio = { cmd=> chr hex ( '0xFE' ), init=> chr hex ( '0x28' ), stopsend=>chr hex ( '0x37' ), cls=> chr ( 1 ) , home=> chr ( 2 ), blank=> chr ( 8 ), hide=>chr hex ( '0x0C' ), };
1 2 3 4 5 6 7 8 9
my $ezio = { cmd=> "\xFE", init=> "\x28", stopsend=> "\x37", cls=> "\x01", home=> "\x02", blank=> "\x08", hide=> "\x0C", };
1 2 3 4
$PortObj->write("$text"); $PortObj->write("$text,$textlength"); $PortObj->write(q{},$textpos); $PortObj->write($text2,$textlength2);
1 2 3
$PortObj->write($text,$textlength); $PortObj->write(q{ } x $textpos,$textpos); $PortObj->write($text2,$textlength2);
2011-11-03T17:27:57 GwenDragonMir ist aufgefallen, dass du in Zeile 32 und 33 nicht String und Länge sendest, sondern die Zeichenkette aus String + Komma + Länge. Das ist nur ein Parameter, statt zwei.
Ich dachte, der Controller will immer die Message als Bytes und Länge als Byte haben!?
$PortObj->write(pack ('H*' , '0xFE') ) ;
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/perl -w
use strict;
use warnings;
use Data::Dumper;
use IPC::Open2;
my $ezio = {
cmd=> chr ( hex ( '0xFE' ) ) ,
init=> chr ( hex ( '0x28' ) ) ,
stopsend=> chr ( hex ( '0x37' ) ) ,
cls=> chr ( hex ( '0x01' ) ) ,
home=> chr ( hex ( '0x02' ) ) ,
blank=> chr ( hex ( '0x8' ) ) ,
hide=> chr ( hex ( '0x0C' ) ),
readkey=> chr ( hex ( '0x06' ) ),
turnon=> chr ( hex ( '0x0D' ) ) ,
cursor=> chr ( hex ( '0x0E' ) ) ,
};
sub ShowMessage {
my $text = shift;
my $text2 = shift;
use bytes ;
my $textlength = length $text;
my $textlength2 = length $text2;
no bytes;
my $textpos = 40 - $textlength;
print {*TTYOUT} $text,$textlength;
print {*TTYOUT} "q{ } x $textpos";
print {*TTYOUT} $text2,$textlength2;
return ()
}
sub open_display {
qx(pkill cu);
my $stty = `/bin/stty -g`;
open2( \*TTYIN, \*TTYOUT, 'cu -l/dev/cua01 -s2400 2>&1');
# starting cu hoses /dev/tty's stty settings, even when it has
# been opened on a pipe...
qx(/bin/stty $stty);
$_ = <TTYIN>;
chomp;
if ( !m/^Connected/ ) {
print STDERR "$0: cu printed `$_' instead of `Connected'\n";
}
return ();
}
sub close_display {
close TTYIN;
close TTYOUT;
return ();
}
sub EzioInit {
print TTYOUT $ezio->{cmd};
print TTYOUT $ezio->{init};
print TTYOUT $ezio->{cmd};
print TTYOUT $ezio->{init};
return ();
}
sub Cls {
print TTYOUT $ezio->{cmd};
print TTYOUT $ezio->{cls};
return ();
}
sub Blank {
print TTYOUT $ezio->{cmd};
print TTYOUT $ezio->{blank};
return ();
}
sub CursorOn {
print TTYOUT "$ezio->{cmd}";
print TTYOUT "$ezio->{cursor}";
return ();
}
sub Hide {
print TTYOUT $ezio->{cmd};
print TTYOUT $ezio->{hide};
return ();
}
open_display();
EzioInit();
#open_display();
Cls();
Blank();
ShowMessage('*HGL EZIO *','****************');
Hide();
close_display();
1