LibNoDave – exchange data with Siemens PLC

If someone wants to visualize processes controlled by the PLC and this PLC is Siemens, then good choice is LibNoDave exchange data library.

What is Libnodave?

Libnodave is a free library for data exchange between a PC and a PLC’s Siemens. The PLCs that can appeal to the S7-200/300/400. Libnodave is written in C + + and can communicate via MPI, PPI and ISO on TCP. Libnodave works on both Windows and Linux and already available in the following programming languages C + +, VB / C #. NET, Delphi and Java.

During development of project based on the Siemens PLC, often needed to simulate interface of the equipment or machine. The purpose of this article is to show how to do it with different languages for PLC engineers, because contents of the source site is sometimes difficult.

Usage of the library:

1. Initialize the socket interface:
  fds.rfd := openSocket(102, '168.143.1.24';
2. Initialize a daveInterface
  dcIn := daveNewInterface(fds, 'IF1',0,daveProtoISOTCP, daveSpeed187k);
3. Initialize the adapter
  if (daveInitAdapter(dcIn) = 0) then ...
4. Initialize a daveConnection
  dc := daveNewConnection(dcIn,2, StrToInt(rack), StrToInt(slot));
5. Connect to a PLC
  if (daveConnectPLC(dc) = 0) then ...
6. Exchange data with that PLC
  daveReadBytes(dc,daveFlags,0,120,30);
  daveWriteBytes(dc,daveFlags,0,120,16,buf);
7. Disconnect from the PLC
  daveDisconnectPLC(dc);
8. Disconnect from the Adapter
  daveDisconnectAdapter(dcIn);


Example:

Reading sequence of the bytes from PLC:

function daveReadBytes(	dc : PdaveConnection;
                      area : longint;
                      DB   : longint;
                     start : longint;
                       len : longint;
                    buffer : pointer) : longint; stdcall; cdecl;

dc     - connection.
aria   - Datablok , Merker, Input, Output.
DB     - when a data block give data block number. Other areas simply give zero.
start  - location of first byte you want to read.
len    - number of bytes you want to read.
buffer - buffer.

Reading 4 variables from PLC. 3 with integers value and one with double value.

procedure Read_4_DW;
var
  data1, data2, data3 : integer;
  data4 : double;
begin:
    response := daveReadBytes(dc,0x83,0,0,16,NIL);
    if res = 0 then
    begin
      data1 := daveGetU32(dc);
      data2 := daveGetU32(dc);
      data3 := daveGetU32(dc);
      data4 := daveGetFloat(dc);
    end;
end;

Writing sequence of the bytes to PLC: 

function daveWriteBytes(dc : PdaveConnection;
                      area : longint;
                        DB : longint;
                     start : longint;
                       len : longint;
                    buffer : pointer) : longint; stdcall; cdecl;
dc     - connection.
aria   - Datablok , Merker, Input, Output.
DB     - when a data block give data block number. Other areas simply give zero.
start  - is the location of the first bait.
len    - number of bytes you want to write.
buffer - buffer.

Writing bits data to PLC:

function daveWriteBits(dc : PdaveConnection;
                     area : longint;
                       DB : longint;
                    start : longint;
                      len : longint;
                   buffer : pointer) : longint; stdcall; cdecl;
dc     - connection.
aria   - Datablok , Merker, Input, Output.
DB     - when a data block give data block number. Other areas simply give zero.
start  - is the location of the first bait.
len    - is the location of the first bit, so if you want to write a m1.0 then start = 8.
buffer - buffer.

Examples with LibNoDave library for:

  1. DotNet API
  2. Delphi API
  3. NetBeans JavaFX
  4. Android

22 Responses to “LibNoDave – exchange data with Siemens PLC”

  1. Ugur Says:

    Very Good thank u.

  2. abiola Says:

    which programming language would you sugest has greater library support from siemens?

    • alexsentcha Says:

      The great support from Siemens only for .Net begining from version 5.4. The API interface can be used with all Windows applications supporting the Component Object Model technology.

  3. Carlos. Says:

    Alex, i’m using libnodave using C++ language, first create interface then the connection and finally readbytes, but when i run the program appear “I/O POSSIBLE”. i’m testing on Fedora 16 and Centos 6.3 … could you help me, is something about serial port settings???

    • alexsentcha Says:

      Hi Carlos,
      No, i can’t really help you, because i never used Fedora, Ubuntu or other Linux distribution.

      • Carlos G. Says:

        Thanks, but any idea about the message “I/O possible” , i tried changing serial settings, like close delay and closing wait time but nothing change. some forum talk about a SIGIO interrupt has been raised, supposed i have to use or make the file descriptor asynchronous.

      • alexsentcha Says:

        Hi Carlos,
        I never use Fedora but at least for communications between two objects need the same settings for both sides. If you use serial port, then you will need Siemens MPI adapter (serial, not USB) and settings as MPI, port, baud rate, speed must be the same. For example, protocol = MPI = 1, port = COM1, baud = 38400, Speed ​​= 187k = 2, rack and slot do not matter in case of MPI.

      • Carlos. Says:

        I used a Siemens Simatic S7 PC adapter v5.1 (MPI to RS232 *switched to 19,2) to connecto the pc to PLC. In the code i have where localMPI = 1 and useProto is equal to daveProtoMPI. etc. The program works with an old dell optiplex gx620 with RedHat, but i copied all the files to a newer machine and get the “I/O POSSIBLE” message. I don’t know why not run in other linux distribution or if some librarie is missing

  4. Ozgur Says:

    Hello Alex,

    I have Net Beans 7.3 and JDK 7.17. When i try to open project, net beans give “unrecognized project; missing plug-in?”. Do you have any comment ?

    • alexsentcha Says:

      Hello Ozgur,
      Sources of the NetBeans 6.9 or lees (JavaFx 1.3 is last) are not compatible with sources NetBeans 7.0 or high (JavaFx 2.0) and you need plug-in javaFX. Direct your browser to the JavaFX NetBeans plugin page and followed the instructions. This plugin assumes the existence of JavaFX on the developer’s computer.

  5. Ozgur Says:

    Hello Again :),
    I have just open project :),

    Thanks

  6. Ozgur Says:

    Hello Alex,
    Again me :), I have another problem with executable file :(. I build jar file and i try to run jar file like as “java -jar JavaFxNoDaveTest.jar” command. Command line give error below. Do you have another comment here.

    Thanks.

    Exception in thread “main” java.lang.NoClassDefFoundError: com/sun/javafx/runtim
    e/FXObject
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: com.sun.javafx.runtime.FXObject
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    … 12 more
    Could not find the main class: javafxnodavetest.Main. Program will exit.

  7. alexsentcha Says:

    Hello Ozgur,
    JavaFxNoDaveTest was created with NetBeans 6.9. (JavaFx 1.3) and this is not compatible with NetBeans 7.3 (JavaFx 2.0). You can not run this example with NetBeans 7.3.
    For NetBeans 7.3 try download JavaFx2NoDaveTest and launch with JavaFx2NoDaveTest.jnlp from “dist” directory.

    http://pcplcdemos.googlecode.com/hg/JavaFx2NoDaveExample/dist/JavaFx2NoDaveExample.jnlp

    But if you want to try JavaFxNoDaveTest you must first download NetBeans 6.9 from:
    https://netbeans.org/community/releases/69/

  8. stephan Says:

    http://snap7.sourceforge.net/ this looks very handy too!

  9. Simon Says:

    Hi Alex,

    at the moment, I try your VB.NET example program with a S7-200 (Ethernet) and libnodave.

    Writing outputs and flags do work, but writing inputs does nothing.

    Which address and values should I use to write the standard inputs (LEDs on the S7-200 labeled with I0x…)?

    Best regards,
    Simon

    • alexsentcha Says:

      Hello Simon,
      Inputs card must be disconnected from PLC, otherwise you can not write input.
      Best regards.

      • Simon Says:

        Hello again,

        there is no “input card” or cable connected. It’s just a S7-200 with a CP243-1 Ethernet module.

        So what address and value do I have to write to, when I want to activate e.g. input LED “I02″?

  10. Róbert Pavlík Says:

    Hallo Alex. I tried this library, but when I try connect PLC, I receive a message : System,BadImageFormatException{“An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)”}. What it mean? Thank’s.

  11. Erik Says:

    Hello Alex,

    I want to setup a connection pcplc, is there a full tutorial to see everything to do in PLC en also in vb to setup that connection.

    Thanks,

    Erik

  12. Emma Avworo Says:

    Hi Alex,

    I have a siemens plc setup that is giving me some headache, and want to try libnodave. I used a vb6 code and a Hilscher cif50-pb card to connect to a siemens s5 plc in fdl mode. The connection is via an optical fibre link convertor. sometimes the data is ok, at other times the data will all be wrong, it is randomly erratic. hence I want to use the libnodave library with a siemens cp5611 card, if this will provide consistent data reception.

    Can you assist with a little guide or can you do the coding for such an interface for a minimal fee?

    Your kind response will be appreciated.

    Emma Avworo

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: