/[cvs]/nfo/perl/scripts/serialcom/relaiskarte/relais.pl
ViewVC logotype

Contents of /nfo/perl/scripts/serialcom/relaiskarte/relais.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Thu Jun 5 15:51:47 2003 UTC (20 years, 9 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/plain
initial commit

1 #!/usr/bin/perl
2
3 # $Id$
4 # $Log$
5
6
7 use strict;
8 use warnings;
9
10 use Term::ReadKey;
11 use Getopt::Long;
12
13 use Relais qw(
14 sendCommand
15 shutdownPort
16 getPortCount
17 togglePort
18 disableAllPorts
19 getDeviceState
20 );
21
22 my $run_sequence = 0;
23 GetOptions('sequence' => \$run_sequence);
24
25
26 sub main_sequence {
27 # ---- begin main -----
28 # NOPs senden
29 sendCommand('NOP');
30 #sendCommand('NOP');
31
32 # SETUP
33 sendCommand('SETUP');
34
35 #sendCommand('SET PORT', 16);
36
37 enablePort(1);
38 enablePort(2);
39
40 enablePort(6);
41 enablePort(7);
42
43 disablePort(6);
44 disablePort(1);
45
46 #sendCommand('GET PORT');
47 #sendCommand('GET OPTION');
48 # ---- end main -----
49 }
50
51 sub start {
52 sendCommand('SETUP');
53 ReadMode 4; # Turn off controls keys
54 }
55
56 sub stop {
57 ReadMode 1;
58 shutdownPort();
59 }
60
61 sub recieveKey {
62 my $key = shift;
63
64 #print "got key: $key\n";
65
66 if (lc $key eq 'x') {
67 stop();
68 exit;
69
70 } elsif (lc $key eq 'r') {
71 disableAllPorts();
72
73 } elsif (lc $key eq 's') {
74 getDeviceState();
75
76 } elsif (lc $key eq 'h') {
77 usage();
78
79 } elsif ($key =~ m/\d/) {
80 togglePort($key);
81 }
82
83 }
84
85 sub usage {
86
87 my $portcount = getPortCount();
88
89 print "\n";
90 print "relais.pl - please control via keyboard", "\n";
91 print "toggle ports: 1-$portcount", "\n";
92 print "reset ports: r", "\n";
93 print "port-status: s", "\n";
94 print "help (this): h", "\n";
95 print "exit: x", "\n";
96 }
97
98 sub main_interactive {
99
100 start();
101
102 my $key;
103
104 usage();
105
106 while (1) {
107 while (not defined ($key = ReadKey(-1))) {
108 # No key yet
109 #sleep 1;
110 }
111 recieveKey($key);
112 #sleep 1;
113 }
114
115 }
116
117 if ($run_sequence) {
118 main_sequence();
119 } else {
120 main_interactive();
121 }

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed