pyboard
¶
pyboard interface
This module provides the Pyboard class, used to communicate with and control a MicroPython device over a communication channel. Both real boards and emulated devices (e.g. running in QEMU) are supported. Various communication channels are supported, including a serial connection, telnet-style network connection, external process connection.
Example usage:
import pyboard pyb = pyboard.Pyboard(‘/dev/ttyACM0’)
Or:
pyb = pyboard.Pyboard(‘192.168.1.1’)
Then:
pyb.enter_raw_repl() pyb.exec(‘import pyb’) pyb.exec(‘pyb.LED(1).on()’) pyb.exit_raw_repl()
Note: if using Python2 then pyb.exec must be written as pyb.exec_. To run a script from the local machine on the board and print out the results:
import pyboard pyboard.execfile(‘test.py’, device=’/dev/ttyACM0’)
This script can also be run directly. To execute a local script, use:
./pyboard.py test.py
Or:
python pyboard.py test.py
Module Contents¶
Classes¶
Execute a process and emulate serial connection using its stdin/stdout. |
|
Execute a process which creates a PTY and prints slave PTY as |
|
Functions¶
|
|
|
|
|
Attributes¶
- pyboard.stdout¶
- pyboard.stdout_write_bytes(b)¶
- class pyboard.TelnetToSerial(ip, user, password, read_timeout=None)¶
- __del__(self)¶
- close(self)¶
- read(self, size=1)¶
- write(self, data)¶
- inWaiting(self)¶
- class pyboard.ProcessToSerial(cmd)¶
Execute a process and emulate serial connection using its stdin/stdout.
- close(self)¶
- read(self, size=1)¶
- write(self, data)¶
- inWaiting(self)¶
- class pyboard.ProcessPtyToTerminal(cmd)¶
Execute a process which creates a PTY and prints slave PTY as first line of its output, and emulate serial connection using this PTY.
- close(self)¶
- read(self, size=1)¶
- write(self, data)¶
- inWaiting(self)¶
- class pyboard.Pyboard(device, baudrate=115200, user='micro', password='python', wait=0, exclusive=True)¶
- close(self)¶
- read_until(self, min_num_bytes, ending, timeout=10, data_consumer=None)¶
- enter_raw_repl(self, soft_reset=True)¶
- exit_raw_repl(self)¶
- follow(self, timeout, data_consumer=None)¶
- raw_paste_write(self, command_bytes)¶
- exec_raw_no_follow(self, command)¶
- exec_raw(self, command, timeout=10, data_consumer=None)¶
- eval(self, expression)¶
- exec_(self, command, data_consumer=None)¶
- execfile(self, filename)¶
- get_time(self)¶
- fs_ls(self, src)¶
- fs_cat(self, src, chunk_size=256)¶
- fs_get(self, src, dest, chunk_size=256)¶
- fs_put(self, src, dest, chunk_size=256)¶
- fs_mkdir(self, dir)¶
- fs_rmdir(self, dir)¶
- fs_rm(self, src)¶
- pyboard.execfile(filename, device='/dev/ttyACM0', baudrate=115200, user='micro', password='python')¶
- pyboard.filesystem_command(pyb, args)¶
- pyboard._injected_import_hook_code = Multiline-String¶
Show Value
1import uos, uio 2class _FS: 3 class File(uio.IOBase): 4 def __init__(self): 5 self.off = 0 6 def ioctl(self, request, arg): 7 return 0 8 def readinto(self, buf): 9 buf[:] = memoryview(_injected_buf)[self.off:self.off + len(buf)] 10 self.off += len(buf) 11 return len(buf) 12 mount = umount = chdir = lambda *args: None 13 def stat(self, path): 14 if path == '_injected.mpy': 15 return tuple(0 for _ in range(10)) 16 else: 17 raise OSError(-2) # ENOENT 18 def open(self, path, mode): 19 return self.File() 20uos.mount(_FS(), '/_') 21uos.chdir('/_') 22from _injected import * 23uos.umount('/_') 24del _injected_buf, _FS
- pyboard.main()¶