6 A Interface with the hardware
11 from serial.serialutil
import SerialException
12 except Exception
as error:
15 except ImportError
as error:
16 print 'Install Pyserial'
18 if float(serial.VERSION) < 2.6:
19 print 'Upgrade Pyserial'
22 import device
as sensor
23 from mock
import MagicMock
31 Done with the ideia that all the interface happens
42 super(MSP, self).
__init__(tty, baud,
'N',
44 except SerialException:
45 print util.ROOT_MESSAGE
47 self.serial.setTimeout(1)
49 """FIXME: remove the code bellow in
50 production environment"""
52 self.serial.readline = util.randomstring
58 """ Return the value of a item """
60 return getattr(self,key).read_data()
62 return getattr(self,key).read_data(
't')
64 return getattr(self,key).data
69 """ Set a value of a item """
71 getattr(self,key).write_data(str(item))
74 """ Method to enable the micro """
78 """ Method to desable the micro """
82 if __name__ ==
'__main__':
85 print 'Available ports:'
86 PORTS_AVAILABLE = util.available_ports()
88 for i
in PORTS_AVAILABLE:
91 except TypeError, error:
92 print "None device connected"
96 if len(PORTS_AVAILABLE) == 1:
97 msp430 =
MSP(PORTS_AVAILABLE[0])
125 msp430.adc = sensor.Direction(msp430.serial,0)
126 print '\nADC data \n----------'
127 for x
in xrange(1,10):
130 msp430.guidao = sensor.Direction(msp430.serial,2)
131 print '\nGuidão data \n----------'
132 for x
in xrange(1,10):
133 print msp430[
'guidao']
135 msp430.freio = sensor.Freio(msp430.serial,3)
136 print '\nFreio data \n----------'
137 for x
in xrange(1,11):
138 print "Writinh %d..." %x,
140 print msp430[
'freio']
143 msp430.teste = sensor.Direction(msp430.serial,13)
144 print '\nTeste data \n----------'
145 for x
in xrange(1,10):
146 print msp430[
'teste']