VM8090 Win7 and XP

Hi,

I’m having issues interfacing with the VM8090 under Win7. My code was written in VB.NET (2008) and is more or less a straight copy of the example supplied by Velleman. When running under XP, there is no issue code works fine, however under Win7, the same code crashes and returns the error “Conversion from string " " to type ‘Double’ is not valid”, when trying to run the Connect() command. My port address is correct and correctly assigned to the K8090Board object. It doesn’t matter if I try to load the code previously written on an XP machine and then save it again under Win7. Any idea ?

It obviously is something related with unexpectedly converting a string to a double. Your debugger does not show where this error is thrown from?

This is the source code for Velleman.Kits.dll assembly (C#)
velleman.eu/images/tmp/KitsNET.zip

Hi,
Thanks for the reply.
Source: “Microsoft.VisualBasic”
StackTrace: " at Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat) "

Have I got to change OS/ CPU settings somewhere it seems to be System dependant ? I have set the Configuration Manager to x86 on my Win 7 machine, but no success. Sorry I’m new to .NET and x64 OS, so far I have only been using VB6 under Win2000 & XP :slight_smile:

My code (works perfectly fine on XP machines). Error at K8090.Connect() with Win7
Reference library: Velleman.Kits

Module Module1
    Public K8090 As New Velleman.Kits.K8090Board

Public Function Read_Command()

        Dim str_Command As String
        Dim ary_Command As Object
        Dim addr_switches As Integer
        Dim direction, comP As String

        On Error GoTo errh

str_Command = "17,ON,COM4"  'for debug purposes 

        If str_Command <> "" Then
            ary_Command = Split(str_Command, ",")
            If UBound(ary_Command) = 2 Then
                addr_switches = Convert.ToInt32(ary_Command(0)) ' relay adress as integer ex: 17 = 0001 0001, 36 = 0010 0100 
                direction = ary_Command(1)     ' ON or OFF
                comP = ary_Command(2)          ' Com Port address
                If direction = "ON" Then Call Close_Relays(addr_switches, comP)
                If direction = "OFF" Then Call Open_Relays(addr_switches, comP)

            End If
        End If
        End

errh:
        If Err.Number <> 0 Then MsgBox("error num " & Err.Number & " " * Err.Description)

Public Sub Close_Relays(ByVal addr As Integer, ByVal comPort As String)

        Dim addr_byte As Byte

        K8090.Port() = comPort
        addr_byte = Convert.ToByte(addr)
        If K8090.Connect() Then
            K8090.SwitchRelayOn(addr_byte)
            K8090.Disconnect()
        End If

    End Sub

Public Sub Open_Relays(ByVal addr As Integer, ByVal comPort As String)

        Dim addr_byte As Byte

        K8090.Port() = comPort
        addr_byte = Convert.ToByte(addr)
        If K8090.Connect() Then
            K8090.SwitchRelayOff(addr_byte)
            K8090.Disconnect()
        End If
    End Sub

End Module

This seems to be related to your custom code and not to a library or OS. Use breakpoints and the debugger’s Step Over feature to find out what line is causing trouble.

One quick error that I spot is K8090.Port() = comPortPort is not a function, but a property, so Port should not have paranthesis ().K8090.Port = comPort
Anyway, your code contains a lot of Convert.ToSomething, so one of those is probably at fault. Maybe you’re trying to convert an empty string to some number.

Same issue with the parenthesis off…
Anyway, this code is working fine under XP. On Win 7, the Com address gets passed on OK to the K8090.Port (format “COM4” as a String), it’s the only variable attributed before the DLL crashes, this is why I believe the problem is probably coming from some compatibility issue.

So I’ve tried running your Sample code 01 coming with the drivers and the error message is different: “An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)” thrown by 'Velleman.Kits.K8090Native.OpenDevice(String szPort) ’ . On the Win 7 machines, All the .NET references and MicrosoftVisualBasic.dll are taken from C:\Windows\Microsoft.NET\FrameWork (and not Framework64). Could that be the problem ?

[quote=“DenP”]Anyway, this code is working fine under XP. On Win 7, the Com address gets passed on OK to the K8090.Port (format “COM4” as a String), it’s the only variable attributed before the DLL crashes, this is why I believe the problem is probably coming from some compatibility issue.[/quote]Don’t guess, always look at the error and what line of code triggered it, use the debugging tools.

[quote]So I’ve tried running your Sample code 01 coming with the drivers and the error message is different: “An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)” thrown by 'Velleman.Kits.K8090Native.OpenDevice(String szPort) ’ . On the Win 7 machines, All the .NET references and MicrosoftVisualBasic.dll are taken from C:\Windows\Microsoft.NET\FrameWork (and not Framework64). Could that be the problem ?[/quote]Your project is 64-bit while the assembly is 32-bit. You will need to set your project to 32-bit.

How to force an application to run in 32-bit mode on x64 using Visual Studio 2005 and 2005 Express versions: viewtopic.php?f=3&t=724&p=2641