src/eric7/MicroPython/MicroPythonDeviceInterface.py

branch
mpy_network
changeset 9989
286c2a21f36f
parent 9826
9340ce7fb12f
child 9990
54c614d91eff
equal deleted inserted replaced
9988:1ba9d07ba9da 9989:286c2a21f36f
425 err = b"" 425 err = b""
426 426
427 self.__blockReadyRead = False 427 self.__blockReadyRead = False
428 return out, err 428 return out, err
429 429
430 def executeAsync(self, commandsList): 430 def executeAsync(self, commandsList, submitMode):
431 """ 431 """
432 Public method to execute a series of commands over a period of time 432 Public method to execute a series of commands over a period of time
433 without returning any result (asynchronous execution).
434
435 @param commandsList list of commands to be execute on the device
436 @type list of str
437 @param submitMode mode to be used to submit the commands
438 @type str (one of 'raw' or 'paste')
439 @exception ValueError raised to indicate an unknown submit mode
440 """
441 if submitMode not in ("raw", "paste"):
442 raise ValueError("Illegal submit mode given ({0})".format(submitMode))
443
444 if submitMode == "raw":
445 startSequence = [ # sequence of commands to enter raw mode
446 b"\x02", # Ctrl-B: exit raw repl (just in case)
447 b"\r\x03\x03\x03", # Ctrl-C three times: interrupt any running program
448 b"\r\x01", # Ctrl-A: enter raw REPL
449 b'print("\\n")\r',
450 ]
451 endSequence = [
452 b"\r",
453 b"\x04",
454 ]
455 self.__executeAsyncRaw(
456 startSequence
457 + [c.encode("utf-8") + b"\r" for c in commandsList]
458 + endSequence
459 )
460 elif submitMode == "paste":
461 self.__executeAsyncPaste(commandsList)
462
463 def __executeAsyncRaw(self, commandsList):
464 """
465 Private method to execute a series of commands over a period of time
433 without returning any result (asynchronous execution). 466 without returning any result (asynchronous execution).
434 467
435 @param commandsList list of commands to be execute on the device 468 @param commandsList list of commands to be execute on the device
436 @type list of bytes 469 @type list of bytes
437 """ 470 """
438 if commandsList: 471 if commandsList:
439 command = commandsList.pop(0) 472 command = commandsList.pop(0)
440 self.__serial.write(command) 473 self.__serial.write(command)
441 QTimer.singleShot(2, lambda: self.executeAsync(commandsList)) 474 QTimer.singleShot(2, lambda: self.__executeAsyncRaw(commandsList))
442 else: 475 else:
476 self.__rawOff()
443 self.executeAsyncFinished.emit() 477 self.executeAsyncFinished.emit()
444 478
445 def executeAsyncPaste(self, commandsList): 479 def __executeAsyncPaste(self, commandsList):
446 """ 480 """
447 Public method to execute a series of commands over a period of time 481 Private method to execute a series of commands over a period of time
448 without returning any result (asynchronous execution). 482 without returning any result (asynchronous execution).
449 483
450 @param commandsList list of commands to be execute on the device 484 @param commandsList list of commands to be execute on the device
451 @type list of bytes 485 @type list of str
452 """ 486 """
453 if commandsList: 487 self.__blockReadyRead = True
454 self.__blockReadyRead = True 488 self.__pasteOn()
455 command = commandsList.pop(0) 489 command = b"\n".join(c.encode("utf-8)") for c in commandsList)
456 if command == "@PasteOn@": 490 self.__serial.write(command)
457 self.__pasteOn() 491 self.__serial.readUntil(command)
458 else: 492 self.__blockReadyRead = False
459 self.__serial.write(command) 493 self.__pasteOff()
460 self.__serial.readUntil(command) 494 self.executeAsyncFinished.emit
461 QTimer.singleShot(2, lambda: self.executeAsyncPaste(commandsList))
462 else:
463 self.__blockReadyRead = False
464 self.__pasteOff()
465 self.executeAsyncFinished.emit()

eric ide

mercurial