KaVaD 0 Posted August 10, 2010 I am a newbie to Autoit and need help with dll calls to a relayboard to switch on and off some relays. the dll's internal look like this: // masdll.h // Header file for the Control Master DLL /////////////////////////////////////////////// // General Defs #define MAXBOARDS 30 // maximum number of boards that can be connected to the system // Board type defs #define BOARD_MASTER 0 // non isolated master controller #define BOARD_ISOMASTER 1 // isolated master controller #define BOARD_DIGITAL_IOSLAVE 2 // digital I/O Slave #define BOARD_ANALOGUE_IOSLAVE 3 // analogue I/O slave #define BOARD_RELAY_SLAVE 4 // relay slave #define BOARD_MOTOR_SLAVE 5 // motor slave #define NO_BOARD_DETECTED 123 // no board detected at the specified board number // error defs #define SUCCESS 0 // no error #define ERR_REQUEST_FAILED -1 // non specific general failure to process command #define ERR_INVBOARDNUMBER -2 // invalid board number specified as parameter #define ERR_NOMASTERFOUND -3 // no master controller found #define ERR_USB_MESSAGING_ERROR -4 // message received from USB was not as expected (length or header byte) #define ERR_CHECKSUM -5 // checksum error in data received from slave #define ERR_WRONG_BOARD_TYPE -6 // wrong command for the board type (eg CM_RELAY_Update used with board number of a Motor Slave) // sub command defs #define MOTOR_STOP 1 // stop command used within Direction command #define MOTOR_FORWARD 2 // forward command used within Direction command #define MOTOR_REVERSE 3 // reverse command used within Direction command // DLL Function type definitions typedef int (*Type_Mas_Initialise)(); typedef int (*Type_Mas_SendMessage8)(int board, int command, int *message, int *answer); typedef int (*Type_CM_Initialise)(); typedef int (*Type_CM_GetBoardType)(int BoardNumber); typedef int (*Type_CM_DIO_Update)(int BoardNumber, int Outputs, int *Inputs); typedef int (*Type_CM_DIO_GetStatus)(int BoardNumber, int *Outputs); typedef int (*Type_CM_RELAY_Update)(int BoardNumber, int Outputs, int *Inputs); typedef int (*Type_CM_RELAY_GetStatus)(int BoardNumber, int *Outputs); typedef int (*Type_CM_ANIO_Update1to4)(int BoardNumber, int Outputs, int *Inputs, int Sensitivity); typedef int (*Type_CM_ANIO_Update5to8)(int BoardNumber, int Outputs, int *Inputs, int Sensitivity); typedef int (*Type_CM_ANIO_GetStatus)(int BoardNumber, int *Outputs, int *Sensitivity); typedef int (*Type_CM_Motor_M1Speed)(int BoardNumber, int Speed, int *Inputs); typedef int (*Type_CM_Motor_M1Direction)(int BoardNumber, int Direction, int *Inputs); typedef int (*Type_CM_Motor_M2Speed)(int BoardNumber, int Speed, int *Inputs); typedef int (*Type_CM_Motor_M2Direction)(int BoardNumber, int Direction, int *Inputs); typedef int (*Type_CM_Motor_ReadInputs)(int BoardNumber, int *Inputs); typedef int (*Type_CM_Motor_GetStatus)(int BoardNumber, int *M1Speed, int *M1Dir, int *M2Speed, int *M2Dir, int *Inputs); This is what I have done so far with no success. The boardnumber has address 2 via a dil switch on the printboard. The outputs value 85 is the decimal value of binary value 01010101 which will turn on relays 1,3,5 and 7 (reading from right to left) Global $Boardnumber Global $Outputs Global $Inputs Global $RelayUpd Dim $Error $Error = CM_Initalise() If $Error = 0 Then test() $Boardnumber = 2 $Outputs = 85 $Inputs = 0 CM_RELAY_Update($Boardnumber,$Outputs,$Inputs) MsgBox(0,"RelayUpdat",$RelayUpd) Else EndIf Func CM_Initalise() $Init= DllCall ("mas.dll","int","Initialise") if @error Then Return 0 Return $Init EndFunc Func CM_RELAY_Update($Boardnumber,$Outputs,$Inputs) $RelUpd = DllCall ("mas.dll","int","Boardnumber","int","Outputs","int","Inputs") if @error Then Return 0 Return $RelUpd[0] EndFunc Can someone help me with the calls ? maybe a working example? thanks in advance KaVaD Share this post Link to post Share on other sites
PsaltyDS 42 Posted August 10, 2010 (edited) Func CM_Initalise() $Init= DllCall ("mas.dll","int","Initialise") if @error Then Return 0 Return $Init EndFunc Can someone help me with the calls ? maybe a working example? The header you posted is like a bunch of DllStructCreate() tags, not the functions themselves. Shouldn't that cal for example be to "CM_Initialise"? DllCall() always returns an array. The returned int value would be in $Init[0]. Edited August 10, 2010 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Share this post Link to post Share on other sites
KaVaD 0 Posted August 10, 2010 The header you posted is like a bunch of DllStructCreate() tags, not the functions themselves. Shouldn't that cal for example be to "CM_Initialise"? DllCall() always returns an array. The returned int value would be in $Init[0]. In the Manual the Function Name is: CM_Initialise Syntax for 'C/C++' is : int CM_Initalise() Syntax for 'Visual Basic' : CM_Initialise () As Integer Function Name: CM_RELAY_Update Syntax for 'C/C++' : int CM_RELAY_Update (int BoardNumber,int Outputs, int Inputs) Syntax for 'Visual Basic' :CM_RELAY_Update (ByVal BoardNumber AS Integer, ByVal Outputs As Integer, ByVal Inputs As Integer ) As Integer I have no idea how to translate it to Autoit KaVaD Share this post Link to post Share on other sites
KaVaD 0 Posted August 10, 2010 Anyone who can give me some starting help, with an example code? KaVaD Share this post Link to post Share on other sites
Richard Robertson 187 Posted August 10, 2010 Those aren't functions or structures. Those are just definitions for callbacks actually. What C++ you posted alone wouldn't even work in C++. Share this post Link to post Share on other sites
KaVaD 0 Posted August 10, 2010 The manual of the Control board and the Relay board is at this url.Linkon page 37 the programmers guide start.KaVaD Share this post Link to post Share on other sites
KaVaD 0 Posted August 11, 2010 In the manual a VB dllcall has this syntax :Declare Function CM_DIO_Update Lib "mas.dll" (ByVal BoardNumber As Integer, ByVal Outputs As Integer, ByRef Inputs As Integer) As IntegerDim BoardNumber As IntegerDim Inputs As IntegerDim Outputs As IntegerBoardNumber = 2Outputs = 85 „ outputs 1,3,5 and 7 On, 2,4,6 and 8 off„ Update the board (i.e. send the new outputs and read back the current inputsCM_DIO_Update( BoardNumber, Outputs, Inputs )„ After the above call, the variable inputs would hold the current pattern of inputs appearing at the boardIs this how you will call it from Autoit??Global $BoardnumberGlobal $Outputs Global $Inputs Global $DIO_upd$Boardnumber = 2$Outputs = 85$Inputs = 0CM_DIO_Update($Boardnumber,$Outputs,$Inputs)Func CM_DIO_Update($Boardnumber,$Outputs,$Inputs) $DIO_upd = DllCall ("mas.dll","int","Boardnumber","int","Outputs","int","Inputs") if @error Then Return 0Return $DIO_upd EndFunc KaVaD Share this post Link to post Share on other sites
PsaltyDS 42 Posted August 12, 2010 You might try it like this: #include <Array.au3> ; Declare Function CM_DIO_Update Lib "mas.dll" ( ; ByVal BoardNumber As Integer, _ ; ByVal Outputs As Integer, _ ; ByRef Inputs As Integer) As Integer Global $iBoardNum = 2 Global $iOutputs = 85 Global $iInputs = 0 Global $aRET = DllCall("mas.dll", "int", "CM_DIO_Update", "int", $iBoardNum, "int", $iOutputs, "int*", $iInputs) ; [0] = Return value (usually 0=success, depends on function) ; [1] = Repeat back of first param ; [2] = Repeat back of second param ; [3] = Repeat back of third param, which may have been changed by the function (because it was passed ByRef "int*") _ArrayDisplay($aRET, "$aRET") Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Share this post Link to post Share on other sites