Hardware-PortScanner
view release on metacpan or search on metacpan
PortScanner.pm view on Meta::CPAN
my $send;
my $baud;
my $parm;
my $value;
my $key;
my ( $databits, $parity, $stopbits, $handshake );
my $setting;
my $device;
my $config = $serial->{SEARCH_PARM} = {};
my $parm_found;
my $read_iterations;
my $iterations;
my $chars = 0;
my ( $bytes_read, $data_read );
my $waited;
$serial->_add_scan_log("Scan Ports Request");
$serial->_add_scan_log("==================");
# Parse parameters
while ( $parm = uc shift ) {
PortScanner.pm view on Meta::CPAN
{
DATABITS => 8,
PARITY => "none",
STOPBITS => 1,
HANDSHAKE => "none",
SETTING => "8N1"
}
);
}
# Figure the number of read iterations is needed
if ( exists( $config->{MAX_WAIT} ) ) {
$serial->_add_scan_log("(Max Wait set at $config->{MAX_WAIT})");
$read_iterations = int( $config->{MAX_WAIT} / ( $serial->{READ_CONST_TIME} / 1000 ) );
$read_iterations = 1 if ( $read_iterations < 1 );
}
else {
# Must always go though the loop once
$read_iterations = 1;
}
# Begin Scan of Com Ports
PORT:
foreach $com_port ( sort { $a <=> $b } @{ $config->{COM} } ) {
$com_device_name = $serial->_get_com_device_name($com_port);
$serial->_add_scan_log("Scan Port COM${com_port} @ $com_device_name");
PortScanner.pm view on Meta::CPAN
$feedback = "";
# Calculated outside loops for performance
$waited = 0;
# Wait a maximum amount of time to get expected output but move on
# if we dont get it in the alloted amount of time. This also protects
# us from a device just spewing data.
for ( $iterations = 1 ; $iterations <= $read_iterations ; $iterations++ ) {
# Read from the port
( $bytes_read, $data_read ) = $PortObj->read(255); # docs say this must be 255 always
$waited += $serial->{READ_CONST_TIME};
if ( $bytes_read > 0 ) {
$feedback .= $data_read;
# This is what makes this loop faster
last if ( $feedback =~ /$config->{VALID_REPLY_RE}/ );
( run in 2.282 seconds using v1.01-cache-2.11-cpan-71847e10f99 )