Libnodave mit VB2005

Earny

Level-1
Beiträge
422
Reaktionspunkte
38
Zuviel Werbung?
-> Hier kostenlos registrieren
Hallo,

ich will mit Libnodave Bits aus einer S7-CPU lesen und schreiben. Vorerst teste ich mit Accontrol. Das Schreiben klappt problemlos, das Lesen will nicht funktionieren.

Der Code fürs Schreiben des M18.0 ist:
Code:
[COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Sub[/COLOR] btnM18_0Einschalten_Click([COLOR=#0000ff]ByVal[/COLOR] sender [COLOR=#0000ff]As[/COLOR] System.Object, _
[COLOR=#0000ff]ByVal[/COLOR] e [COLOR=#0000ff]As[/COLOR] System.EventArgs) [COLOR=#0000ff]Handles[/COLOR] btnM18_0Einschalten.Click
[COLOR=#0000ff]Dim[/COLOR] buf [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Byte[/COLOR]
[COLOR=#0000ff]If[/COLOR] res = 0 [COLOR=#0000ff]Then[/COLOR]
buf = 1
[COLOR=#008000]'M18.0 = 18x8+0 = M144[/COLOR]
res = daveWriteBits(dc, daveFlags, 0, 144, 1, buf)
[COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]If[/COLOR]
[COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Sub[/COLOR]

Der Code fürs Lesen des M18.0 ist:
Code:
[COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Sub[/COLOR] btnM18_0Lesen_Click([COLOR=#0000ff]ByVal[/COLOR] sender [COLOR=#0000ff]As[/COLOR] System.Object, _
[COLOR=#0000ff]ByVal[/COLOR] e [COLOR=#0000ff]As[/COLOR] System.EventArgs) [COLOR=#0000ff]Handles[/COLOR] btnM18_0Lesen.Click
[COLOR=#0000ff]Dim[/COLOR] buf [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Byte[/COLOR]
[COLOR=#0000ff]If[/COLOR] res = 0 [COLOR=#0000ff]Then[/COLOR]
[COLOR=#008000]'M18.0 = 18x8+0 = M144[/COLOR]
res = daveReadBits(dc, daveFlags, 0, 144, 1, buf)
txtM18_0Lesen.Text = buf
[COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]If[/COLOR]
[COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Sub[/COLOR]

In der Textbox "txtM18_0Lesen" wird immer eine 0 angezeigt, unabhängig davon, ob der M18.0 den Wert True oder False hat.

Ich benutze nur die libnodave.dll, ohne die libnodave.net.dll (Wrapper) und habe sämtliche VB6.0-Funktionen und Prozeduren in einen Modul gepackt und alles öffentlich (Public) eingestellt. Später will ich das dann in eine Klasse stecken.

Ich benutze zum Schreiben:
Code:
[COLOR=#0000ff]Public[/COLOR] [COLOR=#0000ff]Declare[/COLOR] [COLOR=#0000ff]Function[/COLOR] daveWriteBits [COLOR=#0000ff]Lib[/COLOR] [COLOR=#800000]"libnodave.dll"[/COLOR] ([COLOR=#0000ff]ByVal[/COLOR] dc [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR], [COLOR=#0000ff]ByVal[/COLOR] area [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR], [COLOR=#0000ff]ByVal[/COLOR] areaNumber [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR], [COLOR=#0000ff]ByVal[/COLOR] start [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR], [COLOR=#0000ff]ByVal[/COLOR] numBytes [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR], [COLOR=#0000ff]ByRef[/COLOR] buffer [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Byte[/COLOR]) [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]

und zum Lesen:
Code:
[COLOR=#0000ff]Public[/COLOR] [COLOR=#0000ff]Declare[/COLOR] [COLOR=#0000ff]Function[/COLOR] daveReadBits [COLOR=#0000ff]Lib[/COLOR] [COLOR=#800000]"libnodave.dll"[/COLOR] ([COLOR=#0000ff]ByVal[/COLOR] dc [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR], [COLOR=#0000ff]ByVal[/COLOR] area [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR], [COLOR=#0000ff]ByVal[/COLOR] areaNumber [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR], [COLOR=#0000ff]ByVal[/COLOR] start [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR], [COLOR=#0000ff]ByVal[/COLOR] numBytes [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR], [COLOR=#0000ff]ByVal[/COLOR] buffer [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Byte[/COLOR]) [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR]
 
habe meinen Fehler gefunden.
Der letzte Parameter der daveReadBits-Funktion muss als Zeiger, d.h. mit ByRef und nicht mit ByVal übergeben werden. Dann geht auch das Lesen.

Earny
 
Zurück
Oben