262,21 → 262,24 |
def waitForLn(self): |
return self.serPort.readline(eol='\r') |
|
def waitForMsg(self, cmd2wait4): |
def waitForMsg(self, cmd2wait4, timeout=0.5): |
msg = None |
done = False |
if self.printDebugMsg: print "[Debug] =>Wait4 %s TO=%.1fs" % (cmd2wait4, timeout) |
startTime = time.clock() |
while (not done): |
line = self.waitForLn() |
if len(line) == 0: |
raise NoResponse(cmd2wait4) |
try: |
msg = MkMsg(msg=line) |
if self.printDebugMsg: print "[Debug] msg %s" % msg.cmd |
if (msg.cmd == cmd2wait4): |
done = True |
except InvalidMsg: |
if self.printDebugMsg: |
print "DebugMsg: \"%s\"" % line[:-1] |
pass |
if self.printDebugMsg: print "[Debug] no valid msg" |
|
if ((time.clock()-startTime) > timeout): |
raise NoResponse(cmd2wait4) |
if self.printDebugMsg: print "[Debug] Done: %.1fs" % (time.clock()-startTime) |
return msg |
|
def sendMsg(self, msg): |
292,8 → 295,8 |
def sendSettings(self, settings): |
msg = MkMsg(address=MkComm.ADDRESS_FC, cmd='s', data=settings) |
self.sendMsg(msg) |
time.sleep(1) |
msg = self.waitForMsg('S') |
#time.sleep(1) |
msg = self.waitForMsg('S', timeout=2) |
|
def getDebugMsg(self): |
self.serPort.flushInput() |
339,6 → 342,7 |
if __name__ == '__main__': |
try: |
comm = MkComm() |
comm.printDebugMsg = True |
comm.open(comPort="COM5") |
|
msg = comm.getVersionMsg() |
352,6 → 356,8 |
|
msg.setSetting(SettingsMsg.IDX_STICK_P, msg.getSetting(SettingsMsg.IDX_STICK_P)+1) |
comm.sendSettings(msg.getSettings()) |
|
comm.doVibrationTest(100,5) |
|
|
except Exception,e: |