Datasheet
Methods
The task of the methods are to initiate the I/O system, perform reading and writing to the I/O units,
and finally disconnect the I/O system. How these tasks are divided, depend on the construction of
the I/O system. In a centralized I/O on the local bus, methods for the different card objects can
attach the bus and read and write data themselves to their unit, and the methods for the agent and
rack object doesn't have much to do. In a distributed I/O the information for the units are often
gathered in a package, and it is the methods of the agent or rack object that receives the package and
distribute its content on different card objects. The card object methods identifies data for its
channels, performs any conversion and writes or reads data in the area object.
Framework
A process can initiate the I/O framework by calling io_ini(). As argument you send a bitmask that
indicates which process you are, and the threads of the plc process also states the current thread.
io_init() preforms the following
● creates a context.
● allocates a hierarchic data structure of I/O objects with the levels agent, rack, card and
channel. For agents a struct of type io_sAgent is allocated, for racks a struct of type
io_sRack, for cards a struct of type io_sCard, and finally for channels a struct of type
io_sChannel.
● searches for all I/O objects and checks their Process attributes. If the Process attribute
matches the process sent as an argument to io_init(), the object is inserted into the data
structure. If the object has a descendant that matches the process it is also inserted into the
data structure. For the plc process, also the thread argument of io_init() is checked against
the ThreadObject attribute in the I/O object. The result is a linked tree structure with the
agents, racks, card and channel objects that is to be handled by the current process.
● for every I/O objects that is inserted, the methods are identified, and pointers to the
methodsfunctions are fetched. Also pointers to the object and the objects name, is inserted in
the data structure.
● the init methods for the I/O objects in the data structure is called. The methods of the first
agent is called first, and then the first rack of the agent, the first card of the rack etc.
When the initialization is done, the process can call io_read() to read from the I/O units that are
present i the data structure, and io_write() to put out values. A thread in the plc process calls
io_read() every scan to fetch new values from the process. Then the plc-code is executed and
io_write() is called to put out new values. The read methods are called in the same order as the init
methods, and the write methods in reverse order.
When the process terminates, io_close() is called, which calls the close methods of the objects in the
data structure. The close methods are called in reverse order compared to the init methods.
The swap method has an event argument that indicates which type of event has occurred, and in
some cases also from where it is called. The swap method is called when emergency break is set
and the IO should stop, and when a soft restart is performed.
When a soft restart is performed, a restart of the I/O handling is also performed. First the close
methods are called, and then, during the time the restart lasts, the swap methods are called, and then
the init methods. The call to the swap methods are done by rt_io_comm.










