USB TC-08 usb_tc08_get_unit_info function VB.NET

Post your .Net discussions here
Post Reply
sparky3600
Newbie
Posts: 0
Joined: Sun Sep 25, 2011 12:37 am

USB TC-08 usb_tc08_get_unit_info function VB.NET

Post by sparky3600 »

Hi Guys,

I am having a problem returning any information from the usb_tc08_get_unit_info function.

The code runs without error however the tUSBInfo structure is not populated.

below is the code I have written to try and get this to work, can someone please show me where I am going wrong or show me an example of how to get this to work.

Code: Select all


Imports System.Runtime.InteropServices

Public Class Form1
    Declare Function usb_tc08_open_unit Lib "usbtc08.dll" () As Short
    Declare Function usb_tc08_get_unit_info Lib "usbtc08.dll" (ByVal handle As Short, ByRef info As tUSBTC08Info) As Short

    Structure tUSBTC08Info
        Public size As Short
        Public DriverVersion As Short
        Public PicoppVersion As Short
        Public HardwareVersion As Short
        Public picovar As Short
        Public szSerial As String
        Public szCalDate As String
    End Structure

    Public info As tUSBTC08Info

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim handle As Short = usb_tc08_open_unit()
        MessageBox.Show(handle)
        'info.size = Marshal.SizeOf(info)
        Dim infook As Short = usb_tc08_get_unit_info(handle, info)
        MessageBox.Show(infook)

    End Sub
End Class

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: USB TC-08 usb_tc08_get_unit_info function VB.NET

Post by Martyn »

You may need to use

Code: Select all

Declare Function usb_tc08_get_unit_info Lib "usbtc08.dll" (ByVal handle As Short, ByVal info As tUSBTC08Info) As Short
passing tUSBTC08Info as a ByVal, just as you need to do with String, shown here in the alternative call get info call

Code: Select all

Declare Function usb_tc08_get_unit_info2 Lib "usbtc08.dll" (ByVal handle As Integer, ByVal info As String, ByVal string_length As Integer, ByVal line_no As Integer) As Integer

Dim usbtc08Info As String * 80
    
ok = usb_tc08_get_unit_info2(tc08_handle, usbtc08Info, 80, 4)
Martyn
Technical Support Manager

pmarlow
Newbie
Posts: 0
Joined: Fri Apr 20, 2012 2:11 pm

Re: USB TC-08 usb_tc08_get_unit_info function VB.NET

Post by pmarlow »

I'm having the same problem. Any luck finding a solution? The solution posted by Martyn works for VB6, not VB.NET (In VB.NET the info needs to be ByRef, not ByVal, to get data returned, and the string cannot be dimensioned with a fixed length). I tried everything but still couldn't make it work. Please provide some sample VB.NET code. Thank you!

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: USB TC-08 usb_tc08_get_unit_info function VB.NET

Post by Martyn »

It still needs to be

Code: Select all

ByVal info As String
but you define

Code: Select all

usbtc08Info = "                           "
with as many spaces as you need
Martyn
Technical Support Manager

pmarlow
Newbie
Posts: 0
Joined: Fri Apr 20, 2012 2:11 pm

Re: USB TC-08 usb_tc08_get_unit_info function VB.NET

Post by pmarlow »

Thank you for the fast reply. Yes, it works now.

Post Reply