K8090 and VB.NET

Hi, I’m laboriously building a program with VB Express card to drive a K8090. How do I program it to automatically detect the COM port it is connected to the K8090 card? is only recently that I use VB Express. Can anyone help me? Thanks. :unamused:

Well, I finished the first version of the program multitimer for time management in competitive archery FITARCO. The problem is that not knowing how to build an automatic connection to the COM port, is now set to COM4. I saw on the demo program can create a window that displays the active com ports and allows the connection. Nobody really wants to help me make the connection faster? When the program is complete publish it for all who want it.
Carlo.

If you want to enumerate all connected K8090 devices in VB.NET you can use this snippet of code:

' Imports System.Management
' Also add a reference (Project->Add Reference) to System.Management.dll

Dim searcher As System.Management.ManagementObjectSearcher = _
	New ManagementObjectSearcher("Select * from Win32_SerialPort")

Dim results As ManagementObjectCollection = searcher.Get()
Dim USBDevice As ManagementObject

For Each USBDevice In results

	Dim deviceId As String = USBDevice.Properties("PNPDeviceID").Value.ToString()

	If deviceId.Contains("VID_10CF&PID_8090") Then

		' If you want the complete port name like:
		'   K8090 8-Channel Relay Card (COM4)
		'
		' Then use the property "Name" like this:
		'
		' USBDevice.Properties("Name").Value.ToString()

		' If you want simple port names that you can use like:
		'   COM1
		'   COM4
		'
		' Then use the property "DeviceId" like this:
		'
		' USBDevice.Properties("DeviceId").Value.ToString()
	End If
Next

If I’m not mistaken it uses WMI internally

[quote=“VEL448”]If you want to enumerate all connected K8090 devices in VB.NET you can use this snippet of code:

If I’m not mistaken it uses WMI internally[/quote]

hi, I have decided to pursue the idea of a button to connect the K8090 card. In the previous post you provided a code snippet, I created a test form with a button and a listbox and I did some tests like this that I place.
The problem is that I have not a good knowledge of VB2008,
Can you explain me where am I wrong? Thanks

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        For Each USBDevice In results 'in error?'

            Dim results As ManagementObjectCollection
            Dim searcher As System.Management.ManagementObjectSearcher = New ManagementObjectSearcher("Select * from Win32_SerialPort")
            Dim results As ManagementObjectCollection = searcher.Get()
            Dim USBDevice As ManagementObject
            Dim deviceId As String = USBDevice.Properties("PNPDeviceID").Value.ToString()

            If deviceId.Contains("VID_10CF&PID_8090") Then

                ' If you want the complete port name like:
                '   K8090 8-Channel Relay Card (COM4)
                '
                ' Then use the property "Name" like this:
                '
                'USBDevice.Properties("Name").Value.ToString()

                ' If you want simple port names that you can use like:
                '   COM1
                '   COM4
                '
                'Then use the property "DeviceId" like this:
                '
                USBDevice.Properties("DeviceId").Value.ToString()
            End If
        Next
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

    End Sub

Please use the code that is provided. Your code uses variables that haven’t been declared yet because you seem to have jumbled things up a bit.

To demonstrate with a simple example, what you are doing is this:

As opposed to the normal way

This makes the compiler very unhappy :cry:

OK. I moved all the statements out of the Button.
But now I find myself “ManagementObjectSearcher” undefined.
“ManagementObjectCollection” undefined.
“ManagementObject” undefined.
I’m afraid you’ll have to guide me step by step, if it pleases you, as I am a beginner with VB.
In the “ListBox1_SelectedIndexChanged” I entered the list:
COM1
COM2
COM3
COM4
COM5
COM6

Public Class K8090_USB
   
    Dim searcher As System.Management.ManagementObjectSearcher = New ManagementObjectSearcher("Select * from Win32_SerialPort")
    Dim results As ManagementObjectCollection = searcher.Get()
    Dim USBDevice As ManagementObject
    Dim deviceId As String = USBDevice.Properties("PNPDeviceID").Value.ToString()


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        For Each USBDevice In results
            If deviceId.Contains("VID_10CF&PID_8090") Then
                ' If you want the complete port name like:
                '   K8090 8-Channel Relay Card (COM4)
                '
                ' Then use the property "Name" like this:
                '
                USBDevice.Properties("Name").Value.ToString()
                ' If you want simple port names that you can use like:
                '   COM1
                '   COM4
                '
                'Then use the property "DeviceId" like this:
                '
                'USBDevice.Properties("DeviceId").Value.ToString()
            End If
        Next
    End Sub


        Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged


        End Sub
    End Class

Anyway, thank you for patience.
Carlo.

Did you do this?:

Ok, so the code is now set. All errors in the form disappeared. But now when I start the debug returns me this error:
Error while creating the form
Exception.InnerException
‘System.NullReferenceException’ in K8090_USB.exe

It seems to me that something is missing where to display the string…

Imports System.Management
Public Class K8090_USB

    Dim searcher As System.Management.ManagementObjectSearcher = New ManagementObjectSearcher("Select * from Win32_SerialPort")
    Dim results As ManagementObjectCollection = searcher.Get()
    Dim USBDevice As ManagementObject
    Dim deviceId As String = USBDevice.Properties("PNPDeviceID").Value.ToString()

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        For Each Me.USBDevice In results
            If deviceId.Contains("VID_10CF&PID_8090") Then
                USBDevice.Properties("Name").Value.ToString()
            End If
        Next
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

    End Sub

End Class

Carlo.

On which line? Find the line number, find the variable that is null and try to figure out why it is null

In another post I read that we must make changes because something can work with Win 64 bit

The 32-bit DLL must be copied to SysWOW64 folder
Please check this thread:
viewtopic.php?f=3&t=5363