Marais has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Destroying tied serial port
by Marais (Novice) on Dec 23, 2012 at 22:00 UTC | |
by roboticus (Chancellor) on Dec 24, 2012 at 00:03 UTC | |
|
Re: Destroying tied serial port
by jmlynesjr (Deacon) on Dec 24, 2012 at 02:23 UTC |