Test and Measurement Forum

usb_tc08_get_single with USB TC08 & VB6

Post your VB and VBA discussions here

usb_tc08_get_single with USB TC08 & VB6

Postby MichaelV » Tue Feb 07, 2012 5:06 pm

Hello,

I use your example code for the usb_tc08. I get an overrun error on the line:
ok = usb_tc08_get_single(tc08_handle, temp_buffer(0), overflow_flag, 0)
Code: Select all
Option Explicit
Declare Function usb_tc08_set_channel Lib "c:\usbtc08.dll" (ByVal handle As Integer, ByVal channel As Integer, ByVal tc_type As Byte) As Integer

Declare Function usb_tc08_run Lib "c:\usbtc08.dll" (ByVal handle As Integer, ByVal interval_ms As Long) As Long

Declare Function usb_tc08_get_temp Lib "c:\usbtc08.dll" (ByVal handle As Integer, ByRef temp_buffer As Single, ByRef times_ms_buffer As Long, ByVal buffer_length As Long, ByRef overflow, ByVal channel As Integer, units As Integer, ByVal fill_missing As Integer) As Long

Declare Function usb_tc08_get_temp_deskew Lib "c:\usbtc08.dll" (ByVal handle As Integer, ByRef temp_buffer As Single, ByRef times_ms_buffer As Long, ByVal buffer_length As Long, ByRef overflow, ByVal channel As Integer, ByVal units As Integer, ByVal fill_missing As Integer) As Long
Declare Function usb_tc08_get_single Lib "c:\usbtc08.dll" (ByVal handle As Integer, ByRef temp As Single, ByRef overflow_flags, ByVal units As Integer) As Long

'==========================================================================
'    Shared API Calls

'    These functions are designed for use with the USB TC08,
'    however, they can (and should) still be used with the legacy API calls
'===========================================================================*/

Declare Function usb_tc08_open_unit Lib "c:\usbtc08.dll" () As Integer

Declare Function usb_tc08_close_unit Lib "c:\usbtc08.dll" (ByVal handle As Integer) As Integer

Declare Function usb_tc08_stop Lib "c:\usbtc08.dll" (ByVal handle As Integer) As Integer

Declare Function usb_tc08_set_mains Lib "c:\usbtc08.dll" (ByVal handle As Integer, ByVal sixty_hertz As Integer) As Integer

Declare Function usb_tc08_get_minimum_interval_ms Lib "c:\usbtc08.dll" (ByVal handle As Integer) As Long

Declare Function usb_tc08_get_formatted_info Lib "c:\usbtc08.dll" (ByVal handle As Integer, ByVal unit_info As String, ByVal string_length As Integer) As Integer

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

Declare Function usb_tc08_get_last_error Lib "c:\usbtc08.dll" (ByVal handle As Integer) As Integer


'====================================================================
'    Legacy API Calls

'    Provided to aid backwards compatibility with code written
'    for old TC08 Units (differences exist).

'    These functions should not be used in new code and are
'    deprecated for removal in a future version of the driver.
'=====================================================================

Declare Function usb_tc08_legacy_run Lib "c:\usbtc08.dll" (ByVal handle As Integer) As Integer

Declare Function usb_tc08_legacy_set_channel Lib "c:\usbtc08.dll" (ByVal handle As Integer, ByVal channel As Integer, ByVal tc_type As Integer, ByVal filter_factor As Integer, ByVal offset As Integer, ByVal slope As Integer) As Integer

Declare Function usb_tc08_legacy_get_temp Lib "c:\usbtc08.dll" (ByVal handle As Integer, ByRef temp As Long, ByVal channel As Integer, ByVal filtered As Integer) As Integer

Declare Function usb_tc08_legacy_get_cold_junction Lib "c:\usbtc08.dll" (ByVal handle As Integer, ByRef temp As Long) As Integer

Declare Function usb_tc08_legacy_get_driver_version Lib "c:\usbtc08.dll" () As Integer

Declare Function usb_tc08_legacy_get_version Lib "c:\usbtc08.dll" (ByVal handle As Integer, ByRef version As Integer) As Integer

Declare Function usb_tc08_legacy_get_cycle Lib "c:\usbtc08.dll" (ByRef cycle As Long, ByVal handle As Integer) As Integer


Option Explicit

Dim tc08_handle As Integer
Dim in_timer As Integer

Private Sub Close_Click()
  If (tc08_handle > 0) Then
    usb_tc08_close_unit (tc08_handle)
    tc08_handle = 0
    txtComments.Text = "TC-08 closed"
  End If
End Sub

Private Sub Open_Click()
  Dim ok As Integer
  Dim usbtc08Info As String * 80
   
  If (tc08_handle < 1) Then
    txtComments.Text = "Opening TC-08"
    txtComments.Refresh
    tc08_handle = usb_tc08_open_unit()
    If (tc08_handle > 0) Then
   
      ok = usb_tc08_get_unit_info2(tc08_handle, usbtc08Info, 80, 4)
      txtComments.Text = "USBTC-08 Opened                                  " + "Serial: " + usbtc08Info
     
      Call usb_tc08_set_mains(tc08_handle, True)
      ok = usb_tc08_set_channel(tc08_handle, 0, Asc("K"))
      ok = usb_tc08_set_channel(tc08_handle, 1, Asc("K"))
      ok = usb_tc08_set_channel(tc08_handle, 2, Asc("K"))
      ok = usb_tc08_set_channel(tc08_handle, 3, Asc("K"))
      ok = usb_tc08_set_channel(tc08_handle, 4, Asc("K"))
      ok = usb_tc08_set_channel(tc08_handle, 5, Asc("K"))
      ok = usb_tc08_set_channel(tc08_handle, 6, Asc("K"))
      ok = usb_tc08_set_channel(tc08_handle, 7, Asc("K"))
      ok = usb_tc08_set_channel(tc08_handle, 8, Asc("K"))
    Else
      If (tc08_handle = 0) Then
        txtComments.Text = "Unable to open TC-08"
      Else
        txtComments.Text = "Error Code: " & usb_tc08_get_last_error(0)
      End If
    End If
  End If
 
End Sub


Private Sub Timer1_Timer()
  ReDim temp_buffer(9) As Single
  Dim overflow_flag As Integer
  Dim ok As Integer

  If (tc08_handle > 0) Then
    If (Not in_timer) Then
      in_timer = True
    ok = usb_tc08_get_single(tc08_handle, temp_buffer(0), overflow_flag, 0)
     
      If (ok) Then
        txtCJC.Text = temp_buffer(0)
        txtChannel1.Text = temp_buffer(1)
        txtChannel2.Text = temp_buffer(2)
        txtChannel3.Text = temp_buffer(3)
        txtChannel4.Text = temp_buffer(4)
        txtChannel5.Text = temp_buffer(5)
        txtChannel6.Text = temp_buffer(6)
        txtChannel7.Text = temp_buffer(7)
        txtChannel8.Text = temp_buffer(8)
      End If
      in_timer = False
    End If
  End If
End Sub



Can anybody help me ?

Regards
Michael
MichaelV
Newbie
 
Posts: 0
Joined: Tue Feb 07, 2012 4:43 pm

Re: usb_tc08_get_single with USB TC08 & VB6

Postby MichaelV » Fri Feb 10, 2012 8:52 am

I had changed the declaration
ReDim temp_buffer(9) As Single to ReDim temp_buffer(10) As Single
after that change it works.

Regards
MichaelV
Newbie
 
Posts: 0
Joined: Tue Feb 07, 2012 4:43 pm


Return to VB and VBA (Excel, Access)

Who is online

Users browsing this forum: No registered users and 0 guests