upytester.pyboard package

Submodules

upytester.pyboard.exceptions module

exception upytester.pyboard.exceptions.ResponseTimeoutException

Bases: Exception

Raised when no ‘ok’ response is received from the pyboard

upytester.pyboard.pyboard module

class upytester.pyboard.pyboard.PyBoard(serial_number, name=None, comport=None, auto_open=True)

Bases: object

The primary interface to a physical device running the upytester firmware.

Can also be used more passively to mount / unmount file-systems, get the device’s mountpoint (a folder name)

DEFAULT_BAUDRATE = 115200
READ_CHUNKSIZE = 1
READ_TIMEOUT = 0.1
RESPONSE_TIMEOUT = 1
WRITE_TIMEOUT = 0.1
close()
comport
classmethod connected_serial_numbers()
halt()
instruction_list
is_closed
is_open
mount_flash()

Mount on-board flash

Returns

path to mounted folder

Return type

str

mount_sd()

Mount SD card

Returns

path to mounted folder

Return type

str

mountpoint_flash

Directory of mounted on-board flash

mountpoint_sd

Directory of mounted SD card

open()
receive(timeout=None)

Receive object from remote.

If timeout is set, and nothing is received, None is returned after timeout.

Parameters

timeout (float) – Time to wait for a response (if None, will wait forever). If timeout is reached, None is returned.

Returns

decoded json object

Return type

dict, or None

receive_iter(timeout=None)

Generator for each received object.

Parameters

timeout (float) – Maximum time per iteration, if not set, only received objects will be returned.

reset(hard=False)

Soft Reset

A soft reset invokes the machine_reset() method by using the onboard upytester library. Obviously this will only work if there is funcitonal upytester firmware running on the pyboard’s SD card.

Hard Reset

A Ctrl+C character ext is sent to simulate a KeyboardInterrupt exception. Then, assuming a REPL has started on the pyboard, these commands are sent:

import pyb
pyb.hard_reset()
Parameters

hard (bool) – if True, a hard reset is performed, soft by default

send(obj)

Transmit given object encoded as json :param obj: object to json encode and transmit :type obj: anthing serializable

sync_to_flash(source, **kwargs)

Just like PyBoard.sync_to_sd() but to Flash (instead of the SD card).

sync_to_sd(source, **kwargs)

Synchronise files from the given source to the pyboard’s SD card

Parameters
  • source (str) – Directory containing files to syncronise _to_ pyboard

  • force (bool) – If True, assertion of the pre-existence of placeholder files will be ignored.

  • dryrun (bool) – If True, sync will not be performed, but everything else will be done. Use to manually confirm folder sync if you’re concerned about what it’ll do.

  • quiet (bool) – If True process will not print anything to stdout

unmount_flash()

Unmount on-board flash

unmount_sd()

Unmount SD card

wait(period=0.05)

Wait for transmit queue to be clear, meaning everything in the transmit queue has been sent and ok’d by the remote.

Parameters

period (float) – polling period (seconds)

Module contents

class upytester.pyboard.PyBoard(serial_number, name=None, comport=None, auto_open=True)

Bases: object

The primary interface to a physical device running the upytester firmware.

Can also be used more passively to mount / unmount file-systems, get the device’s mountpoint (a folder name)

DEFAULT_BAUDRATE = 115200
READ_CHUNKSIZE = 1
READ_TIMEOUT = 0.1
RESPONSE_TIMEOUT = 1
WRITE_TIMEOUT = 0.1
close()
comport
classmethod connected_serial_numbers()
halt()
instruction_list
is_closed
is_open
mount_flash()

Mount on-board flash

Returns

path to mounted folder

Return type

str

mount_sd()

Mount SD card

Returns

path to mounted folder

Return type

str

mountpoint_flash

Directory of mounted on-board flash

mountpoint_sd

Directory of mounted SD card

open()
receive(timeout=None)

Receive object from remote.

If timeout is set, and nothing is received, None is returned after timeout.

Parameters

timeout (float) – Time to wait for a response (if None, will wait forever). If timeout is reached, None is returned.

Returns

decoded json object

Return type

dict, or None

receive_iter(timeout=None)

Generator for each received object.

Parameters

timeout (float) – Maximum time per iteration, if not set, only received objects will be returned.

reset(hard=False)

Soft Reset

A soft reset invokes the machine_reset() method by using the onboard upytester library. Obviously this will only work if there is funcitonal upytester firmware running on the pyboard’s SD card.

Hard Reset

A Ctrl+C character ext is sent to simulate a KeyboardInterrupt exception. Then, assuming a REPL has started on the pyboard, these commands are sent:

import pyb
pyb.hard_reset()
Parameters

hard (bool) – if True, a hard reset is performed, soft by default

send(obj)

Transmit given object encoded as json :param obj: object to json encode and transmit :type obj: anthing serializable

sync_to_flash(source, **kwargs)

Just like PyBoard.sync_to_sd() but to Flash (instead of the SD card).

sync_to_sd(source, **kwargs)

Synchronise files from the given source to the pyboard’s SD card

Parameters
  • source (str) – Directory containing files to syncronise _to_ pyboard

  • force (bool) – If True, assertion of the pre-existence of placeholder files will be ignored.

  • dryrun (bool) – If True, sync will not be performed, but everything else will be done. Use to manually confirm folder sync if you’re concerned about what it’ll do.

  • quiet (bool) – If True process will not print anything to stdout

unmount_flash()

Unmount on-board flash

unmount_sd()

Unmount SD card

wait(period=0.05)

Wait for transmit queue to be clear, meaning everything in the transmit queue has been sent and ok’d by the remote.

Parameters

period (float) – polling period (seconds)