first running version
This commit is contained in:
28
README.md
28
README.md
@ -12,23 +12,31 @@ Code example
|
||||
|
||||
# declare variables visibile over serial
|
||||
|
||||
vars = Pxsi('MyBox', # idn will be: pxsi,MyBox
|
||||
t = 5,
|
||||
a = 2,
|
||||
)
|
||||
with Pxsi('MyBox'): # idn will be: pxsi,MyBox
|
||||
pollinterval = 5.0 # important: add decimal point in case you want this to be a float
|
||||
anint = 2
|
||||
afloat = 0.0
|
||||
astring = 'text'
|
||||
|
||||
# the given variables are now available in the main namespace
|
||||
|
||||
# create action functions for some of the variables
|
||||
|
||||
def change_t(value):
|
||||
def change_afloat(value):
|
||||
value = float(value) # check value is compatible with float
|
||||
# write here what to do when t changes
|
||||
return value # return the validated value
|
||||
|
||||
# your real code
|
||||
# the validity of <value> has to be checked here, and if any conversion happens
|
||||
# the converted value has to be returned
|
||||
# if no change function is present, the value is converted to the type of
|
||||
# the initial value (e.g. float, int or str)
|
||||
|
||||
# here follows your real code
|
||||
|
||||
print(t) # the given variables are now available in the main namesapce
|
||||
|
||||
while True:
|
||||
# handle IO, wait at most 0.5 secs
|
||||
vars.handle_io(0.5)
|
||||
Pxsi.handle(0.5)
|
||||
# read out sensors, do control logic here
|
||||
# important: do not sleep here!
|
||||
|
||||
@ -43,6 +51,8 @@ Commands:
|
||||
["name1", ["name2", value]] # multiple commands: query name1, change name2. must be a valid JSON array
|
||||
{"name1": null, "name2": value} # alternative form - be aware that order is not guaranteed
|
||||
|
||||
The values must match the type of initial values
|
||||
|
||||
Special command for identification
|
||||
|
||||
*IDN?
|
||||
|
Reference in New Issue
Block a user