From the Cookbook item under SerialPorts I have the following code snippet that works in a small test program (pretty much the Cookbook item:

    # Open a serial port, and tie it to a file handle for POE.

    my $handle = gensym();
    my $port = tie( *$handle, "Device::SerialPort", "/dev/ttyS0" );
    die "can't open port: $!" unless $port;

    $port->datatype('raw');
    $port->baudrate(9600);
    $port->databits(8);
    $port->parity("none");
    $port->stopbits(2);
    $port->handshake("xof");
    $port->write_settings();

    # Start interacting with the scanner.

    $heap->{port}       = $port;

    print"DEBUG: Before ReadWrite->new\n";

    $heap->{port_wheel} = POE::Wheel::ReadWrite->new(
        Handle => $handle,
        Filter => POE::Filter::Line->new(
            InputLiteral  => "\x0D\x0A",    # Received line endings.
            OutputLiteral => "\x0D",        # Sent line endings.
        ),
        InputEvent => "got_port",
        ErrorEvent => "got_error",
                                                     );

    print"DEBUG: After ReadWrite->new\n";

However, when I incorporate this in a Tk based application I get the following output/error:

DEBUG: Before ReadWrite->new
Handle not opened for input at /usr/lib/perl5/vendor_perl/5.8.8/i686-linux/Tk/Event/IO.pm line 122.

In the that file, line 122 is the first code line in this snippet:

   # set the handler
   my $h = $obj->handler($imode,$cb);
   undef $obj;  # Prevent warnings about untie with ref to object
   unless ($h)
    {
     untie *$file;
    }


Any ideas?

Thanks,

John

Reply via email to