Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to use IO::Select to test if there is anything for me to read from my serial port. I thought something like what I have below would work, but I was wrong.
my $serial = tie (*SD, 'Win32::SerialPort', $serial_config); my $serial_select = new IO::Select(); $serial_select->add(\*SD);
It gives an error that Win32::SerialPort has no FILENO method. Is there a way to get around this?

Replies are listed 'Best First'.
Re: Help using a tied filehandle from Win32::SerialPort in IO::Select
by BrowserUk (Patriarch) on Apr 13, 2007 at 13:40 UTC

    I'd suggest you look at the timeouts section of the docs where it says:

    Setting read_interval to 0xffffffff will do a non-blocking read. The ReadFile returns immediately whether or not any characters are actually read.

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Help using a tied filehandle from Win32::SerialPort in IO::Select
by ikegami (Patriarch) on Apr 13, 2007 at 13:22 UTC

    select is a system call. It's not something that Perl can easily emulate. Therefore, it only works on system handles. The system doesn't know anything about tied handles, so it would only be useful to add a FILENO method if the object wrapped a system handle.

    Furthermore, the Windows version (as opposed to the unix version) only supports sockets. It doesn't work on files, pipes or comm ports.

Re: Help using a tied filehandle from Win32::SerialPort in IO::Select
by Anonymous Monk on Apr 13, 2007 at 17:30 UTC
    Thank you both for the quick responses. It figures that Windows can't handle it. In previous code I've made the serial port non-blocking, but in this code I need to wait a few seconds for the hardware to respond. It might respond immediately, after a few seconds, or not at all. I was hoping to use something like
    $serial_select->can_read($timeout)
    This would let me give it a little time, but I guess now I have to learn how to use SIG{ALRM}. Is there something better? Oh I've also found that in Windows, I can't catch SIG{INT} when the code is blocking on a $socket->accept() call. I had to make the socket non-blocking and stick it in a while(1) loop. This is normal (at least for Windows), right?