Introduction:
Libnodave is a free communication library for Siemens S7 300/400. It is free softwar, and provides a way to exchange data with Siemens PLCs of S7-200, 300 and 400 families. It has alse been successfully tested with a VIPA Speed7 CPU. Data exchange comprised all memory areas and variables you can access in your PLC programs, e.g. flags, data blocks, input and output image memory, timers and counters. Additionally, LIBNODAVE provides access to functions that are in the scope of programming software, e.g. reading diagnostic information, read program blocks from a PLC and write them to a PLC, start and stop a PLC.
LIBNODAVE is currently available for UNIX and Win32. It comes with precomiled libraries for LINUX and Windows. You may port it yourself on any system providing a C compiler.
Using the test programs
Libnodave comes with a set of test programs. They shall serve the follwing purposes:
Provide the user with a demostration of what Libnodave can do.
Provide a quick test for compatibility with user’s hardware and configuration.
Provide a source code example as a template for your own applications.
The debug output, obtained with debug (-d), provides valuable informationn in case Libnodave fails with some hardware.
The benchmark options let you measure the time needed for transfers of shor and long data blocks.
Just invoke the test programs without arguments. They will print a list of possible argumens and optons.
If invoked with the connection as the only argument, all test programs will read some data from the memory area of Flags (also known as Merkers). They try to read FD0,FD4,and FD8 as DWORDS and FD12 as real.
Depending on the contents of this memory, the results may or may no seem reasonalbe. The obtained values are just the same as if you would observe these variables in Step7 using the display formats signed, signed, signed and floating point.
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, handlers in case of windows and what other system 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=openSocket(102, Ipaddress_of_CP);
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 successfully initializing your adapter,you can retrieve a list of reachable parters 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 return a length of .
listLength = daveListReachableParters(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 connectiong 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);
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);