From: Michael Wiebusch Date: Wed, 17 Jul 2013 12:30:58 +0000 (+0200) Subject: more comfortable serial polling loop in GW instek power supply remote control X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=497f20dfffe5ebfb8c74ddfd90f478184e23d29d;p=daqtools.git more comfortable serial polling loop in GW instek power supply remote control --- 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 ="";