- Timestamp:
- 12/01/10 10:54:20 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/brainstorms/Puzzlebox/Brainstorms/Wheelchair_Control.py
r228 r232 10 10 11 11 __changelog__ = """ 12 Last Update: 2010.11. 2912 Last Update: 2010.11.30 13 13 14 14 """ … … 17 17 import signal 18 18 #import parallel 19 import serial 19 20 20 21 ##################################################################### … … 85 86 output = data ^ int('00110011', 2) 86 87 #PORT.setData(output) 87 print 'Output set to: ', int2bin(output) 88 89 output = int2bin(output) 90 device.write('x%s' % output) 91 92 #print 'Output set to: ', int2bin(output) 93 print 'Output set to: ', output 88 94 print 'commands: i j k m to move, SPACE = stop, x = quit' 89 95 … … 107 113 return "".join([str((n >> y) & 1) for y in range(count-1, -1, -1)]) 108 114 115 ##################################################################### 116 117 def initializeSerial(): 118 baudrate = 9600 119 bytesize = 8 120 parity = 'NONE' 121 stopbits = 1 122 software_flow_control = 'f' 123 rts_cts_flow_control = 't' 124 #timeout = 15 125 timeout = 5 126 127 # convert bytesize 128 if (bytesize == 5): 129 init_byte_size = serial.FIVEBITS 130 elif (bytesize == 6): 131 init_byte_size = serial.SIXBITS 132 elif (bytesize == 7): 133 init_byte_size = serial.SEVENBITS 134 elif (bytesize == 8): 135 init_byte_size = serial.EIGHTBITS 136 else: 137 #self.log.perror("Invalid value for %s modem byte size! Using default (8)" % modem_type) 138 init_byte_size = serial.EIGHTBITS 139 140 # convert parity 141 if (parity == 'NONE'): 142 init_parity = serial.PARITY_NONE 143 elif (parity == 'EVEN'): 144 init_parity = serial.PARITY_EVEN 145 elif (parity == 'ODD'): 146 init_parity = serial.PARITY_ODD 147 else: 148 #self.log.perror("Invalid value for %s modem parity! Using default (NONE)" % modem_type) 149 init_parity = serial.PARITY_NONE 150 151 # convert stopbits 152 if (stopbits == 1): 153 init_stopbits = serial.STOPBITS_ONE 154 elif (stopbits == 2): 155 init_stopbits = serial.STOPBITS_TWO 156 else: 157 #self.log.perror("Invalid value for %s modem stopbits! Using default (8)" % modem_type) 158 init_byte_size = serial.STOPBITS_ONE 159 160 # convert software flow control 161 if (software_flow_control == 't'): 162 init_software_flow_control = 1 163 else: 164 init_software_flow_control = 0 165 166 # convert rts cts flow control 167 if (rts_cts_flow_control == 't'): 168 init_rts_cts_flow_control = 1 169 else: 170 init_rts_cts_flow_control = 0 171 172 device = serial.Serial(port = '/dev/ttyACM0', \ 173 baudrate = baudrate, \ 174 bytesize = init_byte_size, \ 175 parity = init_parity, \ 176 stopbits = init_stopbits, \ 177 xonxoff = init_software_flow_control, \ 178 rtscts = init_rts_cts_flow_control, \ 179 timeout = timeout) 180 181 device.write('x00110011') 182 print "sent stop" 183 time.sleep(2) 184 print "slept 2" 185 186 return(device) 187 109 188 110 189 ##################################################################### 111 190 # Main 112 191 ##################################################################### 192 193 device = initializeSerial() 113 194 114 195 MYGETCH = Getch()
Note: See TracChangeset
for help on using the changeset viewer.