Jump to content

Thermometer Graph and Log


andybiochem
 Share

Recommended Posts

Hi,

One can buy USB Thermometers that can measure the temperature of liquids etc using an external sensor on a lead.

(These go under names such as TEMPer HID, TEMPerNTC, TEMPer2 etc etc. The unit I have is the "TEMPer1", and as such I don't know if the following software will work with any other versions)

NOTE: This script works for my TEMPer1 devices bought between Nov '09 and Feb '10 and a couple of other people confirm it works for theirs. However, others have had problems with devices bought recently (see replies below). The manufacturers seem to be continuously changing the architecture & software for the devices so this may or may not work for your TEMPer1 device!!!!!

Unfortunately the supplied software is somewhat difficult to get working the way I want it, so I spent ages trying to find a way to control the device via the dll that comes with the original software. After some help from ProgAndy and Mat, I finally managed to make use of the dll.

After a lot of deliberation, I decided to split up my own program into two sections, the first being a simple data log script, and the second a graphing program to display the data. I'll deal with the two separately.

Temperature Data Logger

This simply reads the temperture from all devices attached to the system, and writes it to a TempLog.txt along with a date stamp and device number.

#NoTrayIcon
$hDll = DLLOpen("HidFTDll.dll")
$aiNDevices = DllCall($hDll,"int:cdecl","EMyDetectDevice", 'long', 0)
$sString = ""
For $i = 1 to $aiNDevices[0]
    DllCall($hDll,"none:cdecl","EMySetCurrentDev", 'int',$i - 1)
    DllCall($hDll,"bool:cdecl","EMyInitConfig", 'bool', True)
    $aiTemp = DllCall($hDll,"double:cdecl","EMyReadTemp", 'bool', True)
    $sString &= $i & "," & @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & "," & $aiTemp[0] & @CRLF
Next
$sString = StringStripWS($sString,2)
FileWriteLine("TempLog.txt",$sString)
DllClose($hDll)

Compiled : GetTemp.exe - Old version

Compiled : GetTemp.exe - improved precision

Temperature Graph Program

;*********************************************
; INCLUDES
;*********************************************
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <Math.au3>
#include <Date.au3>
#include <Misc.au3>
#include <File.au3>
#include "GraphGDIPlus.au3"
#include "Table.au3"



;*********************************************
; OPTS
;*********************************************
Opt("GUIOnEventMode", 1)
Opt("MouseCoordMode", 2)
Opt("PixelCoordMode", 2)


;*********************************************
; VARIABLES
;*********************************************

Global $aTEMPERATURE[1][3][3];["",current item ...]["",unit1,unit2]["",date,temp]

Global $iGraphTempLow = 0
Global $iGraphTempHigh = 100
Global $iGraphTimeLow = 0
Global $iGraphTimeHigh = 90 ;minutes
Global $iRound = 0
Global $iLine1 = 60
Global $iLine2 = 65
Global $iLine3 = 70
Global $iLineCol = "0x55FF0000"

Global $pINI = "Data.ini"

Global $iDevices = IniRead($pINI, "devices", "number", 2)
Global $cDevice1Col = "000000"
Global $cDevice2Col = "0084ff"
Global $iSeeThrough = "99"

Global $bRunning = False
Global $bFirstRun = True
Global $bRESET = False
Global $sStartTime = _NowCalc()
Global $iIndexCounter = 1
Global $iCaptureTime = 1000

Global $bAutoResizeAxisX = True
Global $iEWMAWeight = 1
Global $iAverageN = 3

Global $aDeviceCorrection[3][4] ;["",unit1,unit2]["",slope,offset,bias]
$aDeviceCorrection[1][1] = IniRead($pINI, "calibration", "device1slope", 1)
$aDeviceCorrection[1][2] = IniRead($pINI, "calibration", "device1offset", 0)
$aDeviceCorrection[2][1] = IniRead($pINI, "calibration", "device2slope", 1)
$aDeviceCorrection[2][2] = IniRead($pINI, "calibration", "device2offset", 0)
$aDeviceCorrection[1][3] = IniRead($pINI, "calibration", "device1bias", 0) ;bias
$aDeviceCorrection[2][3] = IniRead($pINI, "calibration", "device2bias", 0) ;bias


;*********************************************
; GUI
;*********************************************
;----- GUI -----
$GUI = GUICreate("", 1000, 530)
GUISetOnEvent(-3, "_Close")
GUISetState()

;----- Calibration -----
$iYshift = -8
GUICtrlCreateGroup(" Calibration ", 792, 8, 194, 493)
GUICtrlSetFont(-1, -1, 800)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;- table setup -
GUICtrlCreateLabel("", 800, 26, 179, 72, 0x07) ;border
GUICtrlSetState(-1, 128)
$TABLE = _GUICtrlTable_Create(801, 35 + $iYshift, 34, 25, 3, 5, 0)
_GUICtrlTable_Set_ColumnWidth($TABLE, 1, 21)
_GUICtrlTable_Set_ColumnWidth($TABLE, 2, 54)
_GUICtrlTable_Set_RowHeight($TABLE, 1, 20)
_GUICtrlTable_Set_Text_Row($TABLE, 1, "|Temp|Offset|Slope|Bias")
_GUICtrlTable_Set_Text_Column($TABLE, 1, "|1|2", "|", 0)
_GUICtrlTable_Set_Justify_All($TABLE, 1, 1)
_GUICtrlTable_Set_CellColor_Row($TABLE, 1, 0xdddddd)
_GUICtrlTable_Set_TextFont_Cell($TABLE, 2, 2, 12, 800)
_GUICtrlTable_Set_TextFont_Cell($TABLE, 3, 2, 12, 800)
;- label handles -
Global $hOffsetLabel1 = _GUICtrlTable_CellGetID($TABLE, 2, 3)
Global $hSlopeLabel1 = _GUICtrlTable_CellGetID($TABLE, 2, 4)
Global $hBiasLabel1 = _GUICtrlTable_CellGetID($TABLE, 2, 5)
Global $hOffsetLabel2 = _GUICtrlTable_CellGetID($TABLE, 3, 3)
Global $hSlopeLabel2 = _GUICtrlTable_CellGetID($TABLE, 3, 4)
Global $hBiasLabel2 = _GUICtrlTable_CellGetID($TABLE, 3, 5)
;- label events -
GUICtrlSetOnEvent($hOffsetLabel1, "_Calibrate_Wrapper")
GUICtrlSetOnEvent($hSlopeLabel1, "_Calibrate_Wrapper")
GUICtrlSetOnEvent($hOffsetLabel2, "_Calibrate_Wrapper")
GUICtrlSetOnEvent($hSlopeLabel2, "_Calibrate_Wrapper")
GUICtrlSetOnEvent($hBiasLabel1, "_Calibrate_Wrapper")
GUICtrlSetOnEvent($hBiasLabel2, "_Calibrate_Wrapper")
;- label loading -
GUICtrlSetData($hOffsetLabel1, $aDeviceCorrection[1][2])
GUICtrlSetData($hSlopeLabel1, $aDeviceCorrection[1][1])
GUICtrlSetData($hOffsetLabel2, $aDeviceCorrection[2][2])
GUICtrlSetData($hSlopeLabel2, $aDeviceCorrection[2][1])
GUICtrlSetData($hBiasLabel1, $aDeviceCorrection[1][3])
GUICtrlSetData($hBiasLabel2, $aDeviceCorrection[2][3])
;- progress bar -
$p = GUICtrlCreateProgress(801, 98, 177, 5, 0x01)
;- input switch -
$iYshift += 20
$checkboxSwitchInputs = GUICtrlCreateCheckbox("Switch Device Inputs", 828, 100 + $iYshift, 130, 15, 0x0020)
If $iDevices = 1 Then GUICtrlSetState(-1, 128)

;----- Smoothing control -----
GUICtrlCreateGroup(" Smoothing ", 792, 133, 194, 324)
GUICtrlSetFont(-1, -1, 800)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$iYshift += 20
GUICtrlCreateLabel("N Average results", 813, 123 + $iYshift, 100, 15)
$inputAverageN = GUICtrlCreateInput($iAverageN, 900, 120 + $iYshift, 70, 20, 0x1)
GUICtrlCreateLabel("EWMA Weight", 813, 153 + $iYshift - 10, 80, 15)
$inputEWMAWeight = GUICtrlCreateInput($iEWMAWeight, 900, 150 + $iYshift - 10, 70, 20, 0x1)

;----- Axis setup -----
GUICtrlCreateGroup(" Axes ", 792, 197, 194, 260)
GUICtrlSetFont(-1, -1, 800)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;- x -
$xshift = 765
$yshift = 130 + 25
GUICtrlCreateLabel("x axis", 52 + $xshift, 60 + $yshift, 30, 17)
GUICtrlCreateLabel("_", 140 + $xshift, 55 + $yshift, 10, 19)
$inputXlow = GUICtrlCreateInput($iGraphTimeLow, 88 + $xshift, 56 + $yshift, 49, 21, 0x1)
$inputXhigh = GUICtrlCreateInput($iGraphTimeHigh, 149 + $xshift, 56 + $yshift, 49, 21, 0x1)
$checkboxXAuto = GUICtrlCreateCheckbox("", $xshift + 201, 56 + $yshift, 15, 21)
;- y -
$xshift = 765
$yshift = 130 + 25 + 20
GUICtrlCreateLabel("y axis", 52 + $xshift, 60 + $yshift, 30, 17)
GUICtrlCreateLabel("_", 140 + $xshift, 55 + $yshift, 10, 19)
$inputYlow = GUICtrlCreateInput($iGraphTempLow, 88 + $xshift, 56 + $yshift, 49, 21, 0x1)
$inputYhigh = GUICtrlCreateInput($iGraphTempHigh, 149 + $xshift, 56 + $yshift, 49, 21, 0x1)
$checkboxYAuto = GUICtrlCreateCheckbox("", $xshift + 201, 56 + $yshift, 15, 21)

;----- marker lines -----
GUICtrlCreateGroup(" Markers ", 792, 260, 194, 241)
GUICtrlSetFont(-1, -1, 800)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$yshift = 130 + 5 + 36
$InputLine1 = GUICtrlCreateInput($iLine1, 810 - 6, 109 + $yshift, 51, 21, 0x1)
GUICtrlSetColor(-1, 0xFF0000)
$InputLine2 = GUICtrlCreateInput($iLine2, 870 - 6, 109 + $yshift, 51, 21, 0x1)
$InputLine3 = GUICtrlCreateInput($iLine3, 930 - 6, 109 + $yshift, 51, 21, 0x1)
GUICtrlSetColor(-1, 0xFF0000)

;----- Buttons -----
$bButtonpause = GUICtrlCreateButton("Reset Data", 800, 435, 178, 40)
GUICtrlSetOnEvent(-1, "_Reset")
$bButtonpause = GUICtrlCreateButton("Start", 800, 480, 178, 40)
GUICtrlSetOnEvent(-1, "_StartStop")
GUICtrlSetFont(-1, 14, 800)

;----- GRAPH -----
$GRAPH = _GraphGDIPlus_Create($GUI, 40, 14, 727, 481)
_GraphGDIPlus_Set_RangeX($GRAPH, $iGraphTimeLow, $iGraphTimeHigh, 12, 1)
_GraphGDIPlus_Set_RangeY($GRAPH, $iGraphTempLow, $iGraphTempHigh, 10, 1, 0)
_GraphGDIPlus_Set_PenSize($GRAPH, 1)
_GraphGDIPlus_Set_GridY($GRAPH, 2)
;----- draw initial marker lines -----
_GraphGDIPlus_Set_PenSize($GRAPH, 1)
_GraphGDIPlus_Set_PenDash($GRAPH, 1)
_GraphGDIPlus_Set_PenColor($GRAPH, $iLineCol)
;- red dashed lines -
_GraphGDIPlus_Plot_Start($GRAPH, $iGraphTimeLow, $iLine1)
If $iLine1 <> "" Then _GraphGDIPlus_Plot_Line($GRAPH, $iGraphTimeHigh, $iLine1)
_GraphGDIPlus_Plot_Start($GRAPH, $iGraphTimeLow, $iLine3)
If $iLine3 <> "" Then _GraphGDIPlus_Plot_Line($GRAPH, $iGraphTimeHigh, $iLine3)
;- black full line -
_GraphGDIPlus_Set_PenDash($GRAPH)
_GraphGDIPlus_Set_PenColor($GRAPH, 0xFF000000)
_GraphGDIPlus_Plot_Start($GRAPH, $iGraphTimeLow, $iLine2)
If $iLine2 <> "" Then _GraphGDIPlus_Plot_Line($GRAPH, $iGraphTimeHigh, $iLine2)
_GraphGDIPlus_Refresh($GRAPH)









FileDelete("TempLog.txt")
;##################################################################################
; LOOP
;##################################################################################
$iTimer = TimerInit()
While 1
    Sleep(100)
    If TimerDiff($iTimer) > $iCaptureTime And $bRunning = True Then
        _P(0)
        _UpdateTemperature()
        _P(100)
        $iTimer = TimerInit()
    EndIf
WEnd
;##################################################################################
; END LOOP
;##################################################################################



Func _StartStop()
    ;*********************************************
    ; Start / Stop control
    ;*********************************************
    Switch $bRunning
        Case False
            GUICtrlSetData($bButtonpause, "Stop")
        Case True
            GUICtrlSetData($bButtonpause, "Start")
    EndSwitch

    $bRunning = Not $bRunning

    If $bFirstRun = True Then $sStartTime = _NowCalc()
    $bFirstRun = False

EndFunc   ;==>_StartStop


Func _Reset()
    ;*********************************************
    ; Reset pressed
    ;*********************************************
    Switch MsgBox(4, "", "Sure to reset data?")
        Case 7
            Return
    EndSwitch

    $bRESET = True

EndFunc   ;==>_Reset


Func _UpdateTemperature()
    ;*********************************************
    ; Update from TEMPer programs
    ;*********************************************
    ;----- return if not running -----
    If $bRunning = False Then Return

    ;----- Get new data (prevent change mid function) -----
    $iSwitchInputs = GUICtrlRead($checkboxSwitchInputs)
    $iAverageN = GUICtrlRead($inputAverageN)
    $iEWMAWeight = GUICtrlRead($inputEWMAWeight) ;global var
    $iLine1 = GUICtrlRead($InputLine1)
    $iLine2 = GUICtrlRead($InputLine2)
    $iLine3 = GUICtrlRead($InputLine3)

    ;----- update counter -----
    $iIndexCounter += 1

    ;----- Resize array -----
    ReDim $aTEMPERATURE[$iIndexCounter][3][3]

    ;----- Get temperatures -----
    FileDelete("TempLog.txt")
    For $i = 1 To $iAverageN
        _P(($i / $iAverageN) * 70)
        RunWait(@ComSpec & " /C " & "GetTemp.exe", "", @SW_HIDE) ;prevents hourglass
    Next

    ;----- load temps from file -----
    Dim $aTemp[1]
    _FileReadToArray("TempLog.txt", $aTemp)
    For $j = 1 To $aTemp[0] ;for each entry
        $aData = StringSplit($aTemp[$j], ",")
        $aTEMPERATURE[$iIndexCounter - 1][$aData[1]][1] = $aData[2] ;date
        $aTEMPERATURE[$iIndexCounter - 1][$aData[1]][2] += $aData[3] ;temp
    Next
    FileDelete("TempLog.txt")

    ;----- switch inputs -----
    If $iSwitchInputs = 1 Then
        ;- switch dates -
        $iTemp = $aTEMPERATURE[$iIndexCounter - 1][1][1]
        $aTEMPERATURE[$iIndexCounter - 1][1][1] = $aTEMPERATURE[$iIndexCounter - 1][2][1]
        $aTEMPERATURE[$iIndexCounter - 1][2][1] = $iTemp
        ;- switch Temps -
        $iTemp = $aTEMPERATURE[$iIndexCounter - 1][1][2]
        $aTEMPERATURE[$iIndexCounter - 1][1][2] = $aTEMPERATURE[$iIndexCounter - 1][2][2]
        $aTEMPERATURE[$iIndexCounter - 1][2][2] = $iTemp
    EndIf

    ;----- Pre Calc checks -----
    $iDevice1 = True
    If $aTEMPERATURE[$iIndexCounter - 1][1][1] = "" Then $iDevice1 = False
    $iDevice2 = True
    If $aTEMPERATURE[$iIndexCounter - 1][2][1] = "" Then $iDevice2 = False

    ;----- Apply averaging -----
    $aTEMPERATURE[$iIndexCounter - 1][1][2] /= $iAverageN
    $aTEMPERATURE[$iIndexCounter - 1][2][2] /= $iAverageN

    ;----- Apply calibration correction -----
    $aTEMPERATURE[$iIndexCounter - 1][1][2] = ($aDeviceCorrection[1][1] * $aTEMPERATURE[$iIndexCounter - 1][1][2]) + $aDeviceCorrection[1][2] + $aDeviceCorrection[1][3]
    $aTEMPERATURE[$iIndexCounter - 1][2][2] = ($aDeviceCorrection[2][1] * $aTEMPERATURE[$iIndexCounter - 1][2][2]) + $aDeviceCorrection[2][2] + $aDeviceCorrection[2][3]

    ;----- Apply EWMA -----
    ;- set zeroeth index to current result (just to please EWMA n=1)
    $aTEMPERATURE[0][1][2] = $aTEMPERATURE[$iIndexCounter - 1][1][2]
    $aTEMPERATURE[0][2][2] = $aTEMPERATURE[$iIndexCounter - 1][2][2]
    ;- apply ewma -
    $aTEMPERATURE[$iIndexCounter - 1][1][2] = StringFormat("%.2f", ($iEWMAWeight * $aTEMPERATURE[$iIndexCounter - 1][1][2]) + ((1 - $iEWMAWeight) * $aTEMPERATURE[$iIndexCounter - 2][1][2]))
    $aTEMPERATURE[$iIndexCounter - 1][2][2] = StringFormat("%.2f", ($iEWMAWeight * $aTEMPERATURE[$iIndexCounter - 1][2][2]) + ((1 - $iEWMAWeight) * $aTEMPERATURE[$iIndexCounter - 2][2][2]))

    ;----- check for correct data -----
    If $iDevice1 = False Then $aTEMPERATURE[$iIndexCounter - 1][1][2] = "--"
    If $iDevice2 = False Then $aTEMPERATURE[$iIndexCounter - 1][2][2] = "--"

    ;----- Update Table -----
    _GUICtrlTable_Set_Text_Cell($TABLE, 2, 2, $aTEMPERATURE[$iIndexCounter - 1][1][2])
    _GUICtrlTable_Set_Text_Cell($TABLE, 3, 2, $aTEMPERATURE[$iIndexCounter - 1][2][2])

    ;----- display raw data -----
    ;ConsoleWrite($aTEMPERATURE[$iIndexCounter - 1][1][1] & " " & $aTEMPERATURE[$iIndexCounter - 1][1][2] & " ||| " & _
    ;$aTEMPERATURE[$iIndexCounter - 1][2][1] & " " & $aTEMPERATURE[$iIndexCounter - 1][2][2] & @CRLF)

    ;----- resize graph -----
    ;- y -
    If $iGraphTempLow <> GUICtrlRead($inputYlow) Or $iGraphTempHigh <> GUICtrlRead($inputYhigh) Then
        $iRound = 0
        $iGraphTempLow = GUICtrlRead($inputYlow)
        $iGraphTempHigh = GUICtrlRead($inputYhigh)
        If $iGraphTempHigh - $iGraphTempLow < 10 Then $iRound = 2
        _GraphGDIPlus_Set_RangeY($GRAPH, $iGraphTempLow, $iGraphTempHigh, 10, 1, $iRound)
    EndIf
    ;- x -
    If $iGraphTimeLow <> GUICtrlRead($inputXlow) Or $iGraphTimeHigh <> GUICtrlRead($inputXhigh) Then
        $iRound = 0
        $iGraphTimeLow = GUICtrlRead($inputXlow)
        $iGraphTimeHigh = GUICtrlRead($inputXhigh)
        If $iGraphTimeHigh - $iGraphTimeLow < 10 Then $iRound = 2
        _GraphGDIPlus_Set_RangeX($GRAPH, $iGraphTimeLow, $iGraphTimeHigh, 10, 1, $iRound)
    EndIf

    ;- check auto -
    ;- set max/min -
    $currMAX = _Max(Number($aTEMPERATURE[$iIndexCounter - 1][1][2]), Number($aTEMPERATURE[$iIndexCounter - 1][2][2]))
    $currMIN = _Min(Number($aTEMPERATURE[$iIndexCounter - 1][1][2]), Number($aTEMPERATURE[$iIndexCounter - 1][2][2]))
    ;- y -
    Switch GUICtrlRead($checkboxYAuto)
        Case 1
            If $currMAX > $iGraphTempHigh Then
                $iGraphTempHigh = (0.1 * ($iGraphTempHigh - $iGraphTempLow)) + $currMAX
                $iGraphTempHigh = Round($iGraphTempHigh, 2)
                GUICtrlSetData($inputYhigh, $iGraphTempHigh)
            EndIf
            If $currMIN < $iGraphTempLow Then
                $iGraphTempLow = $currMIN - (0.1 * ($iGraphTempHigh - $iGraphTempLow))
                $iGraphTempLow = Round($iGraphTempLow, 2)
                GUICtrlSetData($inputYlow, $iGraphTempLow)
            EndIf
            _GraphGDIPlus_Set_RangeY($GRAPH, $iGraphTempLow, $iGraphTempHigh, 10, 1, $iRound)
    EndSwitch
    ;- x -
    Switch GUICtrlRead($checkboxXAuto)
        Case 1
            If _DateDiff("s", $sStartTime, $aTEMPERATURE[$iIndexCounter - 1][1][1]) / 60 > (0.9 * $iGraphTimeHigh) Then
                $iGraphTimeHigh = 1.2 * _DateDiff("s", $sStartTime, $aTEMPERATURE[$iIndexCounter - 1][1][1]) / 60
                _GraphGDIPlus_Set_RangeX($GRAPH, $iGraphTimeLow, $iGraphTimeHigh, 10, 1, $iRound)
                GUICtrlSetData($inputXhigh, $iGraphTimeHigh)
            EndIf
    EndSwitch

    ;----- Check RESET -----
    Switch $bRESET
        Case True
            $bFirstRun = True
            $sStartTime = _NowCalc()
            $iIndexCounter = 1
            Dim $aTEMPERATURE[$iIndexCounter][3][3]
            $bRESET = False
    EndSwitch

    ;----- Draw marker lines -----
    _GraphGDIPlus_Clear($GRAPH)
    _GraphGDIPlus_Set_GridY($GRAPH, 2)
    _GraphGDIPlus_Set_PenSize($GRAPH, 1)
    _GraphGDIPlus_Set_PenDash($GRAPH, 1)
    _GraphGDIPlus_Set_PenColor($GRAPH, $iLineCol)
    ;- red dashed lines -
    _GraphGDIPlus_Plot_Start($GRAPH, $iGraphTimeLow, $iLine1)
    If $iLine1 <> "" Then _GraphGDIPlus_Plot_Line($GRAPH, $iGraphTimeHigh, $iLine1)
    _GraphGDIPlus_Plot_Start($GRAPH, $iGraphTimeLow, $iLine3)
    If $iLine3 <> "" Then _GraphGDIPlus_Plot_Line($GRAPH, $iGraphTimeHigh, $iLine3)
    ;- black full line -
    _GraphGDIPlus_Set_PenDash($GRAPH)
    _GraphGDIPlus_Set_PenColor($GRAPH, 0xFF000000)
    _GraphGDIPlus_Plot_Start($GRAPH, $iGraphTimeLow, $iLine2)
    If $iLine2 <> "" Then _GraphGDIPlus_Plot_Line($GRAPH, $iGraphTimeHigh, $iLine2)

    ;----- Graph data -----
    ;- 1 -
    _GraphGDIPlus_Set_PenSize($GRAPH, 3)
    _GraphGDIPlus_Set_PenDash($GRAPH)
    _GraphGDIPlus_Set_PenColor($GRAPH, "0x" & $iSeeThrough & $cDevice1Col)
    $bFirst = True
    For $i = 1 To $iIndexCounter - 1
        ;- check present -
        If $aTEMPERATURE[$i][1][2] = "--" Then ContinueLoop
        ;- calc x/y -
        $iX = _DateDiff("s", $sStartTime, $aTEMPERATURE[$i][1][1]) / 60
        $iY = Number($aTEMPERATURE[$i][1][2])
        ;- check start line -
        If $bFirst = True Then _GraphGDIPlus_Plot_Start($GRAPH, $iX, $iY)
        $bFirst = False
        ;- plot line -
        _GraphGDIPlus_Plot_Line($GRAPH, $iX, $iY)
        ;- progress -
    Next

    ;- 2 -
    _GraphGDIPlus_Set_PenColor($GRAPH, "0x" & $iSeeThrough & $cDevice2Col)
    $bFirst = True
    For $i = 1 To $iIndexCounter - 1
        ;- check present -
        If $aTEMPERATURE[$i][2][2] = "--" Then ContinueLoop
        ;- calc x/y -
        $iX = _DateDiff("s", $sStartTime, $aTEMPERATURE[$i][2][1]) / 60
        $iY = Number($aTEMPERATURE[$i][2][2])
        ;- check start line -
        If $bFirst = True Then _GraphGDIPlus_Plot_Start($GRAPH, $iX, $iY)
        $bFirst = False
        ;- plot line -
        _GraphGDIPlus_Plot_Line($GRAPH, $iX, $iY)
        ;- progress -
    Next

    ;----- Refresh data -----
    _GraphGDIPlus_Refresh($GRAPH)

EndFunc   ;==>_UpdateTemperature


Func _Calibrate_Wrapper()
    ;*********************************************
    ; Wrapper for Calibrate func
    ;*********************************************
    GUICtrlSetData($bButtonpause, "Start")
    _Calibrate(@GUI_CtrlId)
    If $bRunning = True Then GUICtrlSetData($bButtonpause, "Stop")

EndFunc   ;==>_Calibrate_Wrapper


Func _Calibrate($GUI_CtrlId)
    ;*********************************************
    ; Set Calibration data (passed from wrapper)
    ;*********************************************
    ;----- Calculate Cal data? -----
    Switch $GUI_CtrlId
        Case $hOffsetLabel1, $hSlopeLabel1, $hOffsetLabel2, $hSlopeLabel2
            Switch MsgBox(3, "", "Calculate slope and bias?")
                Case 2
                    Return
                Case 6
                    $inG = InputBox("", "Enter [Gold Standard 1]|[Gold Standard 2]")
                    If $inG = "" Then Return
                    $inR = InputBox("", "Enter [Device 1]|[Device 2]")
                    If $inR = "" Then Return

                    ;- split entries -
                    $inG = StringSplit($inG, "|")
                    $inR = StringSplit($inR, "|")

                    ;- calc slopes -
                    $slope = Round(($inG[2] - $inG[1]) / ($inR[2] - $inR[1]), 3)

                    ;- calc offset -
                    $c = Round($inG[2] - ($inR[2] * $slope), 3)

                    ;- apply -
                    Switch $GUI_CtrlId
                        Case $hOffsetLabel1, $hSlopeLabel1
                            $aDeviceCorrection[1][2] = $c
                            $aDeviceCorrection[1][1] = $slope
                            GUICtrlSetData($hOffsetLabel1, $c)
                            GUICtrlSetData($hSlopeLabel1, $slope)
                            IniWrite($pINI, "calibration", "device1slope", $slope)
                            IniWrite($pINI, "calibration", "device1offset", $c)
                        Case $hOffsetLabel2, $hSlopeLabel2
                            $aDeviceCorrection[2][2] = $c
                            $aDeviceCorrection[2][1] = $slope
                            GUICtrlSetData($hOffsetLabel2, $c)
                            GUICtrlSetData($hSlopeLabel2, $slope)
                            IniWrite($pINI, "calibration", "device2slope", $slope)
                            IniWrite($pINI, "calibration", "device2offset", $c)
                    EndSwitch
                    Return
            EndSwitch
    EndSwitch

    ;----- Set data manually -----
    Switch $GUI_CtrlId
        Case $hOffsetLabel1
            $in = InputBox("", "Enter New Offset", $aDeviceCorrection[1][2])
            If $in = "" Then Return
            $aDeviceCorrection[1][2] = $in
            GUICtrlSetData($GUI_CtrlId, $aDeviceCorrection[1][2])
            IniWrite($pINI, "calibration", "device1offset", $aDeviceCorrection[1][2])
        Case $hSlopeLabel1
            $in = InputBox("", "Enter New Slope", $aDeviceCorrection[1][1])
            If $in = "" Then Return
            $aDeviceCorrection[1][1] = $in
            GUICtrlSetData($GUI_CtrlId, $aDeviceCorrection[1][1])
            IniWrite($pINI, "calibration", "device1slope", $aDeviceCorrection[1][1])
        Case $hOffsetLabel2
            $in = InputBox("", "Enter New Offset", $aDeviceCorrection[2][2])
            If $in = "" Then Return
            $aDeviceCorrection[2][2] = $in
            GUICtrlSetData($GUI_CtrlId, $aDeviceCorrection[2][2])
            IniWrite($pINI, "calibration", "device2offset", $aDeviceCorrection[2][2])
        Case $hSlopeLabel2
            $in = InputBox("", "Enter New Slope", $aDeviceCorrection[2][1])
            If $in = "" Then Return
            $aDeviceCorrection[2][1] = $in
            GUICtrlSetData($GUI_CtrlId, $aDeviceCorrection[2][1])
            IniWrite($pINI, "calibration", "device2slope", $aDeviceCorrection[2][1])
        Case $hBiasLabel1
            $in = InputBox("", "Enter New Bias", $aDeviceCorrection[1][3])
            If $in = "" Then Return
            $aDeviceCorrection[1][3] = $in
            GUICtrlSetData($GUI_CtrlId, $aDeviceCorrection[1][3])
            IniWrite($pINI, "calibration", "device1bias", $aDeviceCorrection[1][3])
        Case $hBiasLabel2
            $in = InputBox("", "Enter New Bias", $aDeviceCorrection[2][3])
            If $in = "" Then Return
            $aDeviceCorrection[2][3] = $in
            GUICtrlSetData($GUI_CtrlId, $aDeviceCorrection[2][3])
            IniWrite($pINI, "calibration", "device2bias", $aDeviceCorrection[2][3])
    EndSwitch

EndFunc   ;==>_Calibrate


Func _P($pc)
    ;*********************************************
    ; Progress bar
    ;*********************************************
    GUICtrlSetData($p, $pc)

EndFunc   ;==>_P


Func _Close()
    ;*********************************************
    ; Close
    ;*********************************************
    FileDelete("TempLog.txt")

    Exit

EndFunc   ;==>_Close

(the Table.au and GraphGDIPlus.au3 can be found in my sig)

Compiled : Thermometer.exe

post-29091-12651270883904_thumb.gif

If anyone's wondering what the temperatures are of; I brew my own beer, and this is me monitoring the mash! The black line is the mash, and the blue line the temperature of my oven.

Note:

I wouldn't usually post the compiled exe's on the forum, but having done a lot of searching for a way to use the dll I found that there are quite a few other people on the net who might benefit from the GetTemp.exe at least.

Cheers

AndyBiochem

Edited by andybiochem
- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

I'm looking to create a VB application that can connect to my TEMPer1 USB device and pull temperature readings from it. Can you provide commands on how to connect to the device and commands on how to get temperature readings from it? I looked at your post, thank you for that, but the "GetTemp.exe" program didn't do anything for me and the "Thermometer.exe" isn't really what I need either. Do you have any uncompiled information or documentation on how to go about calling the device?

My goal is to use the temperature readings to add to my WebCam/Weather page. Any and all help is appreciated. Thank you again.

Tim Williams

Link to comment
Share on other sites

I'm looking to create a VB application that can connect to my TEMPer1 USB device and pull temperature readings from it. Can you provide commands on how to connect to the device and commands on how to get temperature readings from it? I looked at your post, thank you for that, but the "GetTemp.exe" program didn't do anything for me and the "Thermometer.exe" isn't really what I need either. Do you have any uncompiled information or documentation on how to go about calling the device?

My goal is to use the temperature readings to add to my WebCam/Weather page. Any and all help is appreciated. Thank you again.

Tim Williams

I know nothing about VB syntax, but maybe if you're lucky someone on here may be able to give you an example of how to call functions from the dll by way of VB.

The functions I found in the HidFTDll.dll were:

EMyCloseDevice

EMyDetectDevice

EMyInitConfig

EMyReadEP

EMyReadHid

EMyReadTemp

EMySetCurrentDev

EMyWriteEP

EMyWriteHid

EMyWriteTempText

And the source to the UTAC program, showed what parameters the dll requires:

public static extern void EMyCloseDevice();

public static extern int EMyDetectDevice(long myhwnd);

public static extern bool EMyInitConfig(bool dOrc);

public static extern bool EMyReadEP(ref byte up1, ref byte up2, ref byte up3, ref byte up4, ref byte up5, ref byte up6);

public static extern bool EMyReadHid([MarshalAs(UnmanagedType.AnsiBStr)] ref string pcBuffer, byte btUrlIndex, int btUrlLen);

public static extern double EMyReadTemp(bool flag);

public static extern void EMySetCurrentDev(int nCurDev);

public static extern bool EMyWriteEP(ref byte fd1, ref byte fd2, ref byte fd3, ref byte fd4, ref byte fd5);

public static extern bool EMyWriteHid(ref char[] pcBuffer, byte btUrlIndex, int btUrlLen);

public static extern bool EMyWriteTempText(bool flag);

Note: the above code is Copyright © Bjoern Boettcher 2008 ( http://utac.n4rf.net (dead) -or- http://www.alsgh.com/utac/ )

and is covered by GNU GPL (copy available here http://www.gnu.org/licenses/ )

I found after a LOT of trial and error, that only EMyDetectDevice, EMySetCurrentDev, and EMyReadTemp were needed to get a reading from the TEMPer device.

How long have you had the device for? Searching the net reveals that older versions (pre mid-2009) use a usb-serial interface rather than HID, and maybe that's why GetTemp.exe doesn't work for you.

What are the contents of TempLog.txt after you have run the GetTemp.exe?

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

  • 2 weeks later...

Hi,

One can buy USB Thermometers that can measure the temperature of liquids etc using an external sensor on a lead.

(These go under names such as TEMPer HID, TEMPerNTC, TEMPer2 etc etc. The unit I have is the "TEMPer1", and as such I don't know if the following software will work with any other versions)

Unfortunately the supplied software is somewhat difficult to get working the way I want it, so I spent ages trying to find a way to control the device via the dll that comes with the original software. After some help from ProgAndy and Mat, I finally managed to make use of the dll.

After a lot of deliberation, I decided to split up my own program into two sections, the first being a simple data log script, and the second a graphing program to display the data. I'll deal with the two separately.

Temperature Data Logger

This simply reads the temperture from all devices attached to the system, and writes it to a TempLog.txt along with a date stamp and device number.

#NoTrayIcon
$hDll = DLLOpen("HidFTDll.dll")
$aiNDevices = DllCall($hDll,"int:cdecl","EMyDetectDevice", 'long', 0)
$sString = ""
For $i = 1 to $aiNDevices[0]
    DllCall($hDll,"none:cdecl","EMySetCurrentDev", 'int',$i - 1)
    $aiTemp = DllCall($hDll,"double:cdecl","EMyReadTemp", 'bool', True)
    $sString &= $i & "," & @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & "," & $aiTemp[0] & @CRLF
Next
$sString = StringStripWS($sString,2)
FileWriteLine("TempLog.txt",$sString)
DllClose($hDll)

Compiled : GetTemp.exe

Temperature Graph Program

;*********************************************
; INCLUDES
;*********************************************
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <Math.au3>
#include <Date.au3>
#include <Misc.au3>
#include <File.au3>
#include "GraphGDIPlus.au3"
#include "Table.au3"



;*********************************************
; OPTS
;*********************************************
Opt("GUIOnEventMode", 1)
Opt("MouseCoordMode", 2)
Opt("PixelCoordMode", 2)


;*********************************************
; VARIABLES
;*********************************************

Global $aTEMPERATURE[1][3][3];["",current item ...]["",unit1,unit2]["",date,temp]

Global $iGraphTempLow = 0
Global $iGraphTempHigh = 100
Global $iGraphTimeLow = 0
Global $iGraphTimeHigh = 90 ;minutes
Global $iRound = 0
Global $iLine1 = 60
Global $iLine2 = 65
Global $iLine3 = 70
Global $iLineCol = "0x55FF0000"

Global $pINI = "Data.ini"

Global $iDevices = IniRead($pINI, "devices", "number", 2)
Global $cDevice1Col = "000000"
Global $cDevice2Col = "0084ff"
Global $iSeeThrough = "99"

Global $bRunning = False
Global $bFirstRun = True
Global $bRESET = False
Global $sStartTime = _NowCalc()
Global $iIndexCounter = 1
Global $iCaptureTime = 1000

Global $bAutoResizeAxisX = True
Global $iEWMAWeight = 1
Global $iAverageN = 3

Global $aDeviceCorrection[3][4] ;["",unit1,unit2]["",slope,offset,bias]
$aDeviceCorrection[1][1] = IniRead($pINI, "calibration", "device1slope", 1)
$aDeviceCorrection[1][2] = IniRead($pINI, "calibration", "device1offset", 0)
$aDeviceCorrection[2][1] = IniRead($pINI, "calibration", "device2slope", 1)
$aDeviceCorrection[2][2] = IniRead($pINI, "calibration", "device2offset", 0)
$aDeviceCorrection[1][3] = IniRead($pINI, "calibration", "device1bias", 0) ;bias
$aDeviceCorrection[2][3] = IniRead($pINI, "calibration", "device2bias", 0) ;bias


;*********************************************
; GUI
;*********************************************
;----- GUI -----
$GUI = GUICreate("", 1000, 530)
GUISetOnEvent(-3, "_Close")
GUISetState()

;----- Calibration -----
$iYshift = -8
GUICtrlCreateGroup(" Calibration ", 792, 8, 194, 493)
GUICtrlSetFont(-1, -1, 800)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;- table setup -
GUICtrlCreateLabel("", 800, 26, 179, 72, 0x07) ;border
GUICtrlSetState(-1, 128)
$TABLE = _GUICtrlTable_Create(801, 35 + $iYshift, 34, 25, 3, 5, 0)
_GUICtrlTable_Set_ColumnWidth($TABLE, 1, 21)
_GUICtrlTable_Set_ColumnWidth($TABLE, 2, 54)
_GUICtrlTable_Set_RowHeight($TABLE, 1, 20)
_GUICtrlTable_Set_Text_Row($TABLE, 1, "|Temp|Offset|Slope|Bias")
_GUICtrlTable_Set_Text_Column($TABLE, 1, "|1|2", "|", 0)
_GUICtrlTable_Set_Justify_All($TABLE, 1, 1)
_GUICtrlTable_Set_CellColor_Row($TABLE, 1, 0xdddddd)
_GUICtrlTable_Set_TextFont_Cell($TABLE, 2, 2, 12, 800)
_GUICtrlTable_Set_TextFont_Cell($TABLE, 3, 2, 12, 800)
;- label handles -
Global $hOffsetLabel1 = _GUICtrlTable_CellGetID($TABLE, 2, 3)
Global $hSlopeLabel1 = _GUICtrlTable_CellGetID($TABLE, 2, 4)
Global $hBiasLabel1 = _GUICtrlTable_CellGetID($TABLE, 2, 5)
Global $hOffsetLabel2 = _GUICtrlTable_CellGetID($TABLE, 3, 3)
Global $hSlopeLabel2 = _GUICtrlTable_CellGetID($TABLE, 3, 4)
Global $hBiasLabel2 = _GUICtrlTable_CellGetID($TABLE, 3, 5)
;- label events -
GUICtrlSetOnEvent($hOffsetLabel1, "_Calibrate_Wrapper")
GUICtrlSetOnEvent($hSlopeLabel1, "_Calibrate_Wrapper")
GUICtrlSetOnEvent($hOffsetLabel2, "_Calibrate_Wrapper")
GUICtrlSetOnEvent($hSlopeLabel2, "_Calibrate_Wrapper")
GUICtrlSetOnEvent($hBiasLabel1, "_Calibrate_Wrapper")
GUICtrlSetOnEvent($hBiasLabel2, "_Calibrate_Wrapper")
;- label loading -
GUICtrlSetData($hOffsetLabel1, $aDeviceCorrection[1][2])
GUICtrlSetData($hSlopeLabel1, $aDeviceCorrection[1][1])
GUICtrlSetData($hOffsetLabel2, $aDeviceCorrection[2][2])
GUICtrlSetData($hSlopeLabel2, $aDeviceCorrection[2][1])
GUICtrlSetData($hBiasLabel1, $aDeviceCorrection[1][3])
GUICtrlSetData($hBiasLabel2, $aDeviceCorrection[2][3])
;- progress bar -
$p = GUICtrlCreateProgress(801, 98, 177, 5, 0x01)
;- input switch -
$iYshift += 20
$checkboxSwitchInputs = GUICtrlCreateCheckbox("Switch Device Inputs", 828, 100 + $iYshift, 130, 15, 0x0020)
If $iDevices = 1 Then GUICtrlSetState(-1, 128)

;----- Smoothing control -----
GUICtrlCreateGroup(" Smoothing ", 792, 133, 194, 324)
GUICtrlSetFont(-1, -1, 800)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$iYshift += 20
GUICtrlCreateLabel("N Average results", 813, 123 + $iYshift, 100, 15)
$inputAverageN = GUICtrlCreateInput($iAverageN, 900, 120 + $iYshift, 70, 20, 0x1)
GUICtrlCreateLabel("EWMA Weight", 813, 153 + $iYshift - 10, 80, 15)
$inputEWMAWeight = GUICtrlCreateInput($iEWMAWeight, 900, 150 + $iYshift - 10, 70, 20, 0x1)

;----- Axis setup -----
GUICtrlCreateGroup(" Axes ", 792, 197, 194, 260)
GUICtrlSetFont(-1, -1, 800)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;- x -
$xshift = 765
$yshift = 130 + 25
GUICtrlCreateLabel("x axis", 52 + $xshift, 60 + $yshift, 30, 17)
GUICtrlCreateLabel("_", 140 + $xshift, 55 + $yshift, 10, 19)
$inputXlow = GUICtrlCreateInput($iGraphTimeLow, 88 + $xshift, 56 + $yshift, 49, 21, 0x1)
$inputXhigh = GUICtrlCreateInput($iGraphTimeHigh, 149 + $xshift, 56 + $yshift, 49, 21, 0x1)
$checkboxXAuto = GUICtrlCreateCheckbox("", $xshift + 201, 56 + $yshift, 15, 21)
;- y -
$xshift = 765
$yshift = 130 + 25 + 20
GUICtrlCreateLabel("y axis", 52 + $xshift, 60 + $yshift, 30, 17)
GUICtrlCreateLabel("_", 140 + $xshift, 55 + $yshift, 10, 19)
$inputYlow = GUICtrlCreateInput($iGraphTempLow, 88 + $xshift, 56 + $yshift, 49, 21, 0x1)
$inputYhigh = GUICtrlCreateInput($iGraphTempHigh, 149 + $xshift, 56 + $yshift, 49, 21, 0x1)
$checkboxYAuto = GUICtrlCreateCheckbox("", $xshift + 201, 56 + $yshift, 15, 21)

;----- marker lines -----
GUICtrlCreateGroup(" Markers ", 792, 260, 194, 241)
GUICtrlSetFont(-1, -1, 800)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$yshift = 130 + 5 + 36
$InputLine1 = GUICtrlCreateInput($iLine1, 810 - 6, 109 + $yshift, 51, 21, 0x1)
GUICtrlSetColor(-1, 0xFF0000)
$InputLine2 = GUICtrlCreateInput($iLine2, 870 - 6, 109 + $yshift, 51, 21, 0x1)
$InputLine3 = GUICtrlCreateInput($iLine3, 930 - 6, 109 + $yshift, 51, 21, 0x1)
GUICtrlSetColor(-1, 0xFF0000)

;----- Buttons -----
$bButtonpause = GUICtrlCreateButton("Reset Data", 800, 435, 178, 40)
GUICtrlSetOnEvent(-1, "_Reset")
$bButtonpause = GUICtrlCreateButton("Start", 800, 480, 178, 40)
GUICtrlSetOnEvent(-1, "_StartStop")
GUICtrlSetFont(-1, 14, 800)

;----- GRAPH -----
$GRAPH = _GraphGDIPlus_Create($GUI, 40, 14, 727, 481)
_GraphGDIPlus_Set_RangeX($GRAPH, $iGraphTimeLow, $iGraphTimeHigh, 12, 1)
_GraphGDIPlus_Set_RangeY($GRAPH, $iGraphTempLow, $iGraphTempHigh, 10, 1, 0)
_GraphGDIPlus_Set_PenSize($GRAPH, 1)
_GraphGDIPlus_Set_GridY($GRAPH, 2)
;----- draw initial marker lines -----
_GraphGDIPlus_Set_PenSize($GRAPH, 1)
_GraphGDIPlus_Set_PenDash($GRAPH, 1)
_GraphGDIPlus_Set_PenColor($GRAPH, $iLineCol)
;- red dashed lines -
_GraphGDIPlus_Plot_Start($GRAPH, $iGraphTimeLow, $iLine1)
If $iLine1 <> "" Then _GraphGDIPlus_Plot_Line($GRAPH, $iGraphTimeHigh, $iLine1)
_GraphGDIPlus_Plot_Start($GRAPH, $iGraphTimeLow, $iLine3)
If $iLine3 <> "" Then _GraphGDIPlus_Plot_Line($GRAPH, $iGraphTimeHigh, $iLine3)
;- black full line -
_GraphGDIPlus_Set_PenDash($GRAPH)
_GraphGDIPlus_Set_PenColor($GRAPH, 0xFF000000)
_GraphGDIPlus_Plot_Start($GRAPH, $iGraphTimeLow, $iLine2)
If $iLine2 <> "" Then _GraphGDIPlus_Plot_Line($GRAPH, $iGraphTimeHigh, $iLine2)
_GraphGDIPlus_Refresh($GRAPH)









FileDelete("TempLog.txt")
;##################################################################################
; LOOP
;##################################################################################
$iTimer = TimerInit()
While 1
    Sleep(100)
    If TimerDiff($iTimer) > $iCaptureTime And $bRunning = True Then
        _P(0)
        _UpdateTemperature()
        _P(100)
        $iTimer = TimerInit()
    EndIf
WEnd
;##################################################################################
; END LOOP
;##################################################################################



Func _StartStop()
    ;*********************************************
    ; Start / Stop control
    ;*********************************************
    Switch $bRunning
        Case False
            GUICtrlSetData($bButtonpause, "Stop")
        Case True
            GUICtrlSetData($bButtonpause, "Start")
    EndSwitch

    $bRunning = Not $bRunning

    If $bFirstRun = True Then $sStartTime = _NowCalc()
    $bFirstRun = False

EndFunc   ;==>_StartStop


Func _Reset()
    ;*********************************************
    ; Reset pressed
    ;*********************************************
    Switch MsgBox(4, "", "Sure to reset data?")
        Case 7
            Return
    EndSwitch

    $bRESET = True

EndFunc   ;==>_Reset


Func _UpdateTemperature()
    ;*********************************************
    ; Update from TEMPer programs
    ;*********************************************
    ;----- return if not running -----
    If $bRunning = False Then Return

    ;----- Get new data (prevent change mid function) -----
    $iSwitchInputs = GUICtrlRead($checkboxSwitchInputs)
    $iAverageN = GUICtrlRead($inputAverageN)
    $iEWMAWeight = GUICtrlRead($inputEWMAWeight) ;global var
    $iLine1 = GUICtrlRead($InputLine1)
    $iLine2 = GUICtrlRead($InputLine2)
    $iLine3 = GUICtrlRead($InputLine3)

    ;----- update counter -----
    $iIndexCounter += 1

    ;----- Resize array -----
    ReDim $aTEMPERATURE[$iIndexCounter][3][3]

    ;----- Get temperatures -----
    FileDelete("TempLog.txt")
    For $i = 1 To $iAverageN
        _P(($i / $iAverageN) * 70)
        RunWait(@ComSpec & " /C " & "GetTemp.exe", "", @SW_HIDE) ;prevents hourglass
    Next

    ;----- load temps from file -----
    Dim $aTemp[1]
    _FileReadToArray("TempLog.txt", $aTemp)
    For $j = 1 To $aTemp[0] ;for each entry
        $aData = StringSplit($aTemp[$j], ",")
        $aTEMPERATURE[$iIndexCounter - 1][$aData[1]][1] = $aData[2] ;date
        $aTEMPERATURE[$iIndexCounter - 1][$aData[1]][2] += $aData[3] ;temp
    Next
    FileDelete("TempLog.txt")

    ;----- switch inputs -----
    If $iSwitchInputs = 1 Then
        ;- switch dates -
        $iTemp = $aTEMPERATURE[$iIndexCounter - 1][1][1]
        $aTEMPERATURE[$iIndexCounter - 1][1][1] = $aTEMPERATURE[$iIndexCounter - 1][2][1]
        $aTEMPERATURE[$iIndexCounter - 1][2][1] = $iTemp
        ;- switch Temps -
        $iTemp = $aTEMPERATURE[$iIndexCounter - 1][1][2]
        $aTEMPERATURE[$iIndexCounter - 1][1][2] = $aTEMPERATURE[$iIndexCounter - 1][2][2]
        $aTEMPERATURE[$iIndexCounter - 1][2][2] = $iTemp
    EndIf

    ;----- Pre Calc checks -----
    $iDevice1 = True
    If $aTEMPERATURE[$iIndexCounter - 1][1][1] = "" Then $iDevice1 = False
    $iDevice2 = True
    If $aTEMPERATURE[$iIndexCounter - 1][2][1] = "" Then $iDevice2 = False

    ;----- Apply averaging -----
    $aTEMPERATURE[$iIndexCounter - 1][1][2] /= $iAverageN
    $aTEMPERATURE[$iIndexCounter - 1][2][2] /= $iAverageN

    ;----- Apply calibration correction -----
    $aTEMPERATURE[$iIndexCounter - 1][1][2] = ($aDeviceCorrection[1][1] * $aTEMPERATURE[$iIndexCounter - 1][1][2]) + $aDeviceCorrection[1][2] + $aDeviceCorrection[1][3]
    $aTEMPERATURE[$iIndexCounter - 1][2][2] = ($aDeviceCorrection[2][1] * $aTEMPERATURE[$iIndexCounter - 1][2][2]) + $aDeviceCorrection[2][2] + $aDeviceCorrection[2][3]

    ;----- Apply EWMA -----
    ;- set zeroeth index to current result (just to please EWMA n=1)
    $aTEMPERATURE[0][1][2] = $aTEMPERATURE[$iIndexCounter - 1][1][2]
    $aTEMPERATURE[0][2][2] = $aTEMPERATURE[$iIndexCounter - 1][2][2]
    ;- apply ewma -
    $aTEMPERATURE[$iIndexCounter - 1][1][2] = StringFormat("%.2f", ($iEWMAWeight * $aTEMPERATURE[$iIndexCounter - 1][1][2]) + ((1 - $iEWMAWeight) * $aTEMPERATURE[$iIndexCounter - 2][1][2]))
    $aTEMPERATURE[$iIndexCounter - 1][2][2] = StringFormat("%.2f", ($iEWMAWeight * $aTEMPERATURE[$iIndexCounter - 1][2][2]) + ((1 - $iEWMAWeight) * $aTEMPERATURE[$iIndexCounter - 2][2][2]))

    ;----- check for correct data -----
    If $iDevice1 = False Then $aTEMPERATURE[$iIndexCounter - 1][1][2] = "--"
    If $iDevice2 = False Then $aTEMPERATURE[$iIndexCounter - 1][2][2] = "--"

    ;----- Update Table -----
    _GUICtrlTable_Set_Text_Cell($TABLE, 2, 2, $aTEMPERATURE[$iIndexCounter - 1][1][2])
    _GUICtrlTable_Set_Text_Cell($TABLE, 3, 2, $aTEMPERATURE[$iIndexCounter - 1][2][2])

    ;----- display raw data -----
    ;ConsoleWrite($aTEMPERATURE[$iIndexCounter - 1][1][1] & " " & $aTEMPERATURE[$iIndexCounter - 1][1][2] & " ||| " & _
    ;$aTEMPERATURE[$iIndexCounter - 1][2][1] & " " & $aTEMPERATURE[$iIndexCounter - 1][2][2] & @CRLF)

    ;----- resize graph -----
    ;- y -
    If $iGraphTempLow <> GUICtrlRead($inputYlow) Or $iGraphTempHigh <> GUICtrlRead($inputYhigh) Then
        $iRound = 0
        $iGraphTempLow = GUICtrlRead($inputYlow)
        $iGraphTempHigh = GUICtrlRead($inputYhigh)
        If $iGraphTempHigh - $iGraphTempLow < 10 Then $iRound = 2
        _GraphGDIPlus_Set_RangeY($GRAPH, $iGraphTempLow, $iGraphTempHigh, 10, 1, $iRound)
    EndIf
    ;- x -
    If $iGraphTimeLow <> GUICtrlRead($inputXlow) Or $iGraphTimeHigh <> GUICtrlRead($inputXhigh) Then
        $iRound = 0
        $iGraphTimeLow = GUICtrlRead($inputXlow)
        $iGraphTimeHigh = GUICtrlRead($inputXhigh)
        If $iGraphTimeHigh - $iGraphTimeLow < 10 Then $iRound = 2
        _GraphGDIPlus_Set_RangeX($GRAPH, $iGraphTimeLow, $iGraphTimeHigh, 10, 1, $iRound)
    EndIf

    ;- check auto -
    ;- set max/min -
    $currMAX = _Max(Number($aTEMPERATURE[$iIndexCounter - 1][1][2]), Number($aTEMPERATURE[$iIndexCounter - 1][2][2]))
    $currMIN = _Min(Number($aTEMPERATURE[$iIndexCounter - 1][1][2]), Number($aTEMPERATURE[$iIndexCounter - 1][2][2]))
    ;- y -
    Switch GUICtrlRead($checkboxYAuto)
        Case 1
            If $currMAX > $iGraphTempHigh Then
                $iGraphTempHigh = (0.1 * ($iGraphTempHigh - $iGraphTempLow)) + $currMAX
                $iGraphTempHigh = Round($iGraphTempHigh, 2)
                GUICtrlSetData($inputYhigh, $iGraphTempHigh)
            EndIf
            If $currMIN < $iGraphTempLow Then
                $iGraphTempLow = $currMIN - (0.1 * ($iGraphTempHigh - $iGraphTempLow))
                $iGraphTempLow = Round($iGraphTempLow, 2)
                GUICtrlSetData($inputYlow, $iGraphTempLow)
            EndIf
            _GraphGDIPlus_Set_RangeY($GRAPH, $iGraphTempLow, $iGraphTempHigh, 10, 1, $iRound)
    EndSwitch
    ;- x -
    Switch GUICtrlRead($checkboxXAuto)
        Case 1
            If _DateDiff("s", $sStartTime, $aTEMPERATURE[$iIndexCounter - 1][1][1]) / 60 > (0.9 * $iGraphTimeHigh) Then
                $iGraphTimeHigh = 1.2 * _DateDiff("s", $sStartTime, $aTEMPERATURE[$iIndexCounter - 1][1][1]) / 60
                _GraphGDIPlus_Set_RangeX($GRAPH, $iGraphTimeLow, $iGraphTimeHigh, 10, 1, $iRound)
                GUICtrlSetData($inputXhigh, $iGraphTimeHigh)
            EndIf
    EndSwitch

    ;----- Check RESET -----
    Switch $bRESET
        Case True
            $bFirstRun = True
            $sStartTime = _NowCalc()
            $iIndexCounter = 1
            Dim $aTEMPERATURE[$iIndexCounter][3][3]
            $bRESET = False
    EndSwitch

    ;----- Draw marker lines -----
    _GraphGDIPlus_Clear($GRAPH)
    _GraphGDIPlus_Set_GridY($GRAPH, 2)
    _GraphGDIPlus_Set_PenSize($GRAPH, 1)
    _GraphGDIPlus_Set_PenDash($GRAPH, 1)
    _GraphGDIPlus_Set_PenColor($GRAPH, $iLineCol)
    ;- red dashed lines -
    _GraphGDIPlus_Plot_Start($GRAPH, $iGraphTimeLow, $iLine1)
    If $iLine1 <> "" Then _GraphGDIPlus_Plot_Line($GRAPH, $iGraphTimeHigh, $iLine1)
    _GraphGDIPlus_Plot_Start($GRAPH, $iGraphTimeLow, $iLine3)
    If $iLine3 <> "" Then _GraphGDIPlus_Plot_Line($GRAPH, $iGraphTimeHigh, $iLine3)
    ;- black full line -
    _GraphGDIPlus_Set_PenDash($GRAPH)
    _GraphGDIPlus_Set_PenColor($GRAPH, 0xFF000000)
    _GraphGDIPlus_Plot_Start($GRAPH, $iGraphTimeLow, $iLine2)
    If $iLine2 <> "" Then _GraphGDIPlus_Plot_Line($GRAPH, $iGraphTimeHigh, $iLine2)

    ;----- Graph data -----
    ;- 1 -
    _GraphGDIPlus_Set_PenSize($GRAPH, 3)
    _GraphGDIPlus_Set_PenDash($GRAPH)
    _GraphGDIPlus_Set_PenColor($GRAPH, "0x" & $iSeeThrough & $cDevice1Col)
    $bFirst = True
    For $i = 1 To $iIndexCounter - 1
        ;- check present -
        If $aTEMPERATURE[$i][1][2] = "--" Then ContinueLoop
        ;- calc x/y -
        $iX = _DateDiff("s", $sStartTime, $aTEMPERATURE[$i][1][1]) / 60
        $iY = Number($aTEMPERATURE[$i][1][2])
        ;- check start line -
        If $bFirst = True Then _GraphGDIPlus_Plot_Start($GRAPH, $iX, $iY)
        $bFirst = False
        ;- plot line -
        _GraphGDIPlus_Plot_Line($GRAPH, $iX, $iY)
        ;- progress -
    Next

    ;- 2 -
    _GraphGDIPlus_Set_PenColor($GRAPH, "0x" & $iSeeThrough & $cDevice2Col)
    $bFirst = True
    For $i = 1 To $iIndexCounter - 1
        ;- check present -
        If $aTEMPERATURE[$i][2][2] = "--" Then ContinueLoop
        ;- calc x/y -
        $iX = _DateDiff("s", $sStartTime, $aTEMPERATURE[$i][2][1]) / 60
        $iY = Number($aTEMPERATURE[$i][2][2])
        ;- check start line -
        If $bFirst = True Then _GraphGDIPlus_Plot_Start($GRAPH, $iX, $iY)
        $bFirst = False
        ;- plot line -
        _GraphGDIPlus_Plot_Line($GRAPH, $iX, $iY)
        ;- progress -
    Next

    ;----- Refresh data -----
    _GraphGDIPlus_Refresh($GRAPH)

EndFunc   ;==>_UpdateTemperature


Func _Calibrate_Wrapper()
    ;*********************************************
    ; Wrapper for Calibrate func
    ;*********************************************
    GUICtrlSetData($bButtonpause, "Start")
    _Calibrate(@GUI_CtrlId)
    If $bRunning = True Then GUICtrlSetData($bButtonpause, "Stop")

EndFunc   ;==>_Calibrate_Wrapper


Func _Calibrate($GUI_CtrlId)
    ;*********************************************
    ; Set Calibration data (passed from wrapper)
    ;*********************************************
    ;----- Calculate Cal data? -----
    Switch $GUI_CtrlId
        Case $hOffsetLabel1, $hSlopeLabel1, $hOffsetLabel2, $hSlopeLabel2
            Switch MsgBox(3, "", "Calculate slope and bias?")
                Case 2
                    Return
                Case 6
                    $inG = InputBox("", "Enter [Gold Standard 1]|[Gold Standard 2]")
                    If $inG = "" Then Return
                    $inR = InputBox("", "Enter [Device 1]|[Device 2]")
                    If $inR = "" Then Return

                    ;- split entries -
                    $inG = StringSplit($inG, "|")
                    $inR = StringSplit($inR, "|")

                    ;- calc slopes -
                    $slope = Round(($inG[2] - $inG[1]) / ($inR[2] - $inR[1]), 3)

                    ;- calc offset -
                    $c = Round($inG[2] - ($inR[2] * $slope), 3)

                    ;- apply -
                    Switch $GUI_CtrlId
                        Case $hOffsetLabel1, $hSlopeLabel1
                            $aDeviceCorrection[1][2] = $c
                            $aDeviceCorrection[1][1] = $slope
                            GUICtrlSetData($hOffsetLabel1, $c)
                            GUICtrlSetData($hSlopeLabel1, $slope)
                            IniWrite($pINI, "calibration", "device1slope", $slope)
                            IniWrite($pINI, "calibration", "device1offset", $c)
                        Case $hOffsetLabel2, $hSlopeLabel2
                            $aDeviceCorrection[2][2] = $c
                            $aDeviceCorrection[2][1] = $slope
                            GUICtrlSetData($hOffsetLabel2, $c)
                            GUICtrlSetData($hSlopeLabel2, $slope)
                            IniWrite($pINI, "calibration", "device2slope", $slope)
                            IniWrite($pINI, "calibration", "device2offset", $c)
                    EndSwitch
                    Return
            EndSwitch
    EndSwitch

    ;----- Set data manually -----
    Switch $GUI_CtrlId
        Case $hOffsetLabel1
            $in = InputBox("", "Enter New Offset", $aDeviceCorrection[1][2])
            If $in = "" Then Return
            $aDeviceCorrection[1][2] = $in
            GUICtrlSetData($GUI_CtrlId, $aDeviceCorrection[1][2])
            IniWrite($pINI, "calibration", "device1offset", $aDeviceCorrection[1][2])
        Case $hSlopeLabel1
            $in = InputBox("", "Enter New Slope", $aDeviceCorrection[1][1])
            If $in = "" Then Return
            $aDeviceCorrection[1][1] = $in
            GUICtrlSetData($GUI_CtrlId, $aDeviceCorrection[1][1])
            IniWrite($pINI, "calibration", "device1slope", $aDeviceCorrection[1][1])
        Case $hOffsetLabel2
            $in = InputBox("", "Enter New Offset", $aDeviceCorrection[2][2])
            If $in = "" Then Return
            $aDeviceCorrection[2][2] = $in
            GUICtrlSetData($GUI_CtrlId, $aDeviceCorrection[2][2])
            IniWrite($pINI, "calibration", "device2offset", $aDeviceCorrection[2][2])
        Case $hSlopeLabel2
            $in = InputBox("", "Enter New Slope", $aDeviceCorrection[2][1])
            If $in = "" Then Return
            $aDeviceCorrection[2][1] = $in
            GUICtrlSetData($GUI_CtrlId, $aDeviceCorrection[2][1])
            IniWrite($pINI, "calibration", "device2slope", $aDeviceCorrection[2][1])
        Case $hBiasLabel1
            $in = InputBox("", "Enter New Bias", $aDeviceCorrection[1][3])
            If $in = "" Then Return
            $aDeviceCorrection[1][3] = $in
            GUICtrlSetData($GUI_CtrlId, $aDeviceCorrection[1][3])
            IniWrite($pINI, "calibration", "device1bias", $aDeviceCorrection[1][3])
        Case $hBiasLabel2
            $in = InputBox("", "Enter New Bias", $aDeviceCorrection[2][3])
            If $in = "" Then Return
            $aDeviceCorrection[2][3] = $in
            GUICtrlSetData($GUI_CtrlId, $aDeviceCorrection[2][3])
            IniWrite($pINI, "calibration", "device2bias", $aDeviceCorrection[2][3])
    EndSwitch

EndFunc   ;==>_Calibrate


Func _P($pc)
    ;*********************************************
    ; Progress bar
    ;*********************************************
    GUICtrlSetData($p, $pc)

EndFunc   ;==>_P


Func _Close()
    ;*********************************************
    ; Close
    ;*********************************************
    FileDelete("TempLog.txt")

    Exit

EndFunc   ;==>_Close

(the Table.au and GraphGDIPlus.au3 can be found in my sig)

Compiled : Thermometer.exe

post-29091-12651270883904_thumb.gif

If anyone's wondering what the temperatures are of; I brew my own beer, and this is me monitoring the mash! The black line is the mash, and the blue line the temperature of my oven.

Note:

I wouldn't usually post the compiled exe's on the forum, but having done a lot of searching for a way to use the dll I found that there are quite a few other people on the net who might benefit from the GetTemp.exe at least.

Cheers

AndyBiochem

Link to comment
Share on other sites

Hi,

I have problem with the include file:

#include "GraphGDIPlus.au3"

In your Signature I can not find the file GraphGDIPlus.au3

Should I use GraphGDIPlus UDF.au3 instead and replace #include "GraphGDIPlus.au3" by #include "GraphGDIPlus UDF.au3"?

Thanks

You could also rename the file :mellow:

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Hi,

I have problem with the include file:

#include "GraphGDIPlus.au3"

In your Signature I can not find the file GraphGDIPlus.au3

Should I use GraphGDIPlus UDF.au3 instead and replace #include "GraphGDIPlus.au3" by #include "GraphGDIPlus UDF.au3"?

Thanks

Sorry, that's my fault; I'm a bit inconsistent with my file names.

It's probably best to do what progandy said, leave the code as it is and rename the GraphGDIPlus UDF.au3 file to GraphGDIPlus.au3

I included the compiled exe files in the first post, so you don't have to bother with the code or includes. Just download the two exes into the same folder and run the thermometer.exe

If you don't like the graph program, or want to do your own thing (e.g. in excel) then just run the GetTemp.exe and look in the TempLog.txt file that is created for the temperature readings.

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

  • 2 weeks later...

I just bought a couple of "HID TEMPer" devices from eBay (The device looks like the one on your link) and they work ok with the supplied software. But I don't have a HidFTDll.dll anywhere. Any idea where I can get this dll or what I should substitute for it?

Link to comment
Share on other sites

  • 4 weeks later...

Hi,

I have very little knowledge of programming so apologies for asking a stupid question.. what language is that code in? I would like to edit it but don't know where to start.

The GenTemp.exe file works great in reading from the 2 TEMPer devices, however it only seems to read in .5 degree increments, even though the devices are far more accurate than that?

Is this someting which can be fixed easily?

Thanks in advance.

Ic.

Link to comment
Share on other sites

The GenTemp.exe file works great in reading from the 2 TEMPer devices, however it only seems to read in .5 degree increments, even though the devices are far more accurate than that?

This language is AutoIt.

Hmmm, well spotted with the reduced precision! I'm looking into it, at first glance it looks like I might need to 'prep' the device somehow to return better precisions.

Thanks!

[EDIT]

UPDATE:

Found the problem with GetTemp.exe! Looks like the devices should be 'initialised' before use. I've included this change in the link in the original post.

The included line is:

DllCall($hDll,"bool:cdecl","EMyInitConfig", 'bool', True)

Because of the way I've designed the program, the 'initialisation' is called every time the GetTemp.exe is ran. This is probably wasteful in terms of speed, but shouldn't make a difference to common use...it's perhaps 0.2s slower?

Thanks for the feedback.

p.s. I think it's highly unlikely that the devices can read to 0.0001 deg c as claimed on ebay etc, and as returned by the dll. Also, the dll seems to self-truncate the readings sometimes, i.e. 20.1200 will return as 20.12 etc.

Edited by andybiochem
- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

Hi

Thanks for sorting out the precision issue.

So this AutoIt thing is pretty amazing, thought I'd share what I managed to cobble together based on your code:

- Little GUI to display the Temps from max of 2 x TEMPer1 devices.

- Refresh option & Auto Refresh based on a selector (seconds)

- Auto Refresh will also trigger the writing of a file (changed format to better import into Excel)

#include <GUIConstantsEx.au3>
$sString = ""
$tempDisp = ""
$temp1 = ""
$temp2 = ""
$date = ""
Local $Refresh_Btn, $Auto_Btn, $msg, $Stop_Btn, $Stop, $input, $updown

GUICreate("TEMPer Readings", 200, 130)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUICtrlCreateLabel("Current Temps are:", 30, 4)
$Refresh_Btn = GUICtrlCreateButton("Refresh", 10, 58, 55, 20)
$Auto_Btn = GUICtrlCreateButton("Auto Refresh", 70, 58, 70, 20)
$input = GUICtrlCreateInput("30", 145, 58, 45, 20)
$updown = GUICtrlCreateUpdown($input)
GUISetState(@SW_SHOW)

Load()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Refresh_Btn
            Load()
        Case $Auto_Btn
            GOAuto()
    EndSwitch
WEnd

Func GOAuto()
    $Stop_Btn = GUICtrlCreateButton("Stop", 30, 86, 36, 36)
    $x = 0
    While 1
        $x = $x + 1
            GUICtrlCreateGroup("Loops", 80, 82, 100, 39)
                GUICtrlCreateLabel($x, 88, 98)
            GUICtrlCreateGroup("", -99, -99, 1, 1)
        WriteFile()
        $TD = TimerInit()
        $timer = (GUICtrlRead($input) - 1.5) * 1000
        While TimerDiff($TD) <= $timer
            $nMsg = GUIGetMsg()
            If $nMsg = $Stop_Btn Then
                If MsgBox(36, "Cancel?", "Are you sure you want to stop?") = 6 Then
                    Return
                EndIf
            ElseIf $nMsg = $GUI_EVENT_CLOSE Then
                If MsgBox(36, "Exit?", "Are you sure you want to Exit?") = 6 Then
                    Exit
                EndIf
            EndIf
        WEnd
    WEnd
EndFunc

Func Load()
$tempDisp = "loading....                 " & @CRLF & "loading....                 "
disp()
$hDll = DLLOpen("HidFTDll.dll")
$aiNDevices = DllCall($hDll,"int:cdecl","EMyDetectDevice", 'long', 0)
For $i = 1 to $aiNDevices[0]
    DllCall($hDll,"none:cdecl","EMySetCurrentDev", 'int',$i - 1)
    $aiTemp = DllCall($hDll,"double:cdecl","EMyReadTemp", 'bool', True)
    if $i = 1 Then
        $tempDisp = "Device " & $i & " = " & $aiTemp[0] & @CRLF
    Else
        $tempDisp &= "Device " & $i & " = " & $aiTemp[0]
    EndIf
Next
DllClose($hDll)
disp()
EndFunc

Func disp()
    GUICtrlCreateLabel($tempDisp, 50, 22)
EndFunc

Func WriteFile()
$tempDisp = "loading....                 " & @CRLF & "loading....                 "
$temp1 = ""
$temp2 = ""
disp()
$hDll = DLLOpen("HidFTDll.dll")
$aiNDevices = DllCall($hDll,"int:cdecl","EMyDetectDevice", 'long', 0)
$date = @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC
For $i = 1 to $aiNDevices[0]
    DllCall($hDll,"none:cdecl","EMySetCurrentDev", 'int',$i - 1)
    $aiTemp = DllCall($hDll,"double:cdecl","EMyReadTemp", 'bool', True)
    if $i = 1 Then
        $tempDisp = "Device " & $i & " = " & $aiTemp[0] & @CRLF
        $temp1 &= $aiTemp[0]
        Else
        $tempDisp &= "Device " & $i & " = " & $aiTemp[0]
        $temp2 &= $aiTemp[0]
    EndIf
Next
DllClose($hDll)

If FileExists("TempLog.txt") Then
        FileWriteLine("TempLog.txt",$date & ", " & $temp1 & ", " & $temp2 & @CRLF)
    Else
        FileWriteLine("TempLog.txt","Date, Device 1 Temp, Device 2 Temp" & @CRLF)
        FileWriteLine("TempLog.txt",$date & ", " & $temp1 & ", " & $temp2 & @CRLF)
EndIf

disp()
EndFunc

Very new to this so there are probably some things which I'm doing the hard way but... it works :(

Cheers,

Ic.

Link to comment
Share on other sites

I bought my TemPER1 on Ebay last month. It has a silver USB plug that looks like a memory stick with the words "TEMPer1 -40C ~ +120C" on it. A three foot long cord goes to the probe. It looks like the one that used to be on the link in your first post (which is broken now). It came with software which installs as HID TEMPer V10.5 and doesn't have the dll in it. I downloaded the "supplied software" link above and downloaded/installed HidTEMPer V10.3 folder. I also downloaded your Thermometer.exe and GetTemp.exe into the same folder as the dll. Running GetTemp, I get an array error in line 5. This also is true when I run your script:

$ghHidFTDll = DLLOpen("HidFTDll.dll")
$a = DllCall($ghHidFTDll,"int:cdecl","EMyDetectDevice", 'long', 0)
ConsoleWrite(@error & " " & $a[0] & @CRLF)
;----- read device 1 ------
$a = DllCall($ghHidFTDll,"none:cdecl","EMySetCurrentDev", 'int', 0)
ConsoleWrite(@error & " " & $a[0] & @CRLF)
$a = DllCall($ghHidFTDll,"double:cdecl","EMyReadTemp", 'bool', True)
ConsoleWrite(@error & " " & $a[0] & @CRLF)

This crashes on the EMyReadTemp because $a is not an array.

Interestingly, if I change the call to :

$a = DllCall($ghHidFTDll,"int:cdecl","EMyReadTemp", 'long', 0)

The script gives me:

0 1

0

0 9237032

Although this is better, it may be just garbage since I don't understand the DllCall. All the programs in 10.3 and 10.5 versions I downloaded run ok. Any ideas?

Link to comment
Share on other sites

Odd! That's exactly the same unit as mine.

All the programs in 10.3 and 10.5 versions I downloaded run ok. Any ideas?

I can't find version 10.5 on the 'net anywhere... this is their current software list.

It looks like perhaps they've changed their interface yet again?

Try running this in the folder with the HidFTDll.dll from v10.3 in:

$ghHidFTDll = DLLOpen("HidFTDll.dll")
$a = DllCall($ghHidFTDll,"int:cdecl","EMyDetectDevice", 'long', 0)
ConsoleWrite("Detect Devices: Fail=" & @error & ", Devices Found=" & $a[0] & @CRLF)
$a = DllCall($ghHidFTDll,"none:cdecl","EMySetCurrentDev", 'int', 0)
ConsoleWrite("Set Current Device 0: Fail=" & @error & @CRLF)
$a = DllCall($ghHidFTDll,"bool:cdecl","EMyInitConfig", 'bool', True)
ConsoleWrite("Initialise Device 0: Fail=" & @error & @CRLF)
$a = DllCall($ghHidFTDll,"double:cdecl","EMyReadTemp", 'bool', True)
$error = @error
Switch IsArray($a)
    Case 1
        ConsoleWrite("Temperature BOOL Read: Fail=" & $error & @CRLF)
        For $i = 0 to UBound($a) - 1
            ConsoleWrite("[" & $i & "] = " & $a[$i] & @CRLF)
        Next
    Case 0
        ConsoleWrite("Temperature BOOL Read: Fail=" & $error & ", DLLReturn=" & $a & @CRLF)
EndSwitch

$a = DllCall($ghHidFTDll,"int:cdecl","EMyReadTemp", 'long', 0)
$error = @error
Switch IsArray($a)
    Case 1
        ConsoleWrite("Temperature LONG Read: Fail=" & $error & @CRLF)
        For $i = 0 to UBound($a) - 1
            ConsoleWrite("[" & $i & "] = " & $a[$i] & @CRLF)
        Next
    Case 0
        ConsoleWrite("Temperature LONG Read: Fail=" & $error & ", DLLReturn=" & $a & @CRLF)
EndSwitch

Post the results from the console here.

This is what I get:

Detect Devices: Fail=0, Devices Found=1

Set Current Device 0: Fail=0

Initialise Device 0: Fail=0

Temperature BOOL Read: Fail=0

[0] = 24.8125

[1] = 1

Temperature LONG Read: Fail=0

[0] = 9237080

[1] = 0

I don't know what the 9237080 refers to. Version number perhaps? It doesn't change with temperature, so I don't think it's related.

[EDIT]

Just out of interest, what version of Windows are you running?

Edited by andybiochem
- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

Here's what I get:

Detect Devices: Fail=0, Devices Found=1

Set Current Device 0: Fail=0

Initialise Device 0: Fail=2

Temperature BOOL Read: Fail=1, DLLReturn=0

Temperature LONG Read: Fail=0

[0] = 9237032

[1] = 0

I'm running XP pro sp3.

Here's the 10.5 version.

I set up another computer and tried the temper on it with the script, Same results!

Thinking I had a bad sensor, I tried another one and STILL got the same results!

Edited by wysocki
Link to comment
Share on other sites

I've looked at the v10.5 software (talk about a backward step!), all the DLL functions seem to have been 'internalised' so I can't see how the software is interacting with the device. ProcMon doesn't reveal much either.

The last suggestion I have is to try calling the DLL differently from autoit, try this:

;----- Following code works -----
$ghHidFTDll = DLLOpen("HidFTDll.dll")
$a = DllCall($ghHidFTDll,"int:cdecl","EMyDetectDevice", 'long', 0)
ConsoleWrite("Detect Devices: Fail=" & @error & ", Devices Found=" & $a[0] & @CRLF)
$a = DllCall($ghHidFTDll,"none:cdecl","EMySetCurrentDev", 'int', 0)
ConsoleWrite("Set Current Device 0: Fail=" & @error & @CRLF)

;----- Following code does not work? -----
$a = DllCall($ghHidFTDll,"bool:cdecl","EMyInitConfig")
ConsoleWrite("Initialise Device (CDECL, No param): Fail=" & @error & @CRLF)

$a = DllCall($ghHidFTDll,"bool","EMyInitConfig")
ConsoleWrite("Initialise Device (STDCALL, No param): Fail=" & @error & @CRLF)

$a = DllCall($ghHidFTDll,"double:cdecl","EMyReadTemp")
ConsoleWrite("Read Temperature (CDECL, No param): Fail=" & @error & @CRLF)

$a = DllCall($ghHidFTDll,"double","EMyReadTemp")
ConsoleWrite("Read Temperature (STDCALL, No param): Fail=" & @error & @CRLF)

$a = DllCall($ghHidFTDll,"float","EMyReadTemp")
ConsoleWrite("Read Temperature (STDCALL, No param, float): Fail=" & @error & @CRLF)

What does the console say to that?

If the device works with v10.3 software (that uses the DLL), then I'm not sure why calling it won't work when called directly from the DLL.

Have you ever used ProcMon (it logs software interactions etc)? When I use v10.3, procmon lists hundreds of calls to the DLL each time the temperature is taken. It would be interesting to see if yours does too.

Also, check to make sure that the device IS recognised as HID in device manager (control panel > system > hardware).

I'm sorry, I'm really at a loss as to why yours doesn't work, other than it being a newer device that is designed differently.

There are other home-brewed software floating around on the net (e.g. UTAC ) that gives you an alternative to the supplied software. Perhaps they're worth a try?

Can anyone else think of anything?

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

Andy: Thanks so much for sticking in there and helping with this!

With both devices plugged in, I get:

Detect Devices: Fail=0, Devices Found=2

Set Current Device 0: Fail=0

Initialise Device (CDECL, No param): Fail=2

Initialise Device (STDCALL, No param): Fail=2

Read Temperature (CDECL, No param): Fail=0

Read Temperature (STDCALL, No param): Fail=0

Read Temperature (STDCALL, No param, float): Fail=0

I tried the UTAC program and it didn't detect any devices. I found the updated 0.1.2o version and it finds both devices and appears to be reading them. Although this version looks like it supports 2 units, there may be some interaction problem though because if one sensor is heated, both devices show approximately (but not exactly) the same temperatures. I wonder how UTAC is able to read the temp but not the AI script?

Edited by wysocki
Link to comment
Share on other sites

Detect Devices: Fail=0, Devices Found=2

Set Current Device 0: Fail=0

Initialise Device (CDECL, No param): Fail=2

Initialise Device (STDCALL, No param): Fail=2

Read Temperature (CDECL, No param): Fail=0

Read Temperature (STDCALL, No param): Fail=0

Read Temperature (STDCALL, No param, float): Fail=0

Hmmm, so the Read Temperature doesn't fail when parameters aren't sent to the DLL.

The Initialise Device was used to improve precision, so it may not matter that that fails just yet, we can deal with that later!

Try this with just 1 device plugged in:

$ghHidFTDll = DLLOpen("HidFTDll.dll")
$a = DllCall($ghHidFTDll,"int:cdecl","EMyDetectDevice", 'long', 0)
ConsoleWrite(@error & " " & $a[0] & @CRLF)
;----- read device 1 ------
$a = DllCall($ghHidFTDll,"none:cdecl","EMySetCurrentDev", 'int', 0)
ConsoleWrite(@error & " " & $a[0] & @CRLF)
$a = DllCall($ghHidFTDll,"double","EMyReadTemp")
ConsoleWrite(@error & " " & $a[0] & @CRLF)

This is just the same script as before, but using EMyReadTemp without passing parameters to the DLL. From your last post, this doesn't say it fails.

Fingers crossed!

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

Yay! That did it!

0 1

0

0 23.0625

I also added another device and was able to get them both using this change.

Guess is doesn't need the initialize device?

Thanks a million for your perseverance!

Edited by wysocki
Link to comment
Share on other sites

Yay! That did it!

0 1

0

0 23.0625

I also added another device and was able to get them both using this change.

Guess is doesn't need the initialize device?

Thanks a million for your perseverance!

Ha! Excellent!

Yeah, I guess yours doesn't need the initialize device...although, just make sure that it still gives results to 4 decimal places after turning the PC off and on again. I found that the "initialize device" only needed to be called once to set the correct precision, and then again after every re-boot. This may have been called on your PC by a different program (manufacturers software, UTAC, etc) whilst you were testing.

I'll update my GetTemp.exe later to include what we've found.

Thanks!

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

  • 3 months later...

I bought TemperNTC and faced with trouble getting second temeprature from the device.

I have 10.5 dll with

EMyCloseDevice

EMyDetectDevice

EMyGetNTCVolt

EMyGetUSBVolt

EMyInitConfig

EMyReadEP

EMyReadHUM

EMyReadHid

EMyReadTemp

EMySetCurrentDev

EMyWriteEP

EMyWriteHid

EMyWriteTempText

SetNTCGain

attached software on cdrom works fine and shows 2 temperatures.

$ghHidFTDll = DLLOpen("HidFTDll.dll")
$a = DllCall($ghHidFTDll,"int:cdecl","EMyDetectDevice", 'long', 0)
ConsoleWrite(@error & " " & $a[0] & @CRLF)
;----- read device 1 ------
$a = DllCall($ghHidFTDll,"none:cdecl","EMySetCurrentDev", 'int', 0)
ConsoleWrite(@error & " " & $a[0] & @CRLF)
$a = DllCall($ghHidFTDll,"double","EMyReadTemp")
ConsoleWrite(@error & " " & $a[0] & @CRLF)
$a = DllCall($ghHidFTDll,"double","EMyReadHid")
ConsoleWrite(@error & " " & $a[0] & @CRLF)

gives:

0 1

0

0 29.375

0 -1.#IND

any ideas I can fount the second temperature?

I tried to use EMyReadEP, but Autoit crashed...

Edited by user5547841
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...