Useful APEL Tricks
How do I add a delay to a script?
To add delay to a script you should use the CLOCK statement. The exact length of the delay can be calculated as count x 1/(TCK frequency). The TCK frequency is specified using the FREQUENCY statement.
Examples
CLOCK 1000
CLOCK counter
How long did my script take to run?
Add the following to the end of the script.
Dim mytime as integer
mytime = TIME()
PRINT " Total :" + DECV(myTIME) + " Seconds"
How can I pass a parameter to a script?
On the command line, Windows Runner and for any compiled executables, just add them after the filename. For example
APEL params.apel c:\temp\Read.hex WRITE 1000
To set the command line parameters in APEL Studio then go to the options Window
For the COM object two functions exist. Use ClearCommandLineVariables() to remove existing parameters and use AddCommandLineVariable(<StringValue>) to add parameters before calling Start().
To access the command line parameter when running the script a string array called param will be defined and can be accessed as follows
Dim i as integer
If length(param)<> 0 then
For i = 1 to length(param)
print param[i-1]
next
endif
How do I report that that a script ran correctly?
The following error values are used as standard
Error State |
Value |
Success |
0 |
File Error |
1 |
Syntax Error in script |
2 |
To report your own status you can add a parameter to the END statement. This will allow you to report Test PASSED/FAILED/PROGRAMMED etc. i.e.
END 23 // Report Error 23 when exiting
Do I have to use the BUS statement to access a single pin?
No. Some people do as it helps to describe the pins but both examples below are valid
BUS I2CCLK = {PIC.RD10}
BUS I2CDATA = {PIC.RD11}
for i = 1 to 8
I2CDATA = subst(Data,i-1,1)
Load
I2CCLK ="1"
Load
I2CCLK ="0"
Load
Next
Can also be written as
for i = 1 to 8
PIC.RD11= subst(Data,i-1,1)
Load
PIC.RD10="1"
Load
PIC.RD10="0"
Load
Next
How do I distribute the production test but protect the scripts from being modified?
The APEL Compiler produces an executable version of your script so that the application can be safely distributed