sub Read { my $self = shift; my $bytes = shift; my $response = ''; my $bytes_read = 0; my $now = scalar gettimeofday(); my $waitfor = $now + (($delay * 4) / 1000000); while( length($response) < $bytes || $now < $waitfor ) { my ($count_read, $chars) = $port->read($bytes - length($response)); $now = scalar gettimeofday(); if ($count_read > 0) { $response .= $chars; $waitfor = scalar gettimeofday() + (($delay * 4) / 1000000); } elsif ( $now < $waitfor ) { usleep($delay); } } return $result; }