usb_tc08_get_temp with USB TC08 & VB6

Post your VB and VBA discussions here
Post Reply
cr79

usb_tc08_get_temp with USB TC08 & VB6

Post by cr79 »

Hello Support,
Need some help.

I am trying to collect data from USB TC-08 through my VB6 program.

I have array of textbox. txtChannel0 to txtChannel1 (0 = CJ and other for K Type TC)
below is my code on cmdStart_click

Code: Select all

Private Sub cmdStart_Click()
    If (tc08_handle > 0) Then
        Timer1.Interval = txtSampRate.Text
        Call usb_tc08_run(tc08_handle, txtSampRate.Text)
    End If
End Sub
I am using a timer interval same as sampling rate. what if i use timer interval less then sampling rate ?

and below code is in my timer1_timer

Code: Select all

Private Sub Timer1_Timer()
    Dim iCh As Integer
    Dim temp_buffer(9) As Single
    Dim times_ms_buffer As Long
    Dim overflow_fleg(9) As Integer
    Dim bLength As Long
    Dim noOfReading As Long
    bLength = 100
    
    Dim flag As Integer

    If (tc08_handle > 0) Then
        If (Not in_timer) Then
            txtComments.Text = ""
            in_timer = True
            For iCh = 0 To 8
                noOfReading = usb_tc08_get_temp(tc08_handle, temp_buffer(iCh), times_ms_buffer, bLength, overflow_fleg(iCh), iCh, cmbTempUnit.ListIndex, 1)
                txtChannel(iCh).Text = temp_buffer(iCh)
                txtTimeStamp.Text = times_ms_buffer
            Next iCh
            in_timer = False
            txtComments.Text = "Error Code: " & usb_tc08_get_last_error(0)
        End If
    End If
End Sub
I am not sure whether usb_tc08_get_temp is under correct loop or not and
the parameters are ok or not.
Second thing, if i set ch1 to collect data, it shows reading in txtChannel(1) and txtChannel(2).

Best Regards
CR

cr79

Re: usb_tc08_get_temp with USB TC08 & VB6

Post by cr79 »

Hello Again,

Now, I have modified the code.

Code: Select all

Private Sub cmdStart_Click()
Dim intSamplingRate As Integer
intSamplingRate = 2000
    
    If (tc08_handle > 0) Then
        Timer1.Interval = (intSamplingRate)
        Call usb_tc08_run(tc08_handle, intSamplingRate)
    End If
End Sub

Private Sub Timer1_Timer()
    
    Dim temp_buffer(9) As Single
    Dim times_ms_buffer As Long
    Dim overflow_fleg(9) As Integer
    Dim bLength As Long
    Dim noOfReading As Long
    bLength = 500
    iCh = 0
    
    Dim flag As Integer

    If (tc08_handle > 0) Then
        If (Not in_timer) Then
            txtComments.Text = ""
            in_timer = True

            For iCh = 0 To 8
                noOfReading = usb_tc08_get_temp(tc08_handle, temp_buffer(iCh), times_ms_buffer, bLength, overflow_fleg(iCh), iCh, cmbTempUnit.ListIndex, 0)
            Next iCh
            
            txtTimeStamp.Text = times_ms_buffer
            Debug.Print "---------- " & "times_buffer = " & times_ms_buffer & " ----------"
            For iCh = 0 To 8
                txtChannel(iCh).Text = temp_buffer(iCh)
                Debug.Print "Channel No = " & iCh & ", Reading = " & Round(temp_buffer(iCh), 2)
            Next iCh
            in_timer = False
            txtComments.Text = "Error Code: " & usb_tc08_get_last_error(0)
        End If
    End If
End Sub
Output is

Code: Select all

---------- times_buffer = 0 ----------
Channel No = 0, Reading = 0
Channel No = 1, Reading = 0
Channel No = 2, Reading = 26.85
Channel No = 3, Reading = 26.84
Channel No = 4, Reading = 27.65
Channel No = 5, Reading = 27.64
Channel No = 6, Reading = 25.91
Channel No = 7, Reading = 25.93
Channel No = 8, Reading = 0
---------- times_buffer = 4000 ----------
Channel No = 0, Reading = 0
Channel No = 1, Reading = 0
Channel No = 2, Reading = 26.84
Channel No = 3, Reading = 26.82
Channel No = 4, Reading = 27.63
Channel No = 5, Reading = 27.58
Channel No = 6, Reading = 25.96
Channel No = 7, Reading = 25.98
Channel No = 8, Reading = 0
---------- times_buffer = 8000 ----------
Channel No = 0, Reading = 0
Channel No = 1, Reading = 0
Channel No = 2, Reading = 26.88
Channel No = 3, Reading = 26.86
Channel No = 4, Reading = 27.56
Channel No = 5, Reading = 27.55
Channel No = 6, Reading = 25.95
Channel No = 7, Reading = 25.98
Channel No = 8, Reading = 0
---------- times_buffer = 12000 ----------
Channel No = 0, Reading = 0
Channel No = 1, Reading = 0
Channel No = 2, Reading = 26.83
Channel No = 3, Reading = 26.81
Channel No = 4, Reading = 27.56
Channel No = 5, Reading = 27.58
Channel No = 6, Reading = 25.94
Channel No = 7, Reading = 25.94
Channel No = 8, Reading = 0
So, I think I am doing something wrong. times_buffer shows double then sampling rate and
noOfReading shows 2 for Ch2, Ch4 and Ch6.
second reading of Ch2 goes in temp_buffer(3),
second reading of Ch4 goes in temp_buffer(5) and
second reading of Ch6 goes in temp_buffer(7).

