Test and Measurement Forum

Does USBTC-08 work with VB.NET?

Post your .Net discussions here

Does USBTC-08 work with VB.NET?

Postby pmarlow » Fri Apr 20, 2012 3:38 pm

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!
pmarlow
Newbie
 
Posts: 0
Joined: Fri Apr 20, 2012 2:11 pm

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

Postby Martyn » Mon Apr 23, 2012 10:40 am

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 Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2280
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

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

Postby pmarlow » Mon Apr 23, 2012 11:50 pm

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
pmarlow
Newbie
 
Posts: 0
Joined: Fri Apr 20, 2012 2:11 pm

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

Postby Martyn » Tue Apr 24, 2012 10:35 am

Can you try

Code: Select all
unitResult = usb_tc08_get_single(handle, tempReadings(0), ofFlag, tempUnits)
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2280
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

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

Postby pmarlow » Tue Apr 24, 2012 2:26 pm

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!
pmarlow
Newbie
 
Posts: 0
Joined: Fri Apr 20, 2012 2:11 pm

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

Postby Martyn » Tue Apr 24, 2012 2:40 pm

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 Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2280
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

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

Postby pmarlow » Tue Apr 24, 2012 3:32 pm

Great! That did it! Thank you.
pmarlow
Newbie
 
Posts: 0
Joined: Fri Apr 20, 2012 2:11 pm

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

Postby evh » Thu Aug 23, 2012 1:55 am

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
evh
Newbie
 
Posts: 0
Joined: Thu Aug 23, 2012 1:51 am

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

Postby Martyn » Tue Aug 28, 2012 6:59 am

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 Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2280
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots


Return to .Net Languages (C#, VB.Net, .)

Who is online

Users browsing this forum: No registered users and 1 guest