fileevent bad filehadle error 
Author Message
 fileevent bad filehadle error

Hi,

I am trying to write a test harness to read from the serial port and
display results in a window.  I want to use fileevent to capture the
serial data as it arrives without blocking the gui.  I have tried the
following code and get the error

Tk::Error: Bad filehandle: FH at
/usr/lib/perl5/site_perl/5.005/i386-linux/Tk/IO.pm line 287.
 Tk::IO::fileevent at /usr/lib/perl5/site_perl/5.005/i386-linux/Tk/IO.pm
line 287
 SMSC_SIM::setup_fileevent at gui_layer.pm line 593

I am finding the lack of examples very frustrating - it has taken me a
couple of days to get this far - can anyone help, or point me to some
good docs?

Thanks,
Robin

#
# abstract of script
#
# Using Perl 5.005
# and perl/Tk 8.015
#

my $testing;
$testing = hardware_init($tty, $baud, $parity);
setup_fileevent();
MainLoop;
exit(0);

###########################

sub setup_fileevent {
  $mw->fileevent($testing, "readable", \&read_file);
  return(1);

Quote:
}

sub read_file {
  my $buf;

  if (eof($testing)) {
    #cancel binding
    $info_text->insert('end', "END_OF_FILE\n");
    # move to end
    $info_text->see('end');

    $mw->fileevent($testing, "readable", undef);
    return(1);
  }
  if (sysread ($testing, $buf, 1024)) {
    # Write text to window
    $info_text->insert('end', '-> ');
    $info_text->insert('end', $buf);
    # move to end
    $info_text->see('end');
  } else {
    # Sysread returned undef - problem with file
    $info_text->insert('end', "ERROR!");
    #cancel binding
    $mw->fileevent($testing, "readable", undef);

  }

  return(1);

Quote:
}

sub hardware_init {
  my $tty    = shift;
  my $baud   = shift;
  my $parity = shift;

  print "setting internal variables\n" if $SMSC_SIM::DEBUG;
  #
  # opening device
  #
  print "Opening Serial Device\n";

  $tty =~ /com(\d)/;
  # for Linux
  $dev_file = '/dev/ttyS' . $1;

  my $cfgfile = 'com.cfg';
  #
  # Use Device::SerialPort module - this allows us to tie a filehandle
  # to the serial port
  #
  my $PortObj = tie (*FH, 'Device::SerialPort', $cfgfile)
    || die "Can't tie using $cfgfile: $!\n";

  $PortObj->baudrate($baud);

  my $par;
  my $databits;
  if ($parity eq '71E') {
    $par = "even";
    $databits = 7;
  } else {
    $par = "odd";
    $databits = 8;
  }
  $PortObj->parity($par);
  $PortObj->databits($databits);
  $PortObj->stopbits(1);

  $PortObj->save($cfgfile)
    || warn "Can't save $cfgfile: $!\n";
  $PortObj->write_settings;

  $test = \*FH; ############ ahahhahahahaa this works
  return($test);

Quote:
}

Sent via Deja.com
http://www.*-*-*.com/


Sat, 28 Jun 2003 01:42:41 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. fileevent bad filehadle error

2. fileevent and X error

3. Fileevent - closing child -> X-Error

4. Q: How to prevent error report on bad open of pipe

5. Bad free() error?

6. Error in LWP [Bad arg length for Socket::unpack_sockaddr_in, length is 0, should be 16]

7. Bad free() error message from a perl script?

8. Bad free() error???

9. confusing error: "Bad free() ignored at ..."

10. Internal Error: Bad free()

11. "bad file descriptor" error

12. Bad free() error

 

 
Powered by phpBB® Forum Software