But if I increase the timer speed (double then sampling rate) i get correct output.
Code of cmdStart_Click below. Timer1_Timer remains same.

Code: Select all

Private Sub cmdStart_Click()
Dim intSamplingRate As Integer
intSamplingRate = 2000
    
    If (tc08_handle > 0) Then
        Timer1.Interval = (intSamplingRate / 2)
        Call usb_tc08_run(tc08_handle, intSamplingRate)
    End If
End Sub
Output is

Code: Select all

---------- times_buffer = 0 ----------
Channel No = 0, Reading = 0
Channel No = 1, Reading = 0
Channel No = 2, Reading = 26.41
Channel No = 3, Reading = 0
Channel No = 4, Reading = 27.49
Channel No = 5, Reading = 0
Channel No = 6, Reading = 25.29
Channel No = 7, Reading = 0
Channel No = 8, Reading = 0
---------- times_buffer = 2000 ----------
Channel No = 0, Reading = 0
Channel No = 1, Reading = 0
Channel No = 2, Reading = 26.39
Channel No = 3, Reading = 0
Channel No = 4, Reading = 27.5
Channel No = 5, Reading = 0
Channel No = 6, Reading = 25.29
Channel No = 7, Reading = 0
Channel No = 8, Reading = 0
---------- times_buffer = 4000 ----------
Channel No = 0, Reading = 0
Channel No = 1, Reading = 0
Channel No = 2, Reading = 26.36
Channel No = 3, Reading = 0
Channel No = 4, Reading = 27.51
Channel No = 5, Reading = 0
Channel No = 6, Reading = 25.27
Channel No = 7, Reading = 0
Channel No = 8, Reading = 0
---------- times_buffer = 6000 ----------
Channel No = 0, Reading = 0
Channel No = 1, Reading = 0
Channel No = 2, Reading = 26.37
Channel No = 3, Reading = 0
Channel No = 4, Reading = 27.48
Channel No = 5, Reading = 0
Channel No = 6, Reading = 25.25
Channel No = 7, Reading = 0
Channel No = 8, Reading = 0
---------- times_buffer = 8000 ----------
Channel No = 0, Reading = 0
Channel No = 1, Reading = 0
Channel No = 2, Reading = 26.39
Channel No = 3, Reading = 0
Channel No = 4, Reading = 27.46
Channel No = 5, Reading = 0
Channel No = 6, Reading = 25.24
Channel No = 7, Reading = 0
Channel No = 8, Reading = 0
I think this is correct output and noOfReading shows 1.
But I am confused, why I have to read the buffer at double speed then sampling speed ?
Is there something I am missing ?

Please help and correct my mistake.

Best Regards
CR.

cr79

Re: usb_tc08_get_temp with USB TC08 & VB6

Post by cr79 »

Hello Again,

I am still not able to find the solution.
Can anyone guide me please ?

In streaming mode USB TC-08 takes 2 samples in the given sampling rate.
Moreover, it stores readings of second sample in the space of next channel.

Best Regards

Chris
Site Admin
Site Admin
Posts: 169
Joined: Tue Aug 17, 2010 9:00 am
Location: St. Neots

Re: usb_tc08_get_temp with USB TC08 & VB6

Post by Chris »

The TC-08 will collect data from the enabled channels at intervals set in the call to usb_tc08_run

(The interval value passed in the usb_tc08_run call needs to be 2x the required interval. This issue has been reported to the development team)

You are using a timer to call the usb_tc08_get_temp function.

If your timer is set to be faster than the sample interval set in usb_tc08_run, the last values read will be read again.

If your timer is set to be slower than the sample interval set in usb_tc08_run, values will be stored up until the usb_tc08_get_temp function is called....

i.e. if usb_tc08_run is set to sample at 1 second, and the timer calls usb_tc08_get_temp every 10 seconds, 10 readings will be read into the allocated buffers.

usb_tc08_get_temp is called for each channel required, so all values in the reading_buffer[channel] will relate to the channel set when the function is called.


Note: In your example code, you have set the buffers size to 9, but have passed a buffer length bLength = 100
This could cause a buffer overrun. Best to allocate more buffer space than required.

Post Reply