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
#!/usr/bin/perl -w use IO::Async::Listener; use Device::SerialPort; use IO::Async::Loop; my $loop = IO::Async::Loop->new; my $port = Device::SerialPort->new("/dev/ttyUSB1"); $| = 1; my $listener = IO::Async::Listener->new( on_stream => sub { my ( undef, $stream ) = @_; $stream->configure( on_read => sub { my ( $self, $buffref, $eof ) = @_; $self->write( $$buffref ); $$buffref = ""; return 0; }, ); $loop->add( $stream ); }, ); $loop->add( $listener ); $listener->listen( addr => { family => "inet", socktype => "stream", port => 8000, ip => "localhost", }, on_listen => sub { my ( $listener ) = @_; my $socket = $listener->read_handle; print "Now listening on port ".$socket->sockport; }, on_listen_error => sub { print "Now listening on port "; }, ); while (1) { sleep(3); print "."; # Hier kommt dann die Serial-Meldung hin an einen TCP-Server was vom Device kommt an Output. }