Jump to content
Sign in to follow this  
SystemWontAccept

DLL call for initializing a circuit board

Recommended Posts

SystemWontAccept

I have a circuit board kit that drives a servo. It works. It includes a dll that has instructions to drive the servo (via the dll) but they are for C.

I've read instructions in this forum for calling DLLs in AutoIt but I don't know how to convert the info I have (written in C).

Here's what I know (from the kit instructions.

// Header file for use with mtb.dll

typedef bool (*Type_InitMotoBee)();

typedef bool (*Type_SetMotors)(int on1, int speed1, int on2, int speed2, int on3, int speed3, int on4, int speed4, int servo);

typedef void (*Type_Digital_IO)(int *inputs, int outputs);

And here's what the sample program looks like.

Declare Function InitMotoBee Lib "mtb.dll" () As Boolean

Declare Function Digital_IO Lib "mtb.dll" (ByRef inputs As Integer, ByVal outputs As Integer) As Boolean

Declare Function SetMotors Lib "mtb.dll" (ByVal on1 As Integer, ByVal speed1 As Integer, ByVal on2 As Integer, ByVal speed2 As Integer, ByVal on3 As Integer, ByVal speed3 As Integer, ByVal on4 As Integer, ByVal speed4 As Integer, ByVal servo As Integer) As Boolean

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

InitMotoBee() ' initialise the MotorBee

When you click an onscreen button it initializes the circuit. What would be the syntax to convert this to AutoIt. I've tried numerous ways but I have no clue what the above is doing.

Ed

Share this post


Link to post
Share on other sites
jchd

typedef void (*Type_Digital_IO)(int *inputs, int outputs);

Declare Function Digital_IO Lib "mtb.dll" (ByRef inputs As Integer, ByVal outputs As Integer) As Boolean

This is a contradiction! Let's take it as if mtb.dll returns a status for every call. That's plausible.

Of course I've no way to test this, I'm not even sure of the name of the functions. I suspect something weird with the Type_ prefix, but I don't have my remote dll source reading magic wand nearby at the time of writing...

Beware tht in the unlikely case this would work, I've absolutely no idea of what I'm asking to this thing. Simply hope it isn't able to launch missiles around...

Local $sDll = "mtb.dll"
Local $hDll = DllOpen($sDll)        ; dll file in script dir
If @error Then
    MsgBox(0, '', 'Unable to open ' & $sDll)
    Exit
EndIf

Local $status = MotoBee_Init()
If @error Then
    MsgBox(0, '', 'Unable to initialize MotoBee.')
    Exit
EndIf
MsgBox(0, '', 'Init_MotoBee status = ' & $status)

Local $status = MotoBee_SetMotors(1, 1, 1, 2, 0, 0, 1, 3, 25)       ; set mot 1, 2, 3 at various speeds (?) set servo ar 25, whatever that means
If @error Then
    MsgBox(0, '', 'Unable to pilot motors and servo')
    Exit
EndIf
MsgBox(0, '', 'Init_MotoBee status = ' & $status)
Sleep(1000)                                         ; for one second

Local $status = MotoBee_SetMotors(0, 1, 0, 2, 1, 5, 1, 3, 75)       ; set mot 3, 4 at various speeds (?) set servo ar 75
If @error Then
    MsgBox(0, '', 'Unable to pilot motors and servo')
    Exit
EndIf
MsgBox(0, '', 'Init_MotoBee status = ' & $status)
Sleep(1000)                                         ; for one second

Local $inputs = 0
Local $outputs = 0x55
Local $status = MotoBee_Digital_IO($inputs, $outputs)
If @error Then
    MsgBox(0, '', 'Unable to read/write digital I/O lines')
    Exit
EndIf
MsgBox(0, '', 'Init_MotoBee status = ' & $status)
MsgBox(0, 'MotoBee inputs', 'Read digital I/O lines = ' & Hex($inputs))
Sleep(1000)                                         ; for one second

Local $outputs = 0xAA
Local $status = MotoBee_Digital_IO($inputs, $outputs)
If @error Then
    MsgBox(0, '', 'Unable to read/write digital I/O lines')
    Exit
EndIf
MsgBox(0, '', 'Init_MotoBee status = ' & $status)
MsgBox(0, 'MotoBee inputs', 'Read digital I/O lines = ' & Hex($inputs))
Sleep(1000)                                         ; for one second

DllClose($hDll)




Func MotoBee_Init()
    Local $Ret = DllCall($hDll, "int:cdecl", "Type_InitMotoBee")
    If @error Then Return SetError(@error, 0, 0)
    Return $Ret[0]
EndFunc

Func MotoBee_SetMotors($Mot1On, $Mot1Speed, $Mot2On, $Mot2Speed, $Mot3On, $Mot3Speed, $Mot4On, $Mot4Speed, $Servo)
    Local $Ret = DllCall($hDll, "int:cdecl", "Type_SetMotors", "int", $Mot1On, "int", $Mot1Speed, _
                                                                "int", $Mot2On, "int", $Mot2Speed, _
                                                                "int", $Mot3On, "int", $Mot3Speed, _
                                                                "int", $Mot4On, "int", $Mot4Speed, _
                                                                "int", $Servo)
    If @error Then Return SetError(@error, 0, 0)
    Return $Ret[0]
