# Libnodave and Visual Studio 2008



## Rick (22 September 2009)

Wenn the programm is calling this function, it hangs on the

ph = openSocket(port, Peer$) 

Port = 102 (as long)
Peer = 192.168.0.1 (as string)

i use

Microsoft studio 2008
Vista 64 Bits
write in visual basic

Microsoft Visual Studio Solution (.sln)
file included in the *.rar

Thank you.....


'************************************************* ****
' End of interface declarations and helper functions.
'************************************************* ****
PublicFunction initialize(ByRef ph AsLong, ByRef di AsLong, ByRef dc AsLong)
Dim res AsLong
Dim Peer AsString
Dim port AsLong
Dim MpiPpi AsLong
Dim Rack AsLong
Dim Slot AsLong
ph = 0
di = 0
dc = 0
REM uncomment the daveSetDebug... line, save your sheet
REM run excel from dos box with: excel yoursheet >debugout.txt
REM send me the file debugout.txt if you have trouble.
REM call daveSetDebug(daveDebugAll)
initialize = -1
Peer$ = Form1.TextBox1.Text
port = 102
'Form1.Label3.Text = openSocket(port, Peer$)
ph = openSocket(port, Peer$) ' for ISO over TCP

If (ph > 0) Then
di = daveNewInterface(ph, ph, "IF1", 0, daveProtoISOTCP, daveSpeed187k)
res = daveInitAdapter(di)
If res = 0 Then
' with ISO over TCP, set correct values for rack and slot of the CPU
Rack = Form1.TextBox2.Text
Slot = Form1.TextBox3.Text
dc = daveNewConnection(di, MpiPpi, Rack, Slot)
res = daveConnectPLC(dc)
If res = 0 Then
initialize = 0
EndIf
EndIf
EndIf
EndFunction


----------



## Earny (24 September 2009)

Hallo Rick,
i think, this is the initialisation routine for LibNoDave with Excel, but i am not sure. I recommand the following routine, which is tested with VB2005:


```
[SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]Option[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]Explicit[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]On[/COLOR][/SIZE]
[SIZE=1][COLOR=#0000ff]Option[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]Strict[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]Off[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=1][COLOR=#0000ff]
[SIZE=1][COLOR=#0000ff]Public[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]Class[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1] Form1[/SIZE]
[SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1] localMPI [/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]Integer[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1] = 1, plcMPI [/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]Integer[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1] = 2[/SIZE]
[SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1] fds [/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1] libnodave.daveOSserialType[/SIZE]
[SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1] di [/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1] libnodave.daveInterface[/SIZE]
[SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1] dc [/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1] libnodave.daveConnection[/SIZE]
[SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1] res [/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]Integer[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1] = 1[/SIZE]
[SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1] livebit [/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]Boolean[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=1][COLOR=#0000ff]
[/COLOR][/SIZE][SIZE=1][COLOR=#0000ff]
[/COLOR][/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]Public[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]Sub[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1] ISO_TCP()[/SIZE]
[SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1] IP [/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]String[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=1]IP = cbxIP.Text[/SIZE]
[SIZE=1]fds.rfd = libnodave.openSocket(102, IP) [/SIZE][SIZE=1][COLOR=#008000][SIZE=1][COLOR=#008000]'Portstatus - lesen[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=1]fds.wfd = fds.rfd [/SIZE][SIZE=1][COLOR=#008000][SIZE=1][COLOR=#008000]'Portstatus schreiben = Portstatus - lesen[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=1]di = [/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1] libnodave.daveInterface(fds, [/SIZE][SIZE=1][COLOR=#800000][SIZE=1][COLOR=#800000]"Mein Interface"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1], localMPI, _[/SIZE]
[SIZE=1]libnodave.daveProtoISOTCP, libnodave.daveSpeed187k)[/SIZE]
[SIZE=1]di.setTimeout(1000000)[/SIZE]
[SIZE=1]res = di.initAdapter[/SIZE]
[SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]If[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1] res = 0 [/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]Then[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1][COLOR=#008000][SIZE=1][COLOR=#008000]'initAdapter OK[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=1][COLOR=#008000][SIZE=1][COLOR=#008000]' Rack und Slot spielen keine Rolle bei diesem Protokoll[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=1]dc = [/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1] libnodave.daveConnection(di, plcMPI, 0, 2)[/SIZE]
[SIZE=1]res = dc.connectPLC()[/SIZE]
[SIZE=1]livebit = [/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]True[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=1]...[/SIZE]
[SIZE=1]...[/SIZE][SIZE=1][COLOR=#0000ff]
[/COLOR][/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]If[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[/COLOR][/SIZE]
```
 

Good Luck
Earny


----------



## Rick (28 September 2009)

*Ok*

Thank you i managed to setup a project using Visual studio 2008
the code was indeed for excel.
iàm just starting.......


----------



## juergen1969 (9 Oktober 2009)

Rick,
do you compile your application in 32 bit mode or for "any cpu" ?

juergen


----------



## Rick (12 Oktober 2009)

IdOn`t know i think its Any CPU.
But i switched to Visual Basic Express.....
I know that on my Laptop 64 Bits they file project was not working.

that means wenn is call a Libnodave function it crasehes.

On my 32 Bit machine the projectworked oke.

Gr. Rick


----------



## juergen1969 (12 Oktober 2009)

When you compile an application as Any CPU, it will run on a 64 bit machine in 64 bit mode.
libnodave is a 32 bit dll, so you have to compile your application as x86.
It's not allowed to mix various assemblies/dlls in different machine modes.


----------

