Connection to PLC with libnodave

romulus001

Member
Join Date
Jun 2016
Location
Aquitaine
Posts
5
Greetings everyone,

I encounter a lot of problems to connect to the PLC. For a couple of days, I had to find by myself the port number ...

For now, I managed to connect to the automaton, but now, impossible to connect to the PLC (and no documentation was given to me).

As far as I understood, I do need an MPI address but I have no clue of where to find it, to connect to the PLC, I simply had the rack and slot values.

Strangely, by using the UserTransport protocol, I can connect to the PLC but my program crashes by trying to read a value...

According to this site : https://alexsentcha.wordpress.com/l...-plc-2/vb-net-exchange-data-with-siemens-plc/

I have to use the ISOTPC protocol but the connection fails...

The automaton mark is Siemens S7.

Thanks for your help
 
Depends on what type of S7 CPU and/or communication processor you have.

If you've got a CPU which has only MPI or Profibus, then you need in your PC at least a special communication processor. With libnodave are only Siemens PC cards compatible, because you have to choose S7online in libnodave, which uses underlying interfaces if the Siemens cards.

If you've got a PN-CPU or an Ethernet CP inside your S7 rack, then you can use the standard network interface of the PC to connect to the plc, then you have to use IsoOnTCP in libnodave.
 
Thanks for your reply.
I just got these new informations:
CPU 412-2
Communication : CP 443-1

How can I know if it has MPI / Profibus / PN CPU / Ethernet CP?
On various forums, I understood I would need to install an OPC server, I just installed TwinCat OPC Server 4.1.94

EDIT : my customer has a Profibus connection but it's no longer used now
 
Last edited:
CP443-1 is an ethernet processor.
If you use Libnodave, then you dont need an OPC Server.
For an S7-400, you have to be aware of the slot number. On an S7-300 it is always rack 0 slot 2. On an S7-400, the slot no can be variable.
 
Libnodave is .... not the best solution atm.
You should be looking at Snap7, which is easier to use and works a bit better in my opinion.

But if you really wanna use LibNoDave:


Variable declaration
Code:
  dc   : pdaveConnection;                                                     // NoDaveConnection
  dcIn : pdaveInterface;                                                      // NoDaveInterface
  IPAddress   : string;                                                       // If String => add #0 at end, else use ANSIString
  CPURack     : integer;
  CPUSlot     : integer;
  MPISpeed    : integer;
  COMPort     : string;
  IntfTimeout : Integer;
  ConnProtocol: Integer; 
  PLCMachStart = Array[1..14] of Byte
Set variable values
Code:
  IPAddress   := 'xxx.xxx.xxx.xxx';
  CPURack     := 0;
  CPUSlot     := 3;
  MPISpeed    := 2;
  COMPort     := 'COM1:';
  IntfTimeout := 100000;
  ConnProtocol:= 122;                                                           // ISO over TCP
Create connection
Code:
procedure TMainForm.DoConnection;                                               // Do Connection
Var
  Fds:_daveOSserialType;                                                        // NoDave type thingy
  Address : AnsiString;                                                         // ANSI string NEEDED!!! to make connection work

begin
    Address := IPAddress + #0;                                                  // Set IP address
    Fds.Rfd := OpenSocket(102, @Address[1]);                                    // Open the socket
    fds.wfd:=fds.rfd;                                                           // set wfd to rfd (read/write socket, should need it)

    PLCConnection := false;                                                        // Set Connection status to False
    if (fds.rfd>0) then                                                         // Is the socket open?
    begin
      dcIn:=daveNewInterface(fds, 'IF1',0,ConnProtocol, MPISpeed);              // Then create new interface
      dcIn^.timeout:=IntfTimeout;                                               // Set the timeout to 10s
      if (daveInitAdapter(dcIn)=0) then                                         // If Interface created
      begin
        dc :=daveNewConnection(dcIn,2, CPURack, CPUSlot);                       // Then create connection
        if (daveConnectPLC(dc)=0) then                                          // If connected
        begin
          StatusBar1.Panels[0].Text := 'Connected '+IPAddress;                  // Then provide visual
          PLCConnection := true;                                                   // And set connection to true
                                                                                // Write various Status info should one of these steps fail
        end else StatusBar1.Panels[0].Text :='Not successful attempt of connection!';
      end else StatusBar1.Panels[0].Text :='Not successful attempt to initialize  the adapter!';
    end else StatusBar1.Panels[0].Text :='Not successful attempt of creation of the interface!';

end;
Read data
Code:
res := daveReadBytes(dc, daveDB, 910, 10, 14, @PLCMachStat[1]);         // Read PLC data
// daveDB = defined in libnodave as 132
// 910 = DB number in PLC
// 10 = Address of starting byte in DB 
// 14 = number of bytes to read.
// res = result, is 0 if read was executed without error.
This is working code that was written in Delphi.
Should help you solve your issues.
 
many thanks guys for your help, but I finally managed to establish a connection to the PLC, guess what? Actually, my own pc is not able to connect to their PLC, I simply had to realize my tests on one of their pc which is able to use their automatons ...
I finally gave up the libnodave library and used instead S7, which requires no port number.
 
I'm trying to data, strangely, I have some incoherent values, I don't know why.
For that, I'm calling the read method (not readBytes) on the database 172, on the Dword 1 : the first value returned is a quantity, the second one is either 0 or 1

With this test (in vb.net) :
Dim result as Object = MyPLC(“DB172.DBW1″)
MsgBox(result.ToString & ” ” & result.GetType.ToString)

I obtain as displayed message :
12 System.UInt16

On DB172.DBW2, I obtain this one :
3073 System.UInt16

What am I doing wrong? may it be because of the conneIction to the PLC, because of the wrong version of Siemens S7? I put S7300 as value. Thanks
 
Last edited:
Values are correct.
Your addresses are overlapping.

DB172.DBXy.z => Bit address where y is the byte and z is the bit in said byte
DB172.DBBx => Byte address where x is the byte
DB172.DBWx => Word address, consisting of bytes DB172.DBBx and DB172.DBBx+1
DB172.DBDx => Double address, consisting of bytes DB172.DBBx, DB172.DBBx+1, DB172.DBBx+2 and DB172.DBBx+3.

In your case:
DB172.DBW1 (W#16#000C) = DB172.DBB1 (B#16#00) and DB172.DBB2 (B#16#0C)
DB172.DBW2 (W#16#0C01) = DB172.DBB2 (B#16#0C) and DB172.DBB3 (B#16#01)
 
Many thanks Jeebs for your help, I was trying to understand your message with my contact, he could find out the solution.
For example, to read the DWord number 10, the first value is obtained by querying DB172.DBW20, the second one by querying DB172.DBW21
 
Many thanks Jeebs for your help, I was trying to understand your message with my contact, he could find out the solution.
For example, to read the DWord number 10, the first value is obtained by querying DB172.DBW20, the second one by querying DB172.DBW21


I assume you meant DWord number 20, If so still not correct.

Byte = 8 bits
Word = 2 bytes
Dword = 4 bytes


So if you 'read' DB172.DBD20, this is the four bytes of DB172.DBB20, DB172.DBB21, DB172.DBB22 and DB172.DBB23

DB172.DBW20 would use DB172.DBB20 and DB172.DBB21.

But with the two examples listed about you couldn't use both DBD20 and DBW20 for two seperate items since they share the same memory areas.

Try opening Options -> Reference Data -> Display -> Assignment list, from Simatic manager. Then scroll down to the MB section. It will show you what types of data area used and what bytes they include.
 

Similar Topics

Hello gentlemen, Im working on a small project on TIA Portal, about establishing a Modbus TCP connection between my ET200SP plc and a socomec...
Replies
12
Views
310
Hi all, My ethernet port on my laptop recently broke and I was hoping to just use a usb-c dongle in the mean time to go live on my PLC until I...
Replies
14
Views
454
Hello, I've been trying to learn this a while now and still have not found out how this works. I have an Omron CJ2M PLC and an ABB ACS 355 VFD...
Replies
1
Views
248
Dear all, I have fx3u series plc with built in rs422 port and usb-sc09-fx cable. I have a a hyperterminal like application to send and receive...
Replies
8
Views
227
Hi all, I'm having an issue with connecting View Studio emulation to a real PLC. I am running View Studio 8.01 on a Hyper-V virtual machine...
Replies
0
Views
262
Back
Top Bottom