From 497f20dfffe5ebfb8c74ddfd90f478184e23d29d Mon Sep 17 00:00:00 2001 From: Michael Wiebusch Date: Wed, 17 Jul 2013 14:30:58 +0200 Subject: [PATCH] more comfortable serial polling loop in GW instek power supply remote control --- web/htdocs/tools/pwr/pwr.pl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/web/htdocs/tools/pwr/pwr.pl b/web/htdocs/tools/pwr/pwr.pl index 3699b57..bf13e3e 100755 --- a/web/htdocs/tools/pwr/pwr.pl +++ b/web/htdocs/tools/pwr/pwr.pl @@ -99,11 +99,12 @@ sub receive_answer { # clear buffers, then send the "list"-command to the power supply $port->lookclear; $port->write("L\r"); - # sleep a second to give the supply time to react - usleep 1E5; - # read what has accumulated in the serial buffer - while(my $a = $port->lookfor) { + + # do polling for 5 seconds, break polling as soon as answer was received + my $i; + for ($i = 0; ($i<500) ;$i++) { + my $a = $port->lookfor; #print $a."\n"; # debug output if ($a =~ m/V(\d\d\.\d\d)A(\d\.\d\d\d)W(\d\d\d\.\d)U(\d\d)I(\d\.\d\d)P(\d\d\d)F(\d\d\d\d\d\d)/) { $found = 1; @@ -145,9 +146,11 @@ sub receive_answer { last; + } else { + usleep 1E4; # 10 ms delay } } - } +} sub receive_answer_HMP { my $ret =""; -- 2.43.0