EndFunc

Func MotoBee_Digital_IO(Byref $MBinputs, $MBoutputs)
    Local $tMBIO = DllStructCreate("int_ptr")
    Local $Ret = DllCall($hDll, "int:cdecl", "Type_Digital_IO", "ptr", DllStructGetPtr($tMBIO, 1), "int", $MBoutputs)
    If @error Then Return SetError(@error)
    $MBinputs = DllStructGetData($tMBIO, 1)
    Return $Ret[0]
EndFunc

Exit

Do you get eroors, where, or does it work somehow?


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
martin

This is a contradiction! Let's take it as if mtb.dll returns a status for every call. That's plausible.

Of course I've no way to test this, I'm not even sure of the name of the functions. I suspect something weird with the Type_ prefix, but I don't have my remote dll source reading magic wand nearby at the time of writing...

Beware tht in the unlikely case this would work, I've absolutely no idea of what I'm asking to this thing. Simply hope it isn't able to launch missiles around...

Local $sDll = "mtb.dll"
Local $hDll = DllOpen($sDll)        ; dll file in script dir
If @error Then
    MsgBox(0, '', 'Unable to open ' & $sDll)
    Exit
EndIf

Local $status = MotoBee_Init()
If @error Then
    MsgBox(0, '', 'Unable to initialize MotoBee.')
    Exit
EndIf
MsgBox(0, '', 'Init_MotoBee status = ' & $status)

Local $status = MotoBee_SetMotors(1, 1, 1, 2, 0, 0, 1, 3, 25)       ; set mot 1, 2, 3 at various speeds (?) set servo ar 25, whatever that means
If @error Then
    MsgBox(0, '', 'Unable to pilot motors and servo')
    Exit
EndIf
MsgBox(0, '', 'Init_MotoBee status = ' & $status)
Sleep(1000)                                         ; for one second

Local $status = MotoBee_SetMotors(0, 1, 0, 2, 1, 5, 1, 3, 75)       ; set mot 3, 4 at various speeds (?) set servo ar 75
If @error Then
    MsgBox(0, '', 'Unable to pilot motors and servo')
    Exit
EndIf
MsgBox(0, '', 'Init_MotoBee status = ' & $status)
Sleep(1000)                                         ; for one second

Local $inputs = 0
Local $outputs = 0x55
Local $status = MotoBee_Digital_IO($inputs, $outputs)
If @error Then
    MsgBox(0, '', 'Unable to read/write digital I/O lines')
    Exit
EndIf
MsgBox(0, '', 'Init_MotoBee status = ' & $status)
MsgBox(0, 'MotoBee inputs', 'Read digital I/O lines = ' & Hex($inputs))
Sleep(1000)                                         ; for one second

Local $outputs = 0xAA
Local $status = MotoBee_Digital_IO($inputs, $outputs)
If @error Then
    MsgBox(0, '', 'Unable to read/write digital I/O lines')
    Exit
EndIf
MsgBox(0, '', 'Init_MotoBee status = ' & $status)
MsgBox(0, 'MotoBee inputs', 'Read digital I/O lines = ' & Hex($inputs))
Sleep(1000)                                         ; for one second

DllClose($hDll)




Func MotoBee_Init()
    Local $Ret = DllCall($hDll, "int:cdecl", "Type_InitMotoBee")
    If @error Then Return SetError(@error, 0, 0)
    Return $Ret[0]
EndFunc

Func MotoBee_SetMotors($Mot1On, $Mot1Speed, $Mot2On, $Mot2Speed, $Mot3On, $Mot3Speed, $Mot4On, $Mot4Speed, $Servo)
    Local $Ret = DllCall($hDll, "int:cdecl", "Type_SetMotors", "int", $Mot1On, "int", $Mot1Speed, _
                                                                "int", $Mot2On, "int", $Mot2Speed, _
                                                                "int", $Mot3On, "int", $Mot3Speed, _
                                                                "int", $Mot4On, "int", $Mot4Speed, _
                                                                "int", $Servo)
    If @error Then Return SetError(@error, 0, 0)
    Return $Ret[0]
EndFunc

Func MotoBee_Digital_IO(Byref $MBinputs, $MBoutputs)
    Local $tMBIO = DllStructCreate("int_ptr")
    Local $Ret = DllCall($hDll, "int:cdecl", "Type_Digital_IO", "ptr", DllStructGetPtr($tMBIO, 1), "int", $MBoutputs)
    If @error Then Return SetError(@error)
    $MBinputs = DllStructGetData($tMBIO, 1)
    Return $Ret[0]
EndFunc

Exit

Do you get eroors, where, or does it work somehow?

According to one of the links on that site, all the functions are stdcall so the :cdecl should be removed in all the DlCall lines.

The $Servo parameter is for an angle. I assume that one of the outputs is for a servo motor which is set to that angle but I don't see what the feedback is to know the angle.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
jchd

