Академический Документы
Профессиональный Документы
Культура Документы
2.1.1 function/end:
A program consists of one or more user defined functions in a text file. These functions should be
laid out one after the other. The last function found is used as the first one to run. Each function
can call the other user-defined functions as long as the functions called are defined earlier in the
file. (i.e. you can only call upwards)
User defined functions can take any number of arguments. They are evaluated at run time and
passed by value. A function can return one value which must be assigned to a variable using the
'call' keyword. User functions cannot be used directly in expressions.
function <function1_name>(<arg1>, <arg2>, ...)
.
.
.
end;
2.1.2 dim:
Used to define a variable for use in the current scope.
dim <variable_name>;
dim <variable_name> = <expression>;
2.1.3 const:
Used to define a constant for use in the current scope. This is the same as a variable except a
value must be assigned at define time and the value cannot be changed. (Like a #define in C)
const <constant_name> = <expression>;
2.1.4 let:
Used to assign a value to a variable. The let command is optional.
let <variable_name> = <expression>;
<variable_name> = <expression>;
2.1.5 if/then/else/endif:
Used to conditionally change the path of execution in a program.
if <expression> then
.
.
endif;
if <expression> then
.
.
else
.
.
endif;
2.1.6 while/do/wend:
Used to conditionally loop the path of execution in a program.
while <expression> do
.
.
wend;
2.1.7 for/next:
Used to loop the path of execution in a program a set number of times. The variable name on the
'next' is optional.
for <variable_name> = <expression> to <expression>
.
.
next <variable_name>;
2.1.8 call:
Required to call a user function that returns a value. The returned value from a function is
assigned to the specified variable. If a return value is not required, just specify the function name
on it's own without the call keywork. A function can be called in either of the following 3 ways:
(NOTE: The last variant will only work on v1.2 and above so avoid it for compatability)
<function_name>(<expression1>, <expression2>, ...);
call <variable_name> = <function_name>(<expression1>, <expression2>,
...);
call <function_name>(<expression1>, <expression2>, ...);
2.1.9 return:
Return a value from a function.
return <expression>;
2.1.10 connect:
Used to connect a data point from the S600 database for use in the program.
connect <variable_name>(<expression>, <expression>, <expression>,
<expression>);
function main()
connect adc1(ioboard(1), "ADC", 0, "MEASURED");
connect dac1(ioboard(1), "DAC", 0, "MEASURED");
while 1 do
copydouble(adc1, dac1);
wend;
end;
Although this logicalc will compile & run, it will not do anything useful as the 'in' and 'out'
variables are not connections, they are just values. The act of passing them into the function
'copydouble' has evaluated them from connected variables (adc1, dac1) to normal variables with
values in them (in, out).
2.1.11 setalarm/clearalarm/accalarm:
Used to manipulate alarms in the S600.
setalarm <variable_name>(<expression>, <expression>);
strVisc = 0.317;
for io = 1 to numioboards()
connect xxx(io, xxxx, xxxx, xxxx);
...
next;
for i = 1 to numints
connect xxx(0, "KPINT", i, "VALUE");
...
next;
2.2.5 timenow()
Snapshot the system time. Useful for working out relative times.
e.g.
while (1) do
dim t = timenow();
.
.
.
# Have we taken too long??? (i.e. exceeded 1.5 seconds)
if (timenow() - t > 1.5) then
setalarm timeout(0, t);
endif
wend
2.2.6 log(x)
Natural logarithm
2.2.7 exp(x)
Exponential value.
2.2.8 pow(x, y)
Power function. Takes x to the power y. Arguments can be double precision. Heavy on processor
so don't hammer this function in a loop unless you have to.
2.2.9 abs(x)
Returns the absolute value of x. If x is positive, return x. If x is negative, return -x.
2.2.10 int(x)
Returns the integer portion of x. Always truncates, so int(1.9) returns 1. If you want to round up,
call int(x + 0.5).
♦ NOT(1) = 0
♦ NOT(0) = 1
♦ NOT(25.6) = 0
NOTB() is a bitwise NOT. Mainly used for masking out bits. e.g.
function ClearBit(value, bitpos)
return value & NOTB(1 << bitpos);
end;
This object will allow access to the alarm status of an ADC. The value returned is a 16 bit mask
with a 1 in each alarm position representing an alarm that is set or unaccepted, respectively.
e.g. To test if alarm 'x' (remember alarms start at 0) is set:
if adcstatus & (1 << x) then # alarm is set
.
.
endif;
The field is a 16 bit mask as are the STATUS and UNACC field of the alarm object. Suppressed
alarms are represented by a set bit in the mask. Setting a bit in the mask suppresses the alarm.
Bear in mind that the above code first reads out the current suppress mask, OR's in a bit and
writes it back. This happens pretty quickly but may conflict with anything else that is updating
the value. Ensure the logicalc is the only task updating the alarm suppression word to avoid
missing the odd suppression.