LibNoDave

userxyz

Member
Join Date
May 2002
Location
any
Posts
2,768
Hi,

I'm trying/playing with the LibNoDave library.
I've installed Visual Studio 2013 and Simatic on a VM with IP 192.168.3.100.
I've installed WinLC on a VM with IP 192.168.3.207.
Both can ping each other and I can manipulate with a VAT DB1.DBX0.0 as a test.

So it's clear that there is acces to a softCPU from the VM where Visual Studiois running.

So I imported the Class and I tried to make a connection, but I get:
DllNotFoundException was unhandled.

Untitled.jpg

This was my code behind the button:

Code:
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim fds As libnodave.daveOSserialType
        Dim di As libnodave.daveInterface
        Dim dc As libnodave.daveConnection
        Dim res As Integer
        Dim buf(100) As Byte
        Dim localMPI As Integer = 0
        Dim rack As Integer = 0
        Dim slot As Integer = 2
        Dim plcMPI As Integer = 2
        Dim Connection As Boolean = False
        Dim IP As String = "192.168.3.207"

        'ConnectPLC.....
        fds.rfd = libnodave.openSocket(102, IP)
        fds.wfd = fds.rfd

        If fds.rfd > 0 Then       ' if step 1 is ok
            di = New libnodave.daveInterface(fds, "IF1",
                            0, libnodave.daveProtoISOTCP,
                            libnodave.daveSpeed187k)

            di.setTimeout(1000000)
            res = di.initAdapter
            If res = 0 Then       ' init Adapter is ok
                ' rack amd slot don't matter in case of MPI
                dc = New libnodave.daveConnection(di, 0,
                                                   rack, slot)
                res = dc.connectPLC()
                If res = 0 Then
                    Connection = True
                    ToolStrip1.Text = "Connected " + IP
                End If
            End If
        End If
    End Sub

Anyone who has some experience with the LibNoDave Class ?

Thanks,
Regards,
Combo
 
Last edited:
I did use libnodave a while back but my memory isn't perfect. I think you need libnodave.dll and libnodave.net.dll in the same folder. libonodave.net.dll translates requests from the .net environment. If you want to see the commands available you need to look at libnodave.net.cs. Then look in the .Net/VB folder to see an example, which looking at your program I guess you already did.
 
same folder

You are right, I also had to copy the dll files to the release directory's.

Thanks,
regards,
Gerry
 
You are right, I also had to copy the dll files to the release directory's.
In Visual Studio, if you have a DLL that is a dependency, you should either add it as a reference or you can do the following:

-Right click your Project in Solution Explorer and select Add Existing
-Browse to and select the DLL
-After the DLL has been added to your project, then select it in Solution Explorer
-In the Properties Window, change Copy To Output Directory to Copy if Newer


Either of these methods will automatically put the file in the directory for you.
 
Thanks

Thanks Archie.

I just tried to read 4 bytes withuut succes...

This is what a wrote:

Code:
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        If Connection Then
            res = dc.readBytes(libnodave.daveFlags, 68, 0, 4, buf)
            If res = 0 Then
                Label2.Text = Str(dc.getU32)  'DB68.DBW8 DWORD 4 bytes
            Else
                Label2.Text = res
            End If
        End If
    End Sub



I added this to see what the RES value is:
Else
Label2.Text = res

When I run it, I get a 5 in res.
DB68 exsists and I made DBD0 real in that DB.
Connection is true, I'm sure about that and the thicker is enabled and running for sure.

Do you have an idea what's wrong ?

Thanks,
Combo
 
If you want to read from datablocks, you should use daveDB instead of daveFlags.

If you want to read flags with daveFlags (M...), then the parameter DB number should be zero. Not all CPUs ignore the DB number when reading flags.
 
Read data

Hi Thomas,

I understand, sounds very logic.
I used code from this link:
https://alexsentcha.wordpress.com/l...-plc-2/vb-net-exchange-data-with-siemens-plc/

This means that the code on that webpage is wrong.

I will try the DB read this evening.

Thanks,
Regards,
Combo

If you want to read from datablocks, you should use daveDB instead of daveFlags.

If you want to read flags with daveFlags (M...), then the parameter DB number should be zero. Not all CPUs ignore the DB number when reading flags.
 
Step further

Hello,

The DaveDB works.

Now I have a problem with the following code:

Code:
    res = dc.readBytes(libnodave.daveFlags, 0, 0, 1, buf)
            If res = 0 Then
                c = Str(dc.getS8)

This is the line marked by the debugger: c = Str(dc.getS8)
Errorinfo: Make sure you are not deviding by zero ?

What could be the problem ?

Regards,
Combo
 
M20.0

Ok, I wrote some things in an other way because IsBitSet seems to be not working in .Net 2013.

I tried the following code:

Code:
   Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Dim bytevalue As Byte = 8
        Dim bits As New BitArray({bytevalue})
        If Connection Then
            res = dc.readBytes(libnodave.daveDB, 68, 0, 4, buf)
            If res = 0 Then
                Label2.Text = Str(dc.getU32)  'DB68.DBW8 DWORD 4 bytes
            Else
                Label2.Text = res
            End If

            res = dc.readBytes(libnodave.daveFlags, 0, 20, 1, buf)
        If res = 0 Then
            bytevalue = dc.getU8
                If bits.Item(0) Then   'M20.0
                    Panel1.BackColor = Color.Green
                Else
                    Panel1.BackColor = Color.LightBlue
                End If
            End If
        End If
    End Sub


M20.0 set to true in S7, but the Panel doesn't change its color...
What could be wrong ?

Thanks,
Combo
 

Similar Topics

Hi I am trying to connect to a s7-300 with libnodave. I successfully connected to 1200 and a 1500. 1500 had to make some change in the hardware...
Replies
1
Views
1,393
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...
Replies
9
Views
6,803
Hi,I'm a beginner.I want to connect 1200 by libnodave .who can upload a simple example . About how to build communication and Write DB Values .Any...
Replies
4
Views
1,967
Hi All I want communicate PLC S7 300 by VB.net and use Libnodave pass usb mpi 6ES7972-0CB20-0XA0. Can do it? If can please guide me. Thank you.
Replies
0
Views
3,292
I coded this app using LIBNODAVE maybe some of you guys can test.. i used PLC siemens s7-1200 1212C images...
Replies
1
Views
3,275
Back
Top Bottom