Commits

Tino de Bruijn  committed 4213b9a

Catch too high port or pin numbers

  • Participants
  • Parent commits 21d0858

Comments (0)

Files changed (1)

File pyfirmata/pyfirmata.py

     def _handle_analog_message(self, pin_nr, lsb, msb):
         value = float((msb << 7) + lsb) / 1023
         # Only set the value if we are actually reporting
-        if self.analog[pin_nr].reporting:
-            self.analog[pin_nr].value = value
+        try:
+            if self.analog[pin_nr].reporting:
+                self.analog[pin_nr].value = value
+        except IndexError:
+            raise ValueError
         return True
 
     def _handle_digital_message(self, port_nr, lsb, msb):
         bitmask wich we update the port.
         """
         mask = (msb << 7) + lsb
-        self.digital_ports[port_nr]._update(mask)
+        try:
+            self.digital_ports[port_nr]._update(mask)
+        except IndexError:
+            raise ValueError
         return True
 
     def _handle_report_version(self, major, minor):