Thread Script für RS232
(10 answers)
Opened by Manne at 2008-02-09 12:12
Das Script demo8.plx aus dem Verzeichnis eg von SerialPort-0.19 zeigt doch wie es geht.
Von der Tastatur einlesen und dann an die serielle Schnittstelle senden/empfangen. Code (perl): (dl
)
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 #!perl -w # # Simple command-line terminal emulator # by Andrej Mikus # with small modifications by Bill Birthisel # no local echo at either end # require 5.005; # for select use Win32::SerialPort 0.14; use Term::ReadKey; use strict; my $cfgfile = "COM1_test.cfg"; my $ob = Win32::SerialPort->start ($cfgfile) or die "Can't start $cfgfile\n"; # next test will die at runtime unless $ob ### setup for dumb terminal, your mileage may vary $ob->stty_icrnl(1); $ob->stty_ocrnl(1); $ob->stty_onlcr(1); $ob->stty_opost(1); ### my $c; my $p1 = "Simple Terminal Emulator\n"; $p1 .= "Type CAPITAL Q to quit\n\n"; print $p1; $p1 =~ s/\n/\r\n/ogs if ($ob->stty_opost && $ob->stty_onlcr); $ob->write ($p1); for ( ;; ) { if ( $c = $ob -> input ) { $c =~ s/\r/\n/ogs if ($ob->stty_icrnl); print $c; last if $c =~ /Q/; } if ( defined ( $c = ReadKey ( -1 ) ) ) { $c =~ s/\r/\n/ogs if ($ob->stty_ocrnl); $c =~ s/\n/\r\n/ogs if ($ob->stty_opost && $ob->stty_onlcr); $ob -> write ( $c ); last if $c eq 'Q'; } select undef, undef, undef, 0.2; # traditional 5/sec. } $ob -> close or die "Close failed: $!\n"; undef $ob; # closes port AND frees memory in perl Quelle: http://members.aol.com/bbirthisel/alpha.html Aus der Zipdatei SerialPort-0_19.zip |