]> jspc29.x-matter.uni-frankfurt.de Git - daqtools.git/commitdiff
more comfortable serial polling loop in GW instek power supply remote control
authorMichael Wiebusch <stratomaster@gmx.net>
Wed, 17 Jul 2013 12:30:58 +0000 (14:30 +0200)
committerMichael Wiebusch <stratomaster@gmx.net>
Wed, 17 Jul 2013 12:30:58 +0000 (14:30 +0200)
web/htdocs/tools/pwr/pwr.pl

index 3699b5734352a41013c327080aac18ac1df128e3..bf13e3e71941ce7ac2e2b839afd3ac9690cb0da4 100755 (executable)
@@ -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 ="";