picossa_pigs module
Classes for provding a pigs interface on top of gpiosvr.picossa. pigs
refers to the exceutable of the same name of the
pigpio project.
With an instance of PigsExecutor, it is possible to execute commands
and scripts like:
m 12 w pud 12 o w 12 1
This sets GPIO 12 as an output GPIO, disables the internal resistor and sets it to level 1.
Classes
- class gpiosvr.picossa_pigs.PigsScript(loop, script, gpioClient, cancelCheckingInterval_μS, uartPause_ms=20, uartReadBufferBytes=1024, uartReadTimeout_ms=200, isStored=False)
Encapsulates a pigs script that can be executed at any point in time, i.e. instantly as an ad-hoc script or in the scope of stored script created with proc and executed with procr.
Normally, this class does not have to be instanced manually, as
PigsExecutorprovides a high-level API for working with scripts.For further reference of the supported pigs commands, see pigpio.
Supported pigs commands:
proc plus other commands for storing a script
parse plus other commands for a mere syntax check
r | read for reading a GPIO level
w | write for writing an output GPIO level
m | modes for setting the mode of a GPIO
pud for setting the internal pull-up/down resistance
mics and mils for pausing the script
tag for tagging a specific point in the script
jmp, jz, jnz, jm and jp for jumping to a tag under certain conditions
dcr and inc for decreasing or increasing a register value, respectively
ld for setting a specific register to a specific value
lda for setting the internal accumulator to a specific value
cmp for comparing the internal accumulator with a specific value
Additional commands not supported by the original pigs command:
uart for sending bytes via UART and receive bytes in return in a certain time frame: uart <channel> <bytes>. Bytes may be specified as an ASCII string or as a hexadecimal value given as a string starting with
0x.
Note that
GPIO servermight accept additional commands for getting and setting server configuration entries.A script is considered long-running, if it includes the command mics and/or mils.
- __init__(loop, script, gpioClient, cancelCheckingInterval_μS, uartPause_ms=20, uartReadBufferBytes=1024, uartReadTimeout_ms=200, isStored=False)
- Parameters:
cancelCheckingInterval_μS¶ (int) – For a long-running script, the interval in microseconds in which a stop request for the script is checked. In other terms, the maximum delay after which a stop request is honored. See
executeProcs().uartPause_ms¶ (int) – When sending bytes with an uart command, the the pause before reading bytes in response. The best value depends on the device to communicate with. Defaults to
UART_PAUSE_DEFAULT_MS.uartReadBufferBytes¶ (int, optional) – After sending bytes with an uart command, the maximum number of bytes read at once in response. Defaults to
UART_READ_BUFFER_BYTES_DEFAULT.uartReadTimeout_ms¶ (int) – After sending bytes with an uart command, the maximum time span in milliseconds to receive bytes in response. If too low, the bytes returned might be incomplete. The best value depends on the device to communicate with. Defaults to
UART_READ_TIMEOUT_DEFAULT_MS.
- class gpiosvr.picossa_pigs.PigsExecutor(taskMonitor, gpioClient, cancelCheckingInterval_μS=1000, msgBuffer=None)
Executor for pigs scripts. It also holds stored scripts created with the proc command.
See
PigsScriptfor the supported commands.- __init__(taskMonitor, gpioClient, cancelCheckingInterval_μS=1000, msgBuffer=None)
- Parameters:
gpioClient¶ – The GPIO API to use, connected with the desired GPIO backend.
cancelCheckingInterval_μS¶ – See
cancelCheckingInterval_μS
- async executeProcd(scriptStr, selectedHandles)
Corresponds to the procd command for deleting a stored script.
- async executeProcp(scriptStr, selectedHandles, isSelectedByHandle=False)
Corresponds to the procp command for showing the status of a stored script.
- async executeProcr(scriptStr, selectedHandles, parameters=())
Corresponds to the procr command for running a stored script.
- async executeProcs(scriptStr, selectedHandles)
Corresponds to the procs command for stopping a running script.
Constants and defaults
- gpiosvr.picossa_pigs.CANCEL_CHECKING_INTERVAL_μS_DEFAULT = 1000
- gpiosvr.picossa_pigs.UART_PAUSE_DEFAULT_MS = 20
- gpiosvr.picossa_pigs.UART_READ_BUFFER_BYTES_DEFAULT = 1024
- gpiosvr.picossa_pigs.UART_READ_TIMEOUT_DEFAULT_MS = 200