[Melbourne-pm] Driving a serial command line device with Perl

Daniel Pittman daniel at rimspace.net
Mon Oct 9 17:39:19 PDT 2006


Craig Sanders <cas at taz.net.au> writes:
> On Wed, Oct 04, 2006 at 12:59:50PM +1000, Daniel Pittman wrote:
>> G'day.  I need to build a script wrapper around a command line device,
>> accessed via a serial port.
>> 
>> I know a bunch of ways to do this, from driving an external cu with
>> Expect, or implementing all that code myself with sysread and syswrite.
>
> no need to do that, there is a CPAN module called 'Expect' which
> re-implements Expect in perl.

That was the Expect I meant, and used. :)

>> All I really need is to connect to the device, write a few commands out
>> and read back the responses.  All pretty trivial, no complex buffering
>> needed, and all should be pretty easy to manage.
>> 
>> So, any suggestions on what the easy way to do this is?
>
> Expect.pm

...and now I have hit one odd problem.

I wanted to make sure that I issued a log-off command to the device and
drained any output correctly as part of the shutdown process for my
device wrapper class.

So, I figured that, hey, using the DESTROY method was a simple enough
way to ensure that this did the right thing, and much safer that forcing
every caller to remember to call a shutdown method.

My object was a blessed hash, containing the Expect object; very basic
stuff.

When my DESTROY method was called, though, the reference to the expect
object was always undef and, with debugging enabled, I could see that it
was destroyed immediately prior to my DESTROY method being called.


Have I missed something basic about Perl objects?  I thought DESTROY was
called before, not after, my contained objects were destroyed -- so I
could clean them up appropriately?

Regards,
        Daniel
-- 
Digital Infrastructure Solutions -- making IT simple, stable and secure
Phone: 0401 155 707        email: contact at digital-infrastructure.com.au
                 http://digital-infrastructure.com.au/


More information about the Melbourne-pm mailing list