in reply to Difficulties with Device::SerialPort

Assuming "Error #9" is a standard Unix error, it's EBADF, or "Bad file number". That probably means the device isn't being opened properly. Are you checking for possible errors after opening the device? Can you get your program down to a few lines that demonstrate the problem, and post that here?
  • Comment on Re: Difficulties with Device::SerialPort

Replies are listed 'Best First'.
Re^2: Difficulties with Device::SerialPort
by EvanK (Chaplain) on Sep 07, 2005 at 15:30 UTC
    hmmm...I've tried this two ways, one with jsut the built-in i/o methods, and another way with a tied filehandle. here's what i'm usign right now:
    # note, ive tried ttyS0 and S1, same error with both $port = '/dev/ttyS0'; # creates a hidden config file in user's home dir $config = '~/.conf'; # this tests for an existing config file, # and creates one if necessary... if(! -e $config) { $PortObj = new Device::SerialPort ($port) || die(RED,"Can't open $port: $^E\n",RESET); $PortObj->databits(7); $PortObj->baudrate(19200); $PortObj->parity("even"); $PortObj->stopbits(1); $PortObj->handshake("xoff"); $PortObj->buffers(4096, 4096); $PortObj->write_settings || undef $PortObj; $PortObj->save("$config"); $PortObj->close || die(RED,"failed to close",RESET); undef $PortObj; } # and this connects to the port by loading said # config file and tying to SERIAL filehandle $PortObj = tie (*SERIAL, 'Device::SerialPort', "$config") || die(RED,"Can't open $port: $^E\n",RESET); # use non-blocking read on serial port $PortObj->read_char_time(5); $PortObj->read_const_time(500); # create flag variables initialized to zero... my $EXIT = 0; # ...when a trapped system signal is sent, set flag to 1 $SIG{'INT'} = sub { $EXIT = 1 };
    i've used this before with a tied filehandle, so it should work.

    __________
    Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
    - Terry Pratchett

      While, probably somewhat lateral to your current problem, please be aware that despite documentation to the contrary, the tied-handle interfaces of the Win32::SerialPort and Device::SerialPort modules are not the same - If you have a read through the source for Device::SerialPort, you will find that the TIEHANDLE subroutine calls the new method in place of the start method as what occurs in Win32::SerialPort - A convenience in Device::SerialPort which means that you do not need to have a configuration file for the serial port previously written, but one which breaks compatability with Win32::SerialPort.

       

      perl -le "print unpack'N', pack'B32', '00000000000000000000001000000000'"