Thanks Martin. The VB style should have decided me to remove he :cdecl instead of having the OP do that in case of error.

So there's a site for this PIC thing? OK, got it.

@OP you should have told us there was. Try the revised version.

Local $sDll = "mtb.dll"     ; path of dll file
Local $hDll = DllOpen($sDll)
If @error Then
    MsgBox(0, '', 'Unable to open ' & $sDll)
    Exit
EndIf

Local $status = MotoBee_Init()
If @error Then
    MsgBox(0, '', 'Unable to initialize MotoBee.')
    Exit
EndIf
MsgBox(0, '', 'Init_MotoBee status = ' & $status)

Local $status = MotoBee_SetMotors(1, 5, 1, 10, 0, 0, 1, 15, 25)     ; set mot 1, 2, 3 at various speeds (?) set servo ar 25, whatever that means
If @error Then
    MsgBox(0, '', 'Unable to pilot motors and servo')
    Exit
EndIf
MsgBox(0, '', 'Init_MotoBee status = ' & $status)
Sleep(1000)                                         ; for one second

Local $status = MotoBee_SetMotors(0, 1, 0, 2, 1, 20, 1, 25, 75)     ; set mot 3, 4 at various speeds (?) set servo at 75
If @error Then
    MsgBox(0, '', 'Unable to pilot motors and servo')
    Exit
EndIf
MsgBox(0, '', 'Init_MotoBee status = ' & $status)
Sleep(1000)                                         ; for one second

Local $inputs = 0
Local $outputs = 0x55
Local $status = MotoBee_Digital_IO($inputs, $outputs)
If @error Then
    MsgBox(0, '', 'Unable to read/write digital I/O lines')
    Exit
EndIf
MsgBox(0, '', 'Init_MotoBee status = ' & $status)
MsgBox(0, 'MotoBee inputs', 'Read digital I/O lines = ' & Hex($inputs))
Sleep(1000)                                         ; for one second

Local $outputs = 0xAA
Local $status = MotoBee_Digital_IO($inputs, $outputs)
If @error Then
    MsgBox(0, '', 'Unable to read/write digital I/O lines')
    Exit
EndIf
MsgBox(0, '', 'Init_MotoBee status = ' & $status)
MsgBox(0, 'MotoBee inputs', 'Read digital I/O lines = ' & Hex($inputs))
Sleep(1000)                                         ; for one second

DllClose($hDll)




Func MotoBee_Init()
    Local $Ret = DllCall($hDll, "int", "InitMotoBee")
    If @error Then Return SetError(@error, 0, 0)
    Return $Ret[0]
EndFunc

Func MotoBee_SetMotors($Mot1On, $Mot1Speed, $Mot2On, $Mot2Speed, $Mot3On, $Mot3Speed, $Mot4On, $Mot4Speed, $Servo)
    Local $Ret = DllCall($hDll, "int", "SetMotors", "int", $Mot1On, "int", $Mot1Speed, _
                                                    "int", $Mot2On, "int", $Mot2Speed, _
                                                     "int", $Mot3On, "int", $Mot3Speed, _
                                                     "int", $Mot4On, "int", $Mot4Speed, _
                                                     "int", $Servo)
    If @error Then Return SetError(@error, 0, 0)
    Return $Ret[0]
EndFunc

Func MotoBee_Digital_IO(Byref $MBinputs, $MBoutputs)
    Local $tMBIO = DllStructCreate("int_ptr")
    Local $Ret = DllCall($hDll, "int", "Digital_IO", "ptr", DllStructGetPtr($tMBIO, 1), "int", $MBoutputs)
    If @error Then Return SetError(@error)
    $MBinputs = DllStructGetData($tMBIO, 1)
    Return $Ret[0]
EndFunc

If it works, you'll have to learn how to do things smoothly (ramp motors up and down, turn slowly, etc).

After that, you want to program the PIC (I guess it's one) yourself for better autonomy, etc.

Have fun!

EDIT:

ProgAndy is right: I found the PC Control site, looked at the .pdf there but failed to remember to remove the Type_ thing (which is an error, there is no underscore in the doc)

With some more patience for the OP and possibly more help from other contributors (as I'm being more dumb than usual), everyhing will run fine ... some day. The most important is that ther's still a bit of hope! Apologies.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
ProgAndy

If it works, you'll have to learn how to do things smoothly (ramp motors up and down, turn slowly, etc).

I think you have to remove the Type_-prefix from the functions since it is not there in the VB-declaration.

@SystemWontAccept: just try both funcion names and check for @error :D


*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

Share this post


Link to post
Share on other sites
SystemWontAccept

The code is golden!

You guys are AWESOME! My servo initializes AND moves. I'll go though this code as my tutorial.

This will allow me to build a real world gage that shows my Internet utilization... I hope.

I've got some math to do but that's easy. This is exciting!

Thank-you, Thank-you, THANK-YOU!!

Share this post


Link to post
Share on other sites
jchd

You guys are AWESOME! My servo initializes AND moves. I'll go though this code as my tutorial.

Glad to see it brings the beast to life!

Now you have to learn how to "pilot" the motors, servo and I/O with care.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.