madhutm Posted February 5, 2014 Share Posted February 5, 2014 i have one function in c++ thats connect with device via bluetooth.how can i call that function from autoit scripting? Link to comment Share on other sites More sharing options...
FireFox Posted February 5, 2014 Share Posted February 5, 2014 Hi,Welcome to the autoit forum I assume the function is in a library, so you have to use the DllCall function.Br, FireFox. Link to comment Share on other sites More sharing options...
madhutm Posted February 5, 2014 Author Share Posted February 5, 2014 hi ths for reply.ya i am calling that function using calldll.But that not working fine. The function return type is bool every it will give different integer number($dll[0]) but it will not connected to the device.is there any prerequires to calling this type of functions. Link to comment Share on other sites More sharing options...
madhutm Posted February 5, 2014 Author Share Posted February 5, 2014 The function is like this in c++ Control(int ctl, byte[] inData, int inLen, byte[] outData, ref int outLen) Link to comment Share on other sites More sharing options...
FireFox Posted February 5, 2014 Share Posted February 5, 2014 (edited) $ctl = 0 $tStruct = DllStructCreate("byte[256]") ;set your byte size here DllStructSetData($tStruct, 1, ... $inLen = 0 $tStruct2 = DllStructCreate("byte[256]") ;set your byte size here $outLen = 0 DllCall("yourlib.dll", "bool", "Control", "int", $ctl, "struct*", $tStruct, "int", $inLen, "struct*", $tStruct2, "int*", $outLen) ;Control(int ctl, byte[] inData, int inLen, byte[] outData, ref int outLen)Not sure if it's a struct*, or if it's a ptr (in this case you will use DllStructGetPtr with the 1st element).Edit: And you will maybe need a struct for the int pointer (I'm pretty sure about it though).Br, FireFox. Edited February 5, 2014 by FireFox Link to comment Share on other sites More sharing options...
madhutm Posted February 5, 2014 Author Share Posted February 5, 2014 ths for reply. i don't know about inside code in c++.same function i am calling from c# it works fine in c#.for testing purpose i need to call this function from autoit. can you please tell me how to convert hex string to bytearray in Autoit. the above function second parameter i need to send this byte array only. Link to comment Share on other sites More sharing options...
FireFox Posted February 5, 2014 Share Posted February 5, 2014 (edited) Here you go:$b = StringToBinary("0x123ABC....") $tStruct = DllStructCreate("byte[" & BinaryLen($b) & "]") DllStructSetData($tStruct, 1, $b)Br, FireFox. Edited February 5, 2014 by FireFox Link to comment Share on other sites More sharing options...
madhutm Posted February 6, 2014 Author Share Posted February 6, 2014 hi still it's giving different integer number only. i am trying to connect blutooth device via com port.after taking com number i am conveting into hexstring then hexstring to bytearray. ths Link to comment Share on other sites More sharing options...
madhutm Posted February 6, 2014 Author Share Posted February 6, 2014 this is how i am sending the function  DllCall($dll,"bool:cdecl","BCRBT_Control","int", $ctl, "struct*", $tStruct, "int", $inLen, "struct*", $tStruct2, "int*", $outLen) my paramer values are        Local $input = GUICtrlRead($hInput)       Local $dd = StringFormat("%X",$input)       Local $outLen = 0;       Local $ctl =0xf901;       $tStruct2 = DllStructCreate("byte[0xff]")       $inLen =0;       $b = StringToBinary($dd)       $tStruct = DllStructCreate("byte[" & BinaryLen($ & "]")       DllStructSetData($tStruct, 1, $  Link to comment Share on other sites More sharing options...
FireFox Posted February 6, 2014 Share Posted February 6, 2014 i am trying to connect blutooth device via com port. Have you tried to communicate directly with the COM port? An example >here. If your struct2 is a simple byte (not a byte array), call the parameter with BYTE and directly 0xFF. Br, FireFox. Link to comment Share on other sites More sharing options...
madhutm Posted February 6, 2014 Author Share Posted February 6, 2014 hi, that stringtobinary function not working properly.my port number is 30 after converting this to hexstring the value become 1E.while converting this value to binary that $b value gives (0x313445) but this is not binary format. and struct2 is byte array.in c# i am declaring like this byte[] = new byte[0xff]; how can i declare same like this in autoit. and how can i find the tstruct lengh because i need to send this as third parameter to function. ths Link to comment Share on other sites More sharing options...
FireFox Posted February 6, 2014 Share Posted February 6, 2014 that stringtobinary function not working properly.my port number is 30 after converting this to hexstring the value become 1E.while converting this value to binary that $b value gives (0x313445)but this is not binary format.Binary is not 010101... it's hexadecimal in Binary variable type.StringToBinary("0xABCDE") ;will be converted to binary typeand struct2 is byte array.in c# i am declaring like this byte[] = new byte[0xff]; how can i declare same like this in autoit.$tStruct2 = DllStructCreate("byte[" & 0xFF & "]") ;or 255and how can i find the tstruct lengh because i need to send this as third parameter to function.You haven't searched at all, take a look at the help file and you will find related function DllStructGetSize.Br, FireFox. Link to comment Share on other sites More sharing options...
madhutm Posted February 6, 2014 Author Share Posted February 6, 2014 after createng $struct2 i was trying to print that value like this Msgbox(0,"text",$tStruct) it'will showing nothing if it is wrong how can i print $tsturct. Link to comment Share on other sites More sharing options...
FireFox Posted February 6, 2014 Share Posted February 6, 2014 Please read the helpfile : Return Value Success: a variable for use with DllStruct calls And check the examples. Br, FireFox. Link to comment Share on other sites More sharing options...
madhutm Posted February 7, 2014 Author Share Posted February 7, 2014 forgot above one for while this is my Bio_diconnect function it will not take any parameter.this one also not calling. i am calling liki this Local $ t1 = calldll($dll,"bool:cdecl","Bio_Disconnect") msgbox(0,"txt",$t1[0]) this value give different integer numbers every time(not 0 or 1) my question is there anything i need to setup working with bluetooth device or not. Link to comment Share on other sites More sharing options...
JohnOne Posted February 7, 2014 Share Posted February 7, 2014 Show how you successfully call the function from C#. AutoIt Absolute Beginners  Require a serial  Pause Script  Video Tutorials by Morthawt  ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
madhutm Posted February 7, 2014 Author Share Posted February 7, 2014 i print the @error it i will gives the 0 value.so i call the function successfully right. ths Link to comment Share on other sites More sharing options...
JohnOne Posted February 7, 2014 Share Posted February 7, 2014 Show how you successfully call the function from C#. AutoIt Absolute Beginners  Require a serial  Pause Script  Video Tutorials by Morthawt  ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
madhutm Posted February 7, 2014 Author Share Posted February 7, 2014 Public bool Bio_Disconnect() like this i call in c# Link to comment Share on other sites More sharing options...
madhutm Posted February 7, 2014 Author Share Posted February 7, 2014 sry if(Bio_Disconnect){ ............ } this how exactly iam calling in c# Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now