Вы находитесь на странице: 1из 8

Config 600 Pro Training Manual

Section 2 – LOGICALC LANGUAGE SPECIFICATION

Supported Types Decimal Integer (e.g. -999)


Binary Integer (e.g. 11001100b)
Double Precision Floating Point (e.g. 3.14159265)
String (e.g. "hello mum")

Supported operators +-*/


()
>, <, =, >=, <=, <>
AND, OR (boolean)
& (bitwise AND), | (Bitwise OR)
$ (string concatenation)
<<, >> (Bit shifting)

Supported statements function/end, dim, const, let, if/then/else/endif, while/do/wend,


for/next, call, return, connect, setalarm/clearalarm/accalarm

Built in functions ioboard(x), station(x), stream(x), numioboards(),


numstations(), numstreams(),
numobjects(x, "type"), log(x), exp(x), abs(x), int(x), pow(x, y),
sin(x), cos(x), tan(x), timenow()
leftstring("string", len), rightstring("string", len)
NOT(), NOTB()

Comments # as first character in a line denotes a comment

Max program file line 255 chars


length
Max variable/function name 63 chars
length
Max chars a string variable 127 chars
can contain
Max number of args to a 16
function
Variable names can contain a-z, A-Z, 0-9 and _. (First char can't be 0-9)
Max terms in single 32
arithmetic expression
Max logicalc program file 8.3 characters (S600 uses FAT) e.g. "my_progy.lc" is ok.
name length "myprogram.lc" is not.

Rev April/07 LogiCalc language specification 1


Config 600 Pro Training Manual

2.1 Logicalc Statements

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
.

Rev April/07 LogiCalc language specification 2


Config 600 Pro Training Manual

.
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>;

for <variable_name> = <expression> to <expression>


.
.
next;

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>;

Rev April/07 LogiCalc language specification 3


Config 600 Pro Training Manual

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>);

The 4 parameters are:


♦ Section index. Usually 0 (for system) or derived from stream(x), station(x) or ioboard(x)
♦ Data type. A string such as "KPREAL", "KPINT", "KPSTRING", etc.
♦ Data index. The tricky bit. An index into the data of the section specified in the first
argument.
♦ Field name. A string representing the field name. e.g. "INUSE", "VALUE", etc.
The connect wizard or system editor will help you out specifying these values.
NOTE: The variable is only dynamically connected to its data point within the scope of the
function it is cponnected in. If you pass the variable as a parameter to another function, the
function will receive a static snapshot of the value when it was passed in. e.g.
function copydouble(in, out)
out = in * 2;
end;

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>);

The 2 parameters are:


♦ Alarm number: 0 - 15
♦ An alarm value.
The alarm value has no significance apart from that it will get printed out on the printer as part of
the alarm event message. This will only happen if it is non-0 so just pass 0 if no value is required
on the printout. Different values can be passed for setalarm, clearalarm and accalarm and they
will all be printed out against the relevant alarm event messages.

Rev April/07 LogiCalc language specification 4


Config 600 Pro Training Manual

2.2 Logicalc Built In Functions


There are a number of built in functions to perform common tasks. They can be used directly in
expressions.

2.2.1 ioboard(x), station(x), stream(x) - Section index functions


These functions return the base index for the specified stream/station/ioboard section. You would
typically use them in a call to connect to index data within a stream, say. If you are using a direct
index or just a system index, pass 0 instead of these functions.
e.g. to update a variable of known index in stream 2:
# Relative stream index for a KPREAL
const INDEX_KPREAL_VISC = 14;

connect strVisc(stream(2), "KPREAL", INDEX_KPREAL_VISC, "VALUE");

strVisc = 0.317;

2.2.2 numioboards(), numstations(), numstreams() - Resource


evaluation functions
These functions return how many streams/stations/io boards are present in the current running
configuration.
e.g. to iterate through io boards
dim io;

for io = 1 to numioboards()
connect xxx(io, xxxx, xxxx, xxxx);
...

next;

2.2.3 numobjects(x, "type") - Object evaluation function


This function returns how many objects of the specified type are present in section (x) of the
currently running configuration.
e.g. to iterate through all the system keypad ints:
dim numints = numobjects(0, "KPINT");

for i = 1 to numints
connect xxx(0, "KPINT", i, "VALUE");
...

next;

2.2.4 setalarm(x, v), clearalarm(x, v), accalarm(x, v) - Alarm handling


functions
These functions set/clear and accept alarms in the system.
The parameters are alarm number (0 -> 15) and alarm value. (Value that gets printed out)
e.g.
connect adc1(ioboard(1), "ADC", 0, "INUSE");

Rev April/07 LogiCalc language specification 5


Config 600 Pro Training Manual

if (adc1 > 50) then


setalarm adc1(1, adc1);
else
clearalarm adc1(1, adc1);
endif;

accalarm adc1(1, 0.0);

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).

2.2.11 sin(x), cos(x), tan(x)


Trig functions. x must be in radians.

2.2.12 NOT(x), NOTB(x)


NOT() is a boolean not. Will return 1 or 0 depending on the value of the passed expression. e.g.

Rev April/07 LogiCalc language specification 6


Config 600 Pro Training Manual

♦ 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;

2.3 Logicalc And Alarms

2.3.1 Testing Alarms


You can test for alarms being set or clear, accepted or unaccepted by connecting to ALARM
objects:
e.g.
connect adcstatus(ioboard(1), "ALARMS", ALARMS_P144IIO_IO01ADC01,
"STATUS");
connect adcunacc(ioboard(1), "ALARMS", ALARMS_P144IIO_IO01ADC01,
"UNACC");

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;

e.g. To test if alarm 'x' (remember alarms start at 0) is unaccepted:


if adcunacc & (1 << x) then # alarm is unaccepted
.
.
endif;

2.3.2 Suppressing Alarms


Access to the alarm object allows suppression and testing of suppression.
e.g. To suppress alarm 'x' (where x = 0 to 15) on an ADC, connect to an alarm object's
"SUPPRESS" field:
connect adcsuppress(ioboard(1), "ALARMS", ALARMS_P144IIO_IO01ADC01,
"SUPPRESS");
adcsuppress = adcsuppress | (1 << x);

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

Rev April/07 LogiCalc language specification 7


Config 600 Pro Training Manual

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.

Rev April/07 LogiCalc language specification 8

Вам также может понравиться