|
|
| Author |
Message |
airalsie User

Joined: 15 Mar 2007
Posts: 2
|
Posted: Thu Mar 15, 2007 4:03 am Post subject: Declaration of dll subs and functions for TH03 |
|
|
Does anybody have succesfully converted the VB6 declaration of the dll to .Net?
I've written the below code but when executing the th03_get_temp method I don't get a value ("ok" = false), and after exactly two calls to the method I get an error about "attempting to read or write in protected memory". The init and setup of the ports works without error.
Declare Function th03_open_unit Lib "th0332.DLL" (ByVal Port As Int16) As Boolean
Declare Sub th03_close_unit Lib "th0332.DLL" (ByVal Port As Int16)
Declare Sub th03_set_channel Lib "th0332.DLL" (ByVal Port As Int16, ByVal channel As Int16, ByVal THtype As Int16, ByVal Factor As Int16)
Declare Sub th03_poll_driver Lib "th0332.DLL" ()
Declare Function th03_get_temp Lib "th0332.DLL" (ByVal value As Int32, ByVal Port As Int16, ByVal channel As Int16, ByVal filtered As Boolean) As Boolean
Declare Function th03_set_ref_update Lib "th0332.DLL" (ByVal Port As Int16, ByVal Rate As Int16) As Boolean
Declare Function th03_get_version Lib "th0332.DLL" (ByVal value As Int16, ByVal Port As Int16) As Boolean
Declare Function th03_get_cycle Lib "th0332.DLL" (ByVal cycle As Int32, ByVal Port As Int16) As Boolean
Declare Function GetTickCount Lib "kernel32" () As Int32
Dim Port As Int16
Dim version As Int16
Dim temperature As Int32
Dim ok As Boolean
Dim Ticks As Long
Sub GetData()
Port = 1
Log("Opening the TH03 on COM" & Port)
ok = th03_open_unit(Port)
If ok Then
Log("TH03 opened")
Else
Log("Cannot open the TH03")
Exit Sub
End If
' Set Channels 1 and 2 for a standard thermistor (low temp), filter factor 10
Call th03_set_channel(Port, 1, 1, 10)
Call th03_set_channel(Port, 2, 1, 10)
' Get 20 readings at 1-second intervals
For i As Int16 = 1 To 20
Ticks = GetTickCount()
While GetTickCount() < Ticks + 1000
Application.DoEvents()
th03_poll_driver()
End While
' Get the reading
ok = th03_get_temp(temperature, Port, 1, False)
If ok Then
Log(temperature / 100)
Else
Log("****")
End If
ok = th03_get_temp(temperature, Port, 2, False)
If ok Then
Log(temperature / 100)
Else
Log("****")
End If
Next i
' Close the driver
Call th03_close_unit(Port)
End Sub
Private Sub Log(ByVal str As String)
'
End Sub
PS. I'm successfully running the Excel demo app (but this is VBA6 code anyway).
Regards, |
|
| Back to top |
|
 |
markB Site Admin

Joined: 27 Mar 2007
Posts: 80
Location: Cambridgeshire,UK
|
Posted: Tue Mar 27, 2007 10:17 am Post subject: |
|
|
You need to pass 'value' in such a way that the called procedure can change the value of a variable underlying the argument (or as a pointer in C):
Declare Function th03_get_temp Lib "th0332.DLL" (ByRef value As Int32, ByVal Port As Int16, ByVal channel As Int16, ByVal filtered As Boolean) As Boolean |
|
| Back to top |
|
 |
airalsie User

Joined: 15 Mar 2007
Posts: 2
|
Posted: Tue Mar 27, 2007 11:27 am Post subject: Thanks! |
|
|
| Of course! It solved the issue and now it's working. |
|
| Back to top |
|
 |
|
Powered by phpBB © 2001, 2005 phpBB Group
|