Sign in to follow this  
Followers 0
hyperjase

DllCall - Unsure of how to access DLL file

26 posts in this topic

Hi,

This is my first time attempting to access a DLL file via AutoIT, but I just keep crashing the script editor (presumably because I'm doing something wrong...)

My code is-

$fOpen = DllOpen ("jeti_core.dll")
If $fOpen = -1 Then
    MsgBox(0,"Warning!","DLL File Not Found")
Else
    DllCall($fOpen,"DWORD",1,"DWORD",0)
    $sTest = DllCall($fOpen,"DWORD",13,"hwnd",1)
    MsgBox(0,"",$sTest)

EndIf
DllClose("jeti_core.dll") 

Now I'm confident it doesn't work as I have no idea that it is correct, I've had a good search and checked the manual, but from what I see, I'm just not sure how to achieve this.

What I'm trying to achieve above it to turn a laser light on in a light calibration unit, which can be accessed through Ordinal #13 (#1 should open the first device).  I've attached the part of the manual that relates to this part.

Can anyone give me a gentle push in the right direction?

Many thanks

 

post-85850-0-42741400-1420557668_thumb.j

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

DllCall($fOpen,"DWORD", "jeti_setlaserstat", "DWORD", 1, "BOOL", 0)

Probably a bit more like that from the image you post.

Also return from dllcall is an array, please read the helpfile again.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Thank you, I shall alter the code and try again - I was so wrapped up in trying to get it working, I didn't take into account that it was an array.

Many thanks for the swift response.

Share this post


Link to post
Share on other sites

Final question;

Screenshot attached shows open device, which has dwDevice called by reference, I have to connect first then turn the laser on or off - how do I deal with the reference?  Doing some testing I've found that I'm usually not connecting for one and keep ending up with an invalid handle error (using hex to get the code)

post-85850-0-85654300-1420562076_thumb.j

Share this post


Link to post
Share on other sites

$Ret=DllCall($fOpen,"DWORD", "JETI_OpenDevice", "dword", 0, "dword*", 0)
$hDevice=$Ret[2]

Saludos

Share this post


Link to post
Share on other sites

$DLL = DllOpen("jeti_core.dll")
$conn = DllCall($DLL,"DWORD", "JETI_OpenDevice", "DWORD", 0, "DWORD", 0)
$Test = DllCall($DLL,"DWORD", "JETI_SetLaserStat", "DWORD", 0, "BOOL", 1)
MsgBox(0,"",Hex($Test[0]))

Running that results in 0000000000000015 which checking in the SDK manual gives me an error of "invalid device handle".

Sorry if I'm being thick, uncharted territory for me!

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Thanks - I understand how the asterisk now integrates with this (also found a handy PDF quick guide and followed that example).

The code I now have is

$DLL = DllOpen("jeti_core.dll")

Local $Ret
Local $hDevice
Local $Close
Local $cDevice

; Open Device #0
$Ret = DllCall($DLL,"DWORD", "JETI_OpenDevice", "DWORD", "0", "DWORD*", $hDevice)
$hDevice = $Ret[1]

; Set laser BOOL = 1
DllCall($DLL,"DWORD", "JETI_SetLaserStat", "DWORD", $hDevice, "BOOL", 1)

; Close Device
$Close = DllCall($DLL,"DWORD", "JETI_CloseDevice", "DWORD", $hDevice)
$cDevice = $Close[1]

; $hDevice gives us 0000000000000000 code which according to Jeti manual = JETI_SUCCESS
MsgBox(0,"",Hex($hDevice))

But still doesn't turn the laser on -- have I got this right?

Was making good progress using the MsgBox to show what error codes I ended up with - what I have here seems to return sucess from open and close.

Edited by hyperjase

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

try to pass the index without put "0" just use 0. (lol I don't remember how to write "" in english)

Saludos

Edited by Danyfirex

Share this post


Link to post
Share on other sites

Sadly makes no difference; still getting a 0x00 code meaning connected OK, but I'm not totally convinced it's working.

Share this post


Link to post
Share on other sites

I've gone a little more specific with targeting the unit, namely selecting the COM port (3) and baud rate (9600).

Here is the current code:

$DLL = DllOpen("jeti_core.dll")

Local $Ret
Local $hDevice
Local $Close
Local $cDevice

; Open Device #0
$Ret = DllCall($DLL,"DWORD", "JETI_OpenCOMDevice", "DWORD", "3", "DWORD", "9600", "DWORD*", $hDevice)
$hDevice = $Ret[3]

; Set laser BOOL = 1
DllCall($DLL,"DWORD", "JETI_SetLaserStat", "DWORD", $hDevice, "BOOL", 1)

; Close Device
$Close = DllCall($DLL,"DWORD", "JETI_CloseDevice", "DWORD", $hDevice)
$cDevice = $Close[1]

; $hDevice gives us 0000000000000000 code which according to Jeti manual = JETI_SUCCESS
MsgBox(0,"",Hex($hDevice))

The one thing I'm curious about is $hDevice become the handle?  As I find I keep getting 0000000000000015 codes which are "JETI_INVALID_HANDLE"

Share this post


Link to post
Share on other sites

mate try with JETI_GetNumDevices.

Saludos

Share this post


Link to post
Share on other sites

I've been testing with that possibility but can't get back useful info - I always seem to find zero devices.

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Try...

$DLL = DllOpen("jeti_core.dll")

$STRUCT = DllStructCreate("DWORD")

$CALL = DllCall($DLL, "DWORD", "JETI_GetNumDevices", "DWORD*", DllStructGetPtr($STRUCT))

If Not $CALL[0] Then

    MsgBox(0, "Num:", DllStructGetData($STRUCT, 1))
    DllClose($DLL)
    Exit
        
EndIf

DllClose($DLL)
MsgBox(0, "Num:", "Error")
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
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
Sign in to follow this  
Followers 0