This is a quite experimental feature.
First you will need correctly formed program blocks stored in files. A possible source are files
previously read out using --readout. You cannot get them from Step7 as Step7 stores program
block in a data base. It has not been tested but may be so that third party programming software
that stores program blocks in files uses the same file format.
Loading of SDBs (System Data Blocks) is highly dependent of the sequence of
block numbers.
Programming a basic application
Preparations
The main purpose of this library is to read and write data from and to Siemens PLCs.
To do so, you need to establish a connection to the PLC.
First, you need to configure a serial port of your computer or establish a TCP connection.
This connection is represented by the type _daveOSserialType, which contains file descriptors
in case of Unix-like systems, handles in case of windows and what other systems supported in
the future might use for this purpose.
use setport to initialize the members of a _daveOSserialType to something representing
a configured serial connection:
fds.rfd=setPort(argv[adrPos],"38400",'O');
for serial connections or:
fds.rfd=openSocket(102, IPaddress_of_CP);
or
fds.rfd=openSocket(1099, IPaddress_of_IBH-NetLink);
for TCP connections. Then do:
fds.wfd=fds.rfd;
With the initialized _daveOSserialType, you will initialize a structure of type
daveInterface,
representing the physical connection to a PLC or a network of PLCs (e.g. like MPI).
di=daveNewInterface(fds, "IF1", localMPI, daveProtoXXX, daveSpeedYYY);
With the resulting daveInterface structure, you can initialize an adapter, if one is used:
res =daveInitAdapter(di);
While currently only MPI-adapters and IBH-NetLinks really need this initialization procedure, it is save to use
daveInitAdapter() with any protocol type. If it has no meaning for the protocol used, it is
mapped to a dummy procedure that returns allways success.
After successfully initializing your adapter, you can retrieve a list of reachable partners
on an MPI network. The function takes the daveInterface structure and a pointer to a buffer
of sufficient length as arguments. It returns the real length of the list. If the partners cannot
be listed with the protocol used, it just returns a length of 0.
listLength = daveListReachablePartners(di,buf1);
After successfully initializing your adapter, you can establish a connection to a certain PLC
on the network. To do so, you will first initialize a structure of
type daveConnection,
representing the logical connection to a single PLC.
dc =daveNewConnection(di, MPI_address, Rack, Slot);
With the resulting daveConnection structure, you need to really connect the PLC:
res =daveConnectPLC(dc);
Exchanging values:
Once you have established a connection to your PLC, you can read and write values:
res=daveReadBytes(dc, AREA, area_Number, start_address, length, buffer);
res=daveWriteBytes(dc, AREA, area_Number, start_address, length, buffer);
Usually, you will have to convert byte sequences from and to the buffer
to use the data in your application.
After you are done with your data exchanges, call:
daveDisconnectPLC(dc);
To disconnect from the PLC and
daveDisconnectAdapter(di);
to disconnect from the Adapter.
Now close the serial or TCP/IP connection using the appropriate system calls for your OS.
Advanced data exchange
Read multiple items with a single transaction.
Read and set single bits.
Other features
Read diagnostic info (300 and 400 only).
Load program code from PLC.
Load program code into PLC.