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:
December 20, 2012 at 4:57 pm |
which programming language would you sugest has greater library support from siemens?
March 6, 2013 at 9:48 pm |
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???
March 8, 2013 at 5:58 am |
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.
March 8, 2013 at 7:03 pm |
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
April 1, 2013 at 7:08 pm |
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 ?
April 3, 2013 at 11:35 am |
Hello Again ,
I have just open project ,
Thanks
April 3, 2013 at 11:35 am |
Hello Again :),
I have just open project :),
Thanks
October 3, 2013 at 8:57 am |
http://snap7.sourceforge.net/ this looks very handy too!
October 8, 2013 at 2:51 pm |
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
October 9, 2013 at 7:19 am |
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”?
October 23, 2013 at 11:06 am |
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.
October 23, 2013 at 11:10 am |
Maybe will better, when I send you screen capture, but I need some email, where I can send it.
March 6, 2014 at 5:20 pm
you build vb.net x86
December 24, 2013 at 7:01 pm |
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
January 4, 2014 at 9:07 am |
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
August 11, 2014 at 5:11 am |
Hi Alex,
I have same probelm with Emma.
I have PLC s7-400 with CP5611 card. And I only need to read the data from I, Q and M. Can you give me suggestions. Because I have the problem with the connection between CP5611 and libnodave.
Thank you very much…
May 6, 2014 at 8:27 pm |
Hi Alex and every one,I am trying to read data from the memory of the plc . for example when i am doing a load instruction L +300 , 300 is places in the ACCU1, How can i read this value using libnodave, Thank you
May 12, 2014 at 5:15 pm |
Hello Alex,
thanks a lot for the sharing.
a question, why after disconnection it still possible to read variable?