I'm developing an application which communicates with an Arduino via USB. It runs in a POE environment. I use the Device::SerialPort module to talk to the USB port (as a file).
At times I want to close the connection (when certain errors occur) and re-open it. So far, closing the connection is not working for me. Here's how I open it:
use Symbol qw(gensym); use Device::SerialPort; (etc.) my $port, $handle; $handle = gensym(); $port = tie(*$handle, "Device::SerialPort", "/dev/ttyUSB0"); $port->baudrate(57600); (etc.)
By passing $handle to a POE ReadWrite wheel, I can communicate perfectly with the Arduino. I use the following code to try to close the connection, prior to re-opening it:
$port->close; undef $port; untie *$handle;
and this results in the error message:
<fh> select error: Bad file descriptor (hits=-1)
I have to admit that I don't understand what the "gensym" and "tie" stuff is all about; I'm just following the examples in the documentation, so it's almost certainly due to my ignorance. Can anyone explain how to properly close this port?
In reply to Destroying tied serial port by Marais
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |