Linux Libnodave example read data from Siemens S7-300

I used Linux Min 17.3, so you can do the same with other Debian based distribution.

  • Step 1 : install mono-complete

    • sudo apt-get install mono-complete
    • if you want to compile libnodave lib by your self, install c develeop headers
      • sudo apt-get install libc6-dev
  • Step 2: download and compile libnodave http://libnodave.sourceforge.net/

    • tar xzf libnodave.*.tar.gz
    • cd libnodave
      • if you are using x64 OS, you need to add CFLAG -fPIC
      • just open Makefile, find the line “CFLAGS” and add at the end -fPIC
      • make clean
      • make
  • Step 3: Now copy libnodave.so and libnodave.net.dll to you project directory

  • Step 4:

    • now create your Program, or use my from example (btw: you can download all files, link is below)
    • using System;
      using System.Threading;
      using System.Collections.Generic;
      using System.ComponentModel;
      
      public class S7reader
      {
          public static void Main(string[] args){
              libnodave.daveOSserialType fds;
              libnodave.daveInterface di;
              libnodave.daveConnection dc;
              int res=0;
              
              try{
                  fds.rfd = libnodave.openSocket (102, "192.168.1.60");
                  fds.wfd = fds.rfd;
      
                  if (fds.rfd > 0) {
                      di = new libnodave.daveInterface (fds, "IF1", 0, libnodave.daveProtoISOTCP, libnodave.daveSpeed500k);
                      di.setTimeout (10000);//10 seconds
                      dc = new libnodave.daveConnection (di, 0, 0, 2);
                      if (0 == dc.connectPLC ()) {
                          while (fds.rfd>0) {
                              res = dc.readBytes (libnodave.daveDB, 100, 12, 4, null);
                              if (res == 0) {
                                  float tmp = dc.getFloat();
                                  Console.WriteLine("DB100.DBD12: "+tmp);
                              }
                              Thread.Sleep (1500);
                          }
                      }
                  } else {
                      
                      Console.Error.WriteLine(DateTime.Now + " :: Error");
                  }
              }catch(Exception exc){
                  Console.Error.WriteLine(DateTime.Now + "Exception: "+exc);
              }
          }
      }
  • Step 5: compile this example
    • mcs S7reader.cs -r:libnodave.net.dll -out:./S7reader
  • Step 6: run the program
    • mono S7reader
  • Step 7: create you own application

Short Video with all steps:

 

10 comments on “Linux Libnodave example read data Siemens S7-300

Leave a Reply

Your email address will not be published. Required fields are marked *

* Please Add the Values