@@ -23,7 +23,7 @@ def enumerate_serial_ports():
2323 try :
2424 key = winreg .OpenKey (winreg .HKEY_LOCAL_MACHINE , path )
2525 except WindowsError :
26- raise IterationError
26+ raise Exception
2727
2828 for i in itertools .count ():
2929 try :
@@ -66,7 +66,7 @@ def find_port(baud, timeout):
6666 log .debug ('Found {0}, testing...' .format (p ))
6767 try :
6868 sr = serial .Serial (p , baud , timeout = timeout )
69- except serial .serialutil .SerialException , e :
69+ except serial .serialutil .SerialException as e :
7070 log .debug (str (e ))
7171 continue
7272 time .sleep (2 )
@@ -96,8 +96,8 @@ class Arduino(object):
9696
9797 def __init__ (self , baud = 9600 , port = None , timeout = 2 , sr = None ):
9898 """
99- Initializes serial communication with Arduino if no connection is given.
100- Attempts to self-select COM port, if not specified.
99+ Initializes serial communication with Arduino if no connection is
100+ given. Attempts to self-select COM port, if not specified.
101101 """
102102 if not sr :
103103 if not port :
@@ -316,23 +316,27 @@ def Melody(self, pin, melody, durations):
316316 Playing short melodies (1 or 2 tones) didn't cause
317317 trouble during testing
318318 """
319- NOTES = dict (B0 = 31 ,C1 = 33 ,CS1 = 35 ,D1 = 37 ,DS1 = 39 ,E1 = 41 ,F1 = 44 ,FS1 = 46 ,G1 = 49 \
320- ,GS1 = 52 ,A1 = 55 ,AS1 = 58 ,B1 = 62 ,C2 = 65 ,CS2 = 69 ,D2 = 73 ,DS2 = 78 ,E2 = 82 \
321- ,F2 = 87 ,FS2 = 93 ,G2 = 98 ,GS2 = 104 ,A2 = 110 ,AS2 = 117 ,B2 = 123 ,C3 = 131 \
322- ,CS3 = 139 ,D3 = 147 ,DS3 = 156 ,E3 = 165 ,F3 = 175 ,FS3 = 185 ,G3 = 196 ,GS3 = 208 \
323- ,A3 = 220 ,AS3 = 233 ,B3 = 247 ,C4 = 262 ,CS4 = 277 ,D4 = 294 ,DS4 = 311 ,E4 = 330 \
324- ,F4 = 349 ,FS4 = 370 ,G4 = 392 ,GS4 = 415 ,A4 = 440 ,AS4 = 466 ,B4 = 494 ,C5 = 523 \
325- ,CS5 = 554 ,D5 = 587 ,DS5 = 622 ,E5 = 659 ,F5 = 698 ,FS5 = 740 ,G5 = 784 ,GS5 = 831 \
326- ,A5 = 880 ,AS5 = 932 ,B5 = 988 ,C6 = 1047 ,CS6 = 1109 ,D6 = 1175 ,DS6 = 1245 ,E6 = 1319 \
327- ,F6 = 1397 ,FS6 = 1480 ,G6 = 1568 ,GS6 = 1661 ,A6 = 1760 ,AS6 = 1865 ,B6 = 1976 ,C7 = 2093 \
328- ,CS7 = 2217 ,D7 = 2349 ,DS7 = 2489 ,E7 = 2637 ,F7 = 2794 ,FS7 = 2960 ,G7 = 3136 \
329- ,GS7 = 3322 ,A7 = 3520 ,AS7 = 3729 ,B7 = 3951 ,C8 = 4186 ,CS8 = 4435 ,D8 = 4699 ,DS8 = 4978 )
330- if (type (melody ) == list ) and (type (durations ) == list ):
319+ NOTES = dict (
320+ B0 = 31 , C1 = 33 , CS1 = 35 , D1 = 37 , DS1 = 39 , E1 = 41 , F1 = 44 , FS1 = 46 , G1 = 49 ,
321+ GS1 = 52 , A1 = 55 , AS1 = 58 , B1 = 62 , C2 = 65 , CS2 = 69 , D2 = 73 , DS2 = 78 , E2 = 82 ,
322+ F2 = 87 , FS2 = 93 , G2 = 98 , GS2 = 104 , A2 = 110 , AS2 = 117 , B2 = 123 , C3 = 131 ,
323+ CS3 = 139 , D3 = 147 , DS3 = 156 , E3 = 165 , F3 = 175 , FS3 = 185 , G3 = 196 , GS3 = 208 ,
324+ A3 = 220 , AS3 = 233 , B3 = 247 , C4 = 262 , CS4 = 277 , D4 = 294 , DS4 = 311 , E4 = 330 ,
325+ F4 = 349 , FS4 = 370 , G4 = 392 , GS4 = 415 , A4 = 440 ,
326+ AS4 = 466 , B4 = 494 , C5 = 523 , CS5 = 554 , D5 = 587 , DS5 = 622 , E5 = 659 , F5 = 698 ,
327+ FS5 = 740 , G5 = 784 , GS5 = 831 , A5 = 880 , AS5 = 932 , B5 = 988 , C6 = 1047 ,
328+ CS6 = 1109 , D6 = 1175 , DS6 = 1245 , E6 = 1319 , F6 = 1397 , FS6 = 1480 , G6 = 1568 ,
329+ GS6 = 1661 , A6 = 1760 , AS6 = 1865 , B6 = 1976 , C7 = 2093 , CS7 = 2217 , D7 = 2349 ,
330+ DS7 = 2489 , E7 = 2637 , F7 = 2794 , FS7 = 2960 , G7 = 3136 , GS7 = 3322 , A7 = 3520 ,
331+ AS7 = 3729 , B7 = 3951 , C8 = 4186 , CS8 = 4435 , D8 = 4699 , DS8 = 4978 )
332+ if (isinstance (melody , list )) and (isinstance (durations , list )):
331333 length = len (melody )
332334 cmd_args = [length , pin ]
333335 if length == len (durations ):
334- cmd_args .extend ([NOTES .get (melody [note ]) for note in range (length )])
335- cmd_args .extend ([durations [duration ] for duration in range (len (durations ))])
336+ cmd_args .extend ([NOTES .get (melody [note ])
337+ for note in range (length )])
338+ cmd_args .extend ([durations [duration ]
339+ for duration in range (len (durations ))])
336340 cmd_str = build_cmd_str ("to" , cmd_args )
337341 try :
338342 self .sr .write (cmd_str )
@@ -365,8 +369,8 @@ def capacitivePin(self, pin):
365369 '''
366370 cmd_str = build_cmd_str ("cap" , (pin ,))
367371 self .sr .write (cmd_str )
368- rd = self .sr .readline ().replace ("\r \n " ,"" )
369- if rd .isdigit () == True :
372+ rd = self .sr .readline ().replace ("\r \n " , "" )
373+ if rd .isdigit ():
370374 return int (rd )
371375
372376 def shiftOut (self , dataPin , clockPin , pinOrder , value ):
@@ -380,7 +384,7 @@ def shiftOut(self, dataPin, clockPin, pinOrder, value):
380384 value (int): an integer from 0 and 255
381385 """
382386 cmd_str = build_cmd_str ("so" ,
383- (dataPin , clockPin , pinOrder , value ))
387+ (dataPin , clockPin , pinOrder , value ))
384388 self .sr .write (cmd_str )
385389 self .sr .flush ()
386390
@@ -398,30 +402,35 @@ def shiftIn(self, dataPin, clockPin, pinOrder):
398402 cmd_str = build_cmd_str ("si" , (dataPin , clockPin , pinOrder ))
399403 self .sr .write (cmd_str )
400404 self .sr .flush ()
401- rd = self .sr .readline ().replace ("\r \n " ,"" )
402- if rd .isdigit () == True :
405+ rd = self .sr .readline ().replace ("\r \n " , "" )
406+ if rd .isdigit ():
403407 return int (rd )
404408
405409
406410class Shrimp (Arduino ):
411+
407412 def __init__ (self ):
408413 Arduino .__init__ (self )
409414
410415
411416class Wires (object ):
417+
412418 """
413419 Class for Arduino wire (i2c) support
414420 """
421+
415422 def __init__ (self , board ):
416423 self .board = board
417424 self .sr = board .sr
418425
419426
420427class Servos (object ):
428+
421429 """
422430 Class for Arduino servo support
423431 0.03 second delay noted
424432 """
433+
425434 def __init__ (self , board ):
426435 self .board = board
427436 self .sr = board .sr
@@ -434,7 +443,7 @@ def attach(self, pin, min=544, max=2400):
434443 self .sr .write (cmd_str )
435444 self .sr .flush ()
436445
437- rd = self .sr .readline ().replace ("\r \n " ,"" )
446+ rd = self .sr .readline ().replace ("\r \n " , "" )
438447 if rd :
439448 break
440449 else :
@@ -477,7 +486,7 @@ def read(self, pin):
477486 self .sr .flush ()
478487 except :
479488 pass
480- rd = self .sr .readline ().replace ("\r \n " ,"" )
489+ rd = self .sr .readline ().replace ("\r \n " , "" )
481490 try :
482491 angle = int (rd )
483492 return angle
@@ -486,9 +495,11 @@ def read(self, pin):
486495
487496
488497class SoftwareSerial (object ):
498+
489499 """
490500 Class for Arduino software serial functionality
491501 """
502+
492503 def __init__ (self , board ):
493504 self .board = board
494505 self .sr = board .sr
@@ -505,7 +516,7 @@ def begin(self, p1, p2, baud):
505516 self .sr .flush ()
506517 except :
507518 pass
508- response = self .sr .readline ().replace ("\r \n " ,"" )
519+ response = self .sr .readline ().replace ("\r \n " , "" )
509520 if response == "ss OK" :
510521 self .connected = True
511522 return True
@@ -525,7 +536,7 @@ def write(self, data):
525536 self .sr .flush ()
526537 except :
527538 pass
528- response = self .sr .readline ().replace ("\r \n " ,"" )
539+ response = self .sr .readline ().replace ("\r \n " , "" )
529540 if response == "ss OK" :
530541 return True
531542 else :
@@ -540,7 +551,7 @@ def read(self):
540551 cmd_str = build_cmd_str ("sr" )
541552 self .sr .write (cmd_str )
542553 self .sr .flush ()
543- response = self .sr .readline ().replace ("\r \n " ,"" )
554+ response = self .sr .readline ().replace ("\r \n " , "" )
544555 if response :
545556 return response
546557 else :
0 commit comments