THUM DLL .Net PDF Print

Sample Visual Basic.Net 2003 and newer code to take readings from the THUM using DLL

Functions

Read - instructs the THUM device to take a reading.  It will read both temperature and humidity.
GetTempUnit - returns the unit of temperature as 1 or 2 (1 means °C or 2 means °F)
SetTempUnit - sets the unit of temperature - valid values 1 or 2 (1 sets to °C and 2 sets to °F)
GetTemp - returns the temperature in the units set by SetTempUnit
GetRH - returns the relative humidity reading
GetDewPt - returns the dew point reading
Reset - resets the THUM device - generally this function is not needed

 

Possible Error Codes returned from functions

THUM_ERROR_SUCCESS             0   // no error
THUM_ERROR_BADTEMPUNIT      1   // bad temperature unit (not 1 or 2)
THUM_ERROR_THUMNOTFOUND  2   // THUM device not found
THUM_ERROR_READTIMEOUT     3   // Read operation timed out
THUM_ERROR_WRITEFAILED       4   // Write operation failed
THUM_ERROR_READFAILED         5   // Read operation failed
THUM_ERROR_RESULTOUTOFRANGE   6   // Temp or RH was out of range

Note: Readings can not be taken from the THUM faster than one reading every 3 seconds. Taking readings faster than this could raise the internal temperature of the sensor. This could skew the temperature and RH readings returned from the THUM.

License:

We require that you purchase one copy of a control per developer on a project. If this is met, you may distribute the DLL with your application royalty free. You may never distribute the .h file.

Usage Notes: 

  • It usually works best to have the thum.dll in the project directory and change the DllImport lines accordingly.
  • 64 bit systems - The thum.dll is a 32 bit dll written in VC++ 6.0.   In your .Net project you need to set the Target cpu in the Advance Compile Settings to be x86 instead of AnyCPU.


Sample Visual Basic.Net 2003 code to read values from the THUM

 

'**************************Module**********************
Imports System.Runtime.InteropServices

Module Module1

<DllImport("C:\My Documents\Visual Studio Projects\THUMdllTest\thum.dll")> _
Public Function Read() As Integer
'Tell the THUM unit to take a temperature and RH reading.
End Function
<DllImport("C:\My Documents\Visual Studio Projects\THUMdllTest\thum.dll")> _
Public Function GetTemp() As Double
'get temperature reading
End Function
<DllImport("C:\My Documents\Visual Studio Projects\THUMdllTest\thum.dll")> _
Public Function SetTempUnit(ByVal cUnit As Double) As Integer
'Sets the temperature unit (to F or C).
End Function
<DllImport("C:\My Documents\Visual Studio Projects\THUMdllTest\thum.dll")> _
Public Function GetRH() As Double
'Gets the relative humidity from the THUM unit.
End Function
<DllImport("C:\My Documents\Visual Studio Projects\THUMdllTest\thum.dll")> _
Public Function GetTempUnit() As Integer
'Gets the temperatire unit (F or C).
End Function
<DllImport("C:\My Documents\Visual Studio Projects\THUMdllTest\thum.dll")> _
Public Function GetDewPt() As Double
'Gets the dew point from the unit.
End Function
<DllImport("C:\My Documents\Visual Studio Projects\THUMdllTest\thum.dll")> _
Public Function Reset() As Integer
'Reset THUM unit.
End Function
End Module


'********************Code in Button*******************
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim iRetVal As Integer 'Return Value.
Dim dblTempUnits As Double
dblTempUnits = 2
iRetVal = SetTempUnit(dblTempUnits)
MsgBox(iRetVal)
iRetVal = Read()
MsgBox(iRetVal)
Msgbox GetTemp()
End Sub