linuxplc.conf - changed syntax

J

Thread Starter

Jiri Baum

Hello,

the new improved linuxplc.conf file parser has progressed...

Incompatible change: linuxplc.conf now must have sections.

The linuxplc.conf file is divided into sections. Sections are normally indicated by a word in square brackets.

Eg:
[SMM]
xyzzy=42
plugh=86

Alternately, a section can be prepended to a single line like this:
SMM:xyzzy=42
SMM:plugh=42

A section can appear any number of times in the file with cummulative effect.


File inclusion is supported. (Recursive, circular OK.)
*include "linuxplc-part1.conf"


There are two types of setting in linuxplc.conf: variables and tables.

Variables
=========

Use:
single values that need to be configured within a module (or
globally throughout the PLC)

Syntax:
variable = value

Variables may be specified any number of times, but only if the
value is always the same (within the same section).

Access from program:
v=conffile_get_value("variable");
or:
v=conffile_get_value_sec("section", "variable");

The first form is preferred, as it will use the module name for the
section. Thus it will be possible to start two instances of the
same module with different configurations.

If the variable doesn't exist, NULL is returned.


Tables
======

Use:
a list of values to be used in a module (or globally in the PLC).
For instance, the mapping between linuxPLC points and physical I/O.

I expect that at least some of the tables will be in keyword
format, so that (after a few initial values each row has) there
will be a sequence of "keyword value" pairs.

Syntax:
tablename word value ...
tablename word value ...
...

For example:
point L1 "light 1" Chaser at 0.0
point L2 "light 2" Chaser at 0.1
point L3 "light 3" Chaser at 0.2
point L4 "light 4" Chaser at 0.3

Access from program:
Err, none yet (except for the "point" table in the "SMM" section).


I think these two types should cover the configuration needs of most
modules...

Comments?

Jiri
--
Jiri Baum <[email protected]>
Windows is not popular. Windows is *widespread*. Linux is popular.

_______________________________________________
LinuxPLC mailing list
[email protected]
http://linuxplc.org/mailman/listinfo/linuxplc
 
Hello,

I wrote yesterday:
> Tables
> ======
...
> Access from program:
> Err, none yet (except for the "point" table in the "SMM" section).

OK, the access is done now.

Getting a value:
The function conffile_get_table() takes the table name and row and
column numbers (zero-based) and returns a malloc()ed string.

If the table is not found or doesn't have that many rows or the row
doesn't have that many columns, it returns NULL, so you can treat
the tables as NULL-terminated if you wish.

Getting dimensions:
Alternately, you can get the number of rows in a table and the
number of cells in a row using conffile_get_table_rows() and
conffile_get_table_rowlen().

Note that each row may have a different number of cells.


Sections:
These three functions also have _sec variants that take an explicit
section name; again, don't use these unless it's appropriate.
Normally you want the default section so it's possible to invoke a
module twice by giving it different module names on the command
line and have them use different sections in the config.


Example:
Have a look at conffile_get_point_by_index() in conffile_lib.c,
it's been updated to use the above functions.


Jiri
--
Jiri Baum <[email protected]>
Windows is not popular. Windows is *widespread*. Linux is popular.

_______________________________________________
LinuxPLC mailing list
[email protected]
http://linuxplc.org/mailman/listinfo/linuxplc
 
Top