works in VB6 but NOT in VB.NET....datatype problem?

Post your .Net discussions here
Post Reply
homer
User
User
Posts: 2
Joined: Wed Feb 27, 2019 9:47 am

works in VB6 but NOT in VB.NET....datatype problem?

Post by homer »

I am writing code for TC08 in VB.NET
I have written a very simple program in VB6 that works 100%
However, if I try to use exactly the same code in VB.NET (adjusted obviously for differences in syntax and language constraints) when trying to retrieve all 8 channels I get the same Cold Junction temperature returned for ALL channels (unlike the VB6 version which performs as required)
I suspect it is something to do with the data type differences between VB6 and VB.NET.
In VB.NET...……..

Public temperature() As Single

some more code etc

ReDim temperature(9)

set mains etc...…….. here.

' activates CJ channel
Status = usb_tc08_set_channel(usbTC08HandleA, 0, Asc("R"))

'reads temp of cold junction
Status = usb_tc08_get_single(usbTC08HandleA, temperature(0), overflow_flag, 0)
If Status > 0 Then
Label1.Text = Label1.Text + vbCrLf + "CJ=" + CStr(temperature(0))
Else
Label1.Text = Label1.Text + "CJ failed to read"
End If

'set channel 'zone' as enabled
Dim zone As Integer
For zone = 1 To 8
Status = usb_tc08_set_channel(usbTC08HandleA, zone, Asc("R"))
Status = usb_tc08_get_single(usbTC08HandleA, temperature(zone), overflow_flag, 0)
Next

' read all 8 channels
status = usb_tc08_get_single(usbTC08HandleA, temperature(0), overflow_flag, 0)

This structure works perfectly in VB6 but not VB.NET?
After above call (in VB.NET+, the array temperature() contains (say)
temperature(0) 20.1234
temperature(1) 20.6357
temperature(2) 20.8373
etc etc
temperature(8) 20.2323

in VB6 ………..
temperature(0) 20.1234
temperature(1) 1020.34
temperature(2) 1040.23
etc etc
temperature(8) 999.456
Any ideas?

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

Re: works in VB6 but NOT in VB.NET....datatype problem?

Post by Martyn »

Have you checked the example code on GitHub ?
Martyn
Technical Support Manager

homer
User
User
Posts: 2
Joined: Wed Feb 27, 2019 9:47 am

Re: works in VB6 but NOT in VB.NET....datatype problem?

Post by homer »

Yes,
this is where the basic structure of (my) code came from...………..
From GITHUB sample code...…….

17 Dim status As Short
18 Dim usbtc08Handle As Short
19 Dim info As String
20 Dim minimumIntervalMS As Integer
21 Dim tempBuffer(8) As Single
22 Dim count As Integer
23 Dim overflowFlag As Short
24 Dim keypress As Boolean

etc

59 ' Set Channels - Cold Junction, Ch 1 and Ch 2
60 status = usb_tc08_set_channel(usbtc08Handle, USBTC08Channels.USBTC08_CHANNEL_CJC, "K")
61 status = usb_tc08_set_channel(usbtc08Handle, USBTC08Channels.USBTC08_CHANNEL_1, "K")
62 status = usb_tc08_set_channel(usbtc08Handle, USBTC08Channels.USBTC08_CHANNEL_2, "K")

etc

75 status = usb_tc08_get_single(usbtc08Handle, tempBuffer(0), overflowFlag, USBTC08TempUnits.USBTC08_UNITS_CENTIGRADE)

77 Console.Write("{0:F}", tempBuffer(0).ToString() & vbTab)
78 Console.Write("{0:F}", tempBuffer(1).ToString() & vbTab)
79 Console.Write("{0:F}", tempBuffer(2).ToString() & vbTab)

My Code...………

Public temperature() As Single

etc

ReDim temperature(9)

etc

'set channel 'zone' as enabled
Dim zone As Integer
For zone = 1 To 8
Status = usb_tc08_set_channel(usbTC08HandleA, zone, Asc("R"))
[Status = usb_tc08_get_single(usbTC08HandleA, temperature(zone), overflow_flag, 0)
Next

' read all 8 channels
status = usb_tc08_get_single(usbTC08HandleA, temperature(0), overflow_flag, 0)

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

Re: works in VB6 but NOT in VB.NET....datatype problem?

Post by Martyn »

I have just taken the code "as is" from GitHub and run it on VB.Net 2017 64bit and it runs fine, I get three channels of data repeated 10 times over 10 seconds. You get a reading from each channel every second that changes if the temperature of that channel is changing.

The delays are important to allow the conversions to complete otherwise the driver will return the previous value, which will possibly be the CJC temperature on the first iteration.

Can you post your complete code, or send it to support@picotech.com so that we can then run it to see what the issue is.
Martyn
Technical Support Manager

homer
User
User
Posts: 2
Joined: Wed Feb 27, 2019 9:47 am

Re: works in VB6 but NOT in VB.NET....datatype problem?

Post by homer »

Hi Martyn,
thanks for your kind offer to examine my code. Just before sending it off to you I thought I had better double check that I was sending you the correct code.
In doing so I spotted the cause of my problem.
It was in the definition of the DLL call...……………..

A)
Declare Function usb_tc08_set_channel Lib "usbtc08.dll" (ByVal handle As Short, ByVal channel As USBTC08Channels, ByVal tc_type As Char) As Short

B)
Declare Function usb_tc08_set_channel Lib "usbtc08.dll" (ByVal handle As Integer, ByVal channel As Integer, ByVal tc_type As Byte) As Integer

B) works...……..
.



A) does not

A) comes from IMPORTS.VB in GitHub example...……...
43 Declare Function usb_tc08_set_channel Lib "usbtc08.dll" (ByVal handle As Short, ByVal channel As USBTC08Channels, ByVal tc_type As Char) As Short
44

Again, thanks for your offer of support etc, much appreciated.
regards
Garry

Post Reply