Test and Measurement Forum

TC-08 and VB6 Development

Post your VB and VBA discussions here

TC-08 and VB6 Development

Postby jpetitti » Wed Mar 14, 2007 3:28 pm

Hello,
I'm having problems getting the szSerial number and temp readings to work correctly.

Here is the test sub I wrote to try to get things up and running.

Dim intRetStatus As Integer
Dim hTC08 As Integer
Dim tc08Info As USBTC08_INFO
ReDim temp_buffer(9) As Single
Dim intFlag As Integer
Dim intErrorCode As Integer

hTC08 = usb_tc08_open_unit()
If (hTC08) Then
List1.AddItem ("Device #" & hTC08 & " has been opened")
tc08Info.size = 30
intRetStatus = usb_tc08_get_unit_info(hTC08, tc08Info)
List1.AddItem ("Serial Number #" & tc08Info.szSerial)

Call usb_tc08_set_mains(hTC08, True)
intRetStatus = usb_tc08_set_channel(hTC08, 0, Asc("K"))

intRetStatus = usb_tc08_get_single(hTC08, temp_buffer(0), intFlag, 0)
List1.AddItem ("Channel 0:" & temp_buffer(0))

End If
hTC08 = usb_tc08_close_unit(hTC08)

The output of List1 is:
Device # 1 has been opened
Serial #

Notice that the serial number is blank. I noticed that in your sample VB application the serial number also does not appear.
The serial number is quite important to me as I will be running 8 devices.

At the "get_single" line I get an overflow error, however your sample application works just fine and I can't see the difference between the sample and my test function.

Any assistance here would be much appreciated.
Thanks in advance!
jpetitti
User
User
 
Posts: 3
Joined: Wed Mar 14, 2007 3:06 pm

Postby markB » Tue Mar 27, 2007 11:11 am

Try:

Code: Select all
Declare Function usb_tc08_get_formatted_info Lib "usbtc08.dll" (ByVal handle As Integer, ByVal unit_info As String, ByVal string_length As Integer) As Integer

Dim info as String * 1024

ok = usb_tc08_get_formatted_info Lib(tc08_handle, info, 1024)


And parse info for the fourth line
markB
Site Admin
Site Admin
 
Posts: 83
Joined: Tue Mar 27, 2007 9:43 am
Location: Cambridgeshire,UK

Postby jpetitti » Tue Mar 27, 2007 1:33 pm

markB,

Thank you for your reply!

I have however tried to use this method before to no effect.
Here is what I wrote to quickly test it again:
(the function declaration is in my module)

Dim intRetVal As Integer
Dim hTC08 As Integer
Dim info As String * 255

hTC08 = usb_tc08_open_unit()
If (hTC08) Then
intRetVal = usb_tc08_get_formatted_info(hTC08, info, 255)
MsgBox (info)
Call usb_tc08_close_unit(hTC08 )
End If

The problem I get here is that anything larger then 255 for the string length causes VB and my project to crash.

However, when I run it at 255 OR with usb_tc08_get_unit_info the return value that I get for both functions is 0. According to the API guide this is an error and usb_tc08_get_last_error should be used. So I use it and it returns 0 as well - no error.

I also know that the device is working correctly because PicoLog Recorder software can get all the device info just fine.

Again, all help is very much appreciated!
jpetitti
User
User
 
Posts: 3
Joined: Wed Mar 14, 2007 3:06 pm

Postby markB » Tue Mar 27, 2007 2:01 pm

Be careful to declare second parameter (the String) byVal and not byRef. Use the decalaration in my earlier post.

I tried this with VBA and it all works fine.
markB
Site Admin
Site Admin
 
Posts: 83
Joined: Tue Mar 27, 2007 9:43 am
Location: Cambridgeshire,UK

Postby jpetitti » Tue Mar 27, 2007 2:47 pm

Excellent markB, That worked perfectly!
I knew it had to be something small I was over looking, those always get me in the end.

It should be noted that the original declaration of the get_formated provided by Pico in the sample module, has it declared ByRef and this needs to be changed to use it in this manor.

OK, so that solves get_formated, any ideas on the structured version get_unit_info?
jpetitti
User
User
 
Posts: 3
Joined: Wed Mar 14, 2007 3:06 pm


Return to VB and VBA (Excel, Access)

Who is online

Users browsing this forum: No registered users and 0 guests