Jump to content

[SOLVED] Calling Functions from a 3rd party DLL


Recommended Posts

Hi,

I posted a thread while ago here where I was trying to call functions from a .net dll :huggles::D

Since then I have found what looks to be a working dll, which of course I still need help with because I'm useless.

I decided to create a new thread, rather than continue the old one, to prevent confusion with the other dll I was using...hope that's ok.

A quick summary of what I'm trying to do...

I bought two of these USB HID thermometers to aid in my homebrewing conquests. However, the software the manufacturer supplies is terrible. I'm trying to figure out how to communicate directly with the HID device to get it to return a temperature value.

Having found a list of the functions contained in the dll here, I'm trying to call them from AI to see what happens. So far I have got:

#cs
// Imported functions for the HID TEMPer device

public static extern int EMyDetectDevice(long myhwnd);
public static extern void EMySetCurrentDev(int nCurDev)
public static extern bool EMyInitConfig(bool dOrc);
public static extern double EMyReadTemp(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/ )

#ce



$a = DllCall("HidFTDll.dll","int","EMyDetectDevice")
ConsoleWrite(@error & " " & $a[0] & @CRLF)

$a = DllCall("HidFTDll.dll","ptr","EMySetCurrentDev")
ConsoleWrite(@error & " " & $a[0] & @CRLF)

$a = DllCall("HidFTDll.dll","boolean","EMyInitConfig")
ConsoleWrite(@error & " " & $a[0] & @CRLF)

$a = DllCall("HidFTDll.dll","double","EMyReadTemp")
ConsoleWrite(@error & " " & $a[0] & @CRLF)

Which prints in the console:

0 1

0 0x004A5920

0 0

0 888

Calling the functions in any other way causes AI to crash (i.e. I can't send the boolean parameter for EMyReadTemp etc)

The first func "EMyDetectDevice" simply returns the number of devices attached (plugging in another, it changes to 2)

The second func looks like it's returning a handle perhaps?

Heaven knows what 888 is? DegC perhaps? It is quite warm in here!

Anyway, I guess my question is, is there anything obviously wrong with my dll calls? Is there anything in the returns that looks like it may be useable data?

I know this is a long shot, and I almost ready to give up on this, but I thought the collective genius here may be able to shed a little more light.

Also, I'd post the dll, but it's probably no use if you don't have the temperature device.

Thanks in advance!

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 think, you should use cdecl-calling convention:

#cs
// Imported functions for the HID TEMPer device

public static extern int EMyDetectDevice(long myhwnd);
public static extern void EMySetCurrentDev(int nCurDev)
public static extern bool EMyInitConfig(bool dOrc);
public static extern double EMyReadTemp(bool flag);

#ce

$ghHidFTDll = DLLOpen("HidFTDll.dll")

$a = DllCall($ghHidFTDll,"int:cdecl","EMyDetectDevice", 'long', $myhwnd)
ConsoleWrite(@error & " " & $a[0] & @CRLF)

$a = DllCall($ghHidFTDll,"none:cdecl","EMySetCurrentDev", 'int', $nCurDev)
ConsoleWrite(@error & " " & $a[0] & @CRLF)

$a = DllCall($ghHidFTDll,"bool:cdecl","EMyInitConfig", 'bool', $dOrc)
ConsoleWrite(@error & " " & $a[0] & @CRLF)

$a = DllCall($ghHidFTDll,"double:cdecl","EMyReadTemp", 'bool', $flag)
ConsoleWrite(@error & " " & $a[0] & @CRLF)

*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

I was right first time! Thats a first :D

Why don't you make your own temperature device? All you need is a thermistor and a little electrical thingy to read the resistance (here?), you can then send the data to the computer using the com ports. It would be quite a fun project (if low level programming is your thing), and you can then use Martins com UDF to read the data. Simple eh?

Link to comment
Share on other sites

I think, you should use cdecl-calling convention:

...code etc...

OH MY F****** LORD! :D The unit just flashed and returned:

0 1

0

0 1

0 -100

:huggles:

It's still nonsense (although it has gotten suddenly colder), but IT FLASHED!!!!!

WOW thanks!!!

I'll post back after a bit of experimenting.

Oh, just out of interest, what does cdecl do? [EDIT] nm, I've just read through Mat's link. Cheers!

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

cdecl is a calling convention, just like stdcall wich is used by default.

*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

Ok, the new dll convention works great!!

This:

$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)

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

Gives this:

0 2

0

0 30.9375

0

0 20.5

One unit is in my hand, and the other in a glass of tap water. Temperatures look ok!

I'll add this to the program I wrote, and I'll post it in examples later.

Seriously, thanks a lot for this...it's been driving me mad! :D

- 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

  • 1 month later...

Also, I'd post the dll, but it's probably no use if you don't have the temperature device.

I may need a copy of your dll, I got one off the links you've posted above but the script has problems. I only have one device plugged in so I commented out the read device 2, but here's what I got when I ran it (BTW: @error is "1" and $a is just "0"). Any ideas?

0 1

0

C:\Apps\Misc\GetTemp.au3 (10) : ==> Subscript used with non-Array variable.:

ConsoleWrite(@error & " " & $a[0] & @CRLF)

ConsoleWrite(@error & " " & $a^ ERROR

Edited by wysocki
Link to comment
Share on other sites

0 1

0

C:\Apps\Misc\GetTemp.au3 (10) : ==> Subscript used with non-Array variable.:

ConsoleWrite(@error & " " & $a[0] & @CRLF)

ConsoleWrite(@error & " " & $a^ ERROR

How old is your Temper device? It seems that units bought pre mid-2009-ish use a serial-to-usb interface, whereas newer units use a HID interface. This script is designed to use the HID interface DLL.

It's a bit odd that the DLL returns the correct number of devices i.e. "0 1", but then fails on the EMyReadTemp.

Try downloading the software in the link here.

...and use the DLL in there. That's the version I use.

If you have further problems, it's probably better that you post in that thread too - I rarely check the 'problems' forum for replies to my previous posts (once they're solved at least).

Let me know how you get on!

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

  • 10 months later...

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...