Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
how to close a comport in perl?

Posted by vinzy1983 (vinzy1983), 24 January 2006
Hi,
Can anyone tell me how to close a comport in perl?
i tried using "undef $PortObj;" but it is not working properly.

i also made an unsuccessful attempt of using the following close funciton.
 $PortObj->close || warn "close failed";

Could anyone please help me out?

Thanks
-Vinay



Posted by admin (Graham Ellis), 24 January 2006
Good question ... but a bit of a different niche to the ones I'm most familiar with.    I'm guessing that your $PortObj variable is a reference to an object.   What type of object?  From a CPAN module or from a Windows distribution of Perl such as Activestate?

Also the term "not working properly" doesn't really tell us what's going wrong.   My understanding of a COM port is that you send characters over it from a program and at that low level there's really nothing to do when you don't want it any longer - just stop writing to it.    If you've got higher level drivers that buffer or lock the port then, yes, I can understand that there may be a bit more to closing the device.

Sorry to answer one question with another, but I need a bit more to have any chance of making any form of reasonable suggestion.

Posted by vinzy1983 (vinzy1983), 25 January 2006
Hi,
sorry for the insufficient description.

First of all, i use Activestate perl on windows platform.

Actually, i have a tool to run my perl scripts(which uses comport) under regression which runs for 2-3 days.
The problem i'm facing is the serial port gets locked up after sometime.
So for this i thought i should close the comport at the end of each of the scripts, which i could not accomplish.

I used a END block in the scripts as,
END {
      undef $comPort;
}

but this has not improved the situation.

And with $PortObj->close, i am facing syntax errors as i am not able to frame the close function properly using the comport object. I used the following combinations by referring the serialport.pm file in my activestate perl.
#################################
$comPort->{ALIAS} = "MYF";
$comPort=>'_port'->Win32::SerialPort::close || warn "close failed";
################################
$comPort=>'_port'->Win32::SerialPort::close(\$comPort=>{'_port'}) || warn "close failed";
Win32::SerialPort::close($comPort) || warn "close failed \n";
#################################

thanks
-Vinay




This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2012: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho