upyt.cmd package¶
Submodules¶
upyt.cmd.can module¶
-
upyt.cmd.can.can_state(send, bus)¶ Get the state of a previously configured CAN bus.
- Parameters
bus (
int) – 1 or 2 (according to the pyboard’s CAN controllers)
Response:
{ 'r': 'can_state', # in response to can_state request 'state': x, # CAN bus state, as string (or None if not configured) }
-
upyt.cmd.can.can_tx(send, bus, id, data, rtr=False)¶
-
upyt.cmd.can.can_tx_p(send, bus, id, data, period)¶ Send a CAN message periodically
-
upyt.cmd.can.can_tx_p_stop(send, bus, id)¶
-
upyt.cmd.can.can_tx_p_stopall(send, bus)¶
upyt.cmd.io module¶
-
upyt.cmd.io.config_pin(id, mode, pull=None, value=None)¶ - Parameters
Parameter:
modemodeValuePin Behaviour
'in'input
'out'(synonymn for ‘out_pp’)
'out_pp'output, with push-pull control
'out_od'output, with open-drain control
'af_pp'alternate function, pull-pull
'af_od'alternate function, open-drain
'analog'analog
Parameter:
pullpullValuePin Behaviour
Noneno pull up/down
'none'no pull up/down
'up'pull up resistor
'down'pull down resistor
-
upyt.cmd.io.get_pin(id)¶
-
upyt.cmd.io.set_pin(id, v)¶
upyt.cmd.leds module¶
-
upyt.cmd.leds.blink_led(led=1, intensity=255, duration=1)¶ Turn LED on for a set duration
upyt.cmd.mapping module¶
-
upyt.cmd.mapping.instruction(func)¶ Maps a function to an incoming instruction
Usage:
@instruction def ping(value=0): return {'r': 'ping', 'value': value + 1}
With this implemented, when a host sends
{'i': 'ping', 'k': {'value': 10}}, it will receive{'r': 'ping', 'value': 11}Format of Request When transmitting a request from a host machine, the
dictformat is:{ 'i': 'some_instruction', # name of the method 'a': [1, 'abc', -5.4], # optional list arguments 'k': { # optional keywords argument list 'value': True, 'pin': 'X3', } }
Instruction Design for Serializing Because the method name, and keyword arguments are serialized and transmitted, consider keeping argument & method names short.
-
upyt.cmd.mapping.interpret(obj)¶ Perform the action defined in the given object
- Parameters
obj (
dict) – deserialized JSON object received from host
-
upyt.cmd.mapping.list_instructions()¶
-
upyt.cmd.mapping.send(obj)¶ Send serial data over the preset serial port
Usage:
>>> import pyb >>> from cmd import set_serial_port, send
# Setup Port >>> com_port = pyb.USB_VCP() >>> set_serial_port(com_port)
# Sender transmits json encoding of given obj over VCP >>> send(‘abc’) >>> send(123) >>> send([1, 2, 3]) >>> send({‘a’: 1, ‘b’: 2})
upyt.cmd.spi module¶
-
upyt.cmd.spi.config_spi(idx)¶ Configure SPI bus
- Parameters
idx (
int(1 or 2)) – pyboard SPI index (1 or 2)
-
upyt.cmd.spi.spi_send(idx, data)¶ Note: SPI must be configured via instruction
config_spi()before sending with this method.
upyt.cmd.system module¶
-
upyt.cmd.system.bootloader_mode(t=50)¶ Reets pyboard, and it will boot into bootloader mode
- Parameters
t (
int) – time until reset (unit: ms) (default: 50ms)
-
upyt.cmd.system.break_loop()¶
-
upyt.cmd.system.get_system_info()¶
-
upyt.cmd.system.get_ticks_ms()¶ Get ticks since boot
Module contents¶
-
upyt.cmd.instruction(func)¶ Maps a function to an incoming instruction
Usage:
@instruction def ping(value=0): return {'r': 'ping', 'value': value + 1}
With this implemented, when a host sends
{'i': 'ping', 'k': {'value': 10}}, it will receive{'r': 'ping', 'value': 11}Format of Request When transmitting a request from a host machine, the
dictformat is:{ 'i': 'some_instruction', # name of the method 'a': [1, 'abc', -5.4], # optional list arguments 'k': { # optional keywords argument list 'value': True, 'pin': 'X3', } }
Instruction Design for Serializing Because the method name, and keyword arguments are serialized and transmitted, consider keeping argument & method names short.
-
upyt.cmd.interpret(obj)¶ Perform the action defined in the given object
- Parameters
obj (
dict) – deserialized JSON object received from host
-
upyt.cmd.send(obj)¶ Send serial data over the preset serial port
Usage:
>>> import pyb >>> from cmd import set_serial_port, send
# Setup Port >>> com_port = pyb.USB_VCP() >>> set_serial_port(com_port)
# Sender transmits json encoding of given obj over VCP >>> send(‘abc’) >>> send(123) >>> send([1, 2, 3]) >>> send({‘a’: 1, ‘b’: 2})