Rev 699 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 699 | Rev 702 | ||
---|---|---|---|
Line 260... | Line 260... | ||
260 | self.serPort.write(ln) |
260 | self.serPort.write(ln) |
Line 261... | Line 261... | ||
261 | 261 | ||
262 | def waitForLn(self): |
262 | def waitForLn(self): |
Line 263... | Line 263... | ||
263 | return self.serPort.readline(eol='\r') |
263 | return self.serPort.readline(eol='\r') |
264 | 264 | ||
265 | def waitForMsg(self, cmd2wait4): |
265 | def waitForMsg(self, cmd2wait4, timeout=0.5): |
- | 266 | msg = None |
|
- | 267 | done = False |
|
266 | msg = None |
268 | if self.printDebugMsg: print "[Debug] =>Wait4 %s TO=%.1fs" % (cmd2wait4, timeout) |
267 | done = False |
269 | startTime = time.clock() |
268 | while (not done): |
- | |
269 | line = self.waitForLn() |
- | |
270 | if len(line) == 0: |
270 | while (not done): |
271 | raise NoResponse(cmd2wait4) |
271 | line = self.waitForLn() |
- | 272 | try: |
|
272 | try: |
273 | msg = MkMsg(msg=line) |
273 | msg = MkMsg(msg=line) |
274 | if self.printDebugMsg: print "[Debug] msg %s" % msg.cmd |
274 | if (msg.cmd == cmd2wait4): |
275 | if (msg.cmd == cmd2wait4): |
275 | done = True |
276 | done = True |
- | 277 | except InvalidMsg: |
|
276 | except InvalidMsg: |
278 | if self.printDebugMsg: print "[Debug] no valid msg" |
277 | if self.printDebugMsg: |
279 | |
- | 280 | if ((time.clock()-startTime) > timeout): |
|
278 | print "DebugMsg: \"%s\"" % line[:-1] |
281 | raise NoResponse(cmd2wait4) |
Line 279... | Line 282... | ||
279 | pass |
282 | if self.printDebugMsg: print "[Debug] Done: %.1fs" % (time.clock()-startTime) |
280 | return msg |
283 | return msg |
Line 290... | Line 293... | ||
290 | # No reply expected... |
293 | # No reply expected... |
Line 291... | Line 294... | ||
291 | 294 | ||
292 | def sendSettings(self, settings): |
295 | def sendSettings(self, settings): |
293 | msg = MkMsg(address=MkComm.ADDRESS_FC, cmd='s', data=settings) |
296 | msg = MkMsg(address=MkComm.ADDRESS_FC, cmd='s', data=settings) |
294 | self.sendMsg(msg) |
297 | self.sendMsg(msg) |
295 | time.sleep(1) |
298 | #time.sleep(1) |
Line 296... | Line 299... | ||
296 | msg = self.waitForMsg('S') |
299 | msg = self.waitForMsg('S', timeout=2) |
297 | 300 | ||
298 | def getDebugMsg(self): |
301 | def getDebugMsg(self): |
299 | self.serPort.flushInput() |
302 | self.serPort.flushInput() |
Line 337... | Line 340... | ||
337 | 340 | ||
338 | 341 | ||
339 | if __name__ == '__main__': |
342 | if __name__ == '__main__': |
- | 343 | try: |
|
340 | try: |
344 | comm = MkComm() |
Line 341... | Line 345... | ||
341 | comm = MkComm() |
345 | comm.printDebugMsg = True |
342 | comm.open(comPort="COM5") |
346 | comm.open(comPort="COM5") |
Line 350... | Line 354... | ||
350 | print "StickP=",msg.getSetting(SettingsMsg.IDX_STICK_P) |
354 | print "StickP=",msg.getSetting(SettingsMsg.IDX_STICK_P) |
351 | print "StickD=",msg.getSetting(SettingsMsg.IDX_STICK_D) |
355 | print "StickD=",msg.getSetting(SettingsMsg.IDX_STICK_D) |
Line 352... | Line 356... | ||
352 | 356 | ||
353 | msg.setSetting(SettingsMsg.IDX_STICK_P, msg.getSetting(SettingsMsg.IDX_STICK_P)+1) |
357 | msg.setSetting(SettingsMsg.IDX_STICK_P, msg.getSetting(SettingsMsg.IDX_STICK_P)+1) |
- | 358 | comm.sendSettings(msg.getSettings()) |
|
- | 359 | ||
Line 354... | Line 360... | ||
354 | comm.sendSettings(msg.getSettings()) |
360 | comm.doVibrationTest(100,5) |
355 | 361 | ||
356 | 362 |