PAL_Script.py
Execution script for TWELITE PAL Script
This script initializes and runs the code that reads data from MONOSTICK and outputs the interpreted data to standard output.
How to Read Data
The example below checks whether data has been received from MONOSTICK and, if so, passes it to the Main() function.
from apppal import AppPAL
...
def mainloop(PAL):
# Check if the user-defined Main function can be imported.
try:
from Main_user import Main
except:
mainflag = False
else:
mainflag = True
# Check whether data is available
if PAL.ReadSensorData():
if mainflag:
# If Main was imported, pass the PAL object to Main()
Main(PAL)
else:
# If Main was not imported, display the data on the console.
PAL.ShowSensorData()
...
if __name__ == '__main__':
...
try:
PAL = AppPAL(port=options.target, baud=options.baud, tout=0.05, sformat=options.format, autolog=bEnableLog, err=bEnableErrMsg, stdinput=options.stdinp, Logfilename=options.file)
except:
print("Cannot open \"AppPAL\" class...")
exit(1)
while True:
try:
mainloop(PAL)
except KeyboardInterrupt:
break
del PAL
First, create an AppPAL object. Since serial port settings are configured at instantiation, pass them as arguments.
PPAL = AppPAL(port=options.target, baud=options.baud, tout=0.05, sformat=options.format, autolog=bEnableLog, err=bEnableErrMsg, stdinput=options.stdinp, Logfilename=options.file)
Next, in the mainloop(), call ReadSensorData() to check whether serial data has arrived. If it returns True, pass the interpreted result to Main().
def mainloop(PAL):
# Check if the user-defined Main function can be imported.
try:
from Main_user import Main
except:
mainflag = False
else:
mainflag = True
# Check whether data is available
if PAL.ReadSensorData():
if mainflag:
# If Main was imported, pass the PAL object to Main()
Main(PAL)
else:
# If Main was not imported, display the data on the console.
PAL.ShowSensorData()
For details on the dictionary structure received, refer to this section.