Does USBTC-08 work with VB.NET?

Post your .Net discussions here
Post Reply
pmarlow
Newbie
Posts: 0
Joined: Fri Apr 20, 2012 2:11 pm

Does USBTC-08 work with VB.NET?

Post by pmarlow »

I'm trying to write code for a USBTC-08 (2 units) in Visual Basic 2010 Windows XP using the latest usbtc08.dll. The sample VB6 code that came with the drivers from Pico works fine. But I can't get all the functions to work in VB.NET. Specifically, the functions: usb_tc08_get_unit_info2, usb_tc08_get_formatted_info and usb_tc08_get_single are not returning any data. The function results come back as 1 (good), but there is no information. Can anyone share a few lines of sample code in VB.NET showing how they got these functions to work? Thank you!

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

Re: Does USBTC-08 work with VB.NET?

Post by Martyn »

You need to make sure that the Function Declarations are correct, in particular strings need to be passed as ByVal even if they are there to receive data. They should be populated as a string of spaces of sufficient length to receive the expected data before use. Any enumerated constants should be longs and not integers.
Martyn
Technical Support Manager

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

Re: Does USBTC-08 work with VB.NET?

Post by pmarlow »

Martyn,

Thank you. Everything works now except usb_tc08_get_single. Please take a close look at my code and let me know what I am doing wrong. The program crashes at the usb_tc08_get_single function.

Code: Select all

    Declare Function usb_tc08_get_single Lib "c:\PICO\usbtc08.dll" (ByVal handle As Integer, ByRef temp() As Single, ByRef overflow_flags As Integer, ByVal units As Integer) As Long

    Private Sub getUSBTC08()
        Dim unitResult As Long
        Dim handle As Integer = 1
        Dim tempReadings(9) As Single
        Dim ofFlag As Integer
        Dim tempUnits As Integer = 1

        For n = 0 To 8
            unitResult = usb_tc08_set_channel(handle, n, "K")
            Debug.Print(unitResult)
        Next

        unitResult = usb_tc08_get_single(handle, tempReadings, ofFlag, tempUnits)
        Debug.Print(unitResult & " " & ofFlag)

        For n = 0 To 8
            Debug.Print(tempReadings(n))
        Next

    End Sub
Thank you,
Peter

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

Re: Does USBTC-08 work with VB.NET?

Post by Martyn »

Can you try

Code: Select all

unitResult = usb_tc08_get_single(handle, tempReadings(0), ofFlag, tempUnits)
Martyn
Technical Support Manager

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

Re: Does USBTC-08 work with VB.NET?

Post by pmarlow »

Thank you. I had already tried this. It gives an error in VB.NET (won't compile). Has anyone had any success with this? Please offer corrections to my code. Thank you!

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

Re: Does USBTC-08 work with VB.NET?

Post by Martyn »

With this declaration ?

Code: Select all

Declare Function usb_tc08_get_single Lib "c:\PICO\usbtc08.dll" (ByVal handle As Integer, ByRef temp As Single, ByRef overflow_flags As Integer, ByVal units As Integer) As Long
note no brackets on temp
Martyn
Technical Support Manager

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

Re: Does USBTC-08 work with VB.NET?

Post by pmarlow »

Great! That did it! Thank you.

evh
Newbie
Posts: 0
Joined: Thu Aug 23, 2012 1:51 am

Re: Does USBTC-08 work with VB.NET?

Post by evh »

Dear Martyn -

The following code give me a "...may be inaccessible due to protection level" error on line 54 ... can you tell me how to fix it? Please send an email.

Thanks!

EVH

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

Re: Does USBTC-08 work with VB.NET?

Post by Martyn »

We would need to see your code to comment on an error on Line 54, please post it and we will take a look
Martyn
Technical Support Manager

Post Reply