KF5WGB Posted September 14, 2019 Share Posted September 14, 2019 Hi Coders, I am a new to Objects. I do not know how to explain it in a short way, so please stick with me.... here it goes... Looooong time ago this was posted: ..and the thread died quickly. I recently installed the program OmniRig.exe (it is for Radio control) , the program in question to read and send data to. I changed some of the script that big_daddy got out of the VB code and it works fine reading data from The OmniRig object. The problem is/was the thread was never finished on how to send data to the object. Well I tried a few different ways without success. I get an "The requested action with this object has failed error", so I contacted the Dev and asked if there is a manual or documentation available. He replied: " There is no documentation, other than the type library included in the exe file. The first step in using OmniRig in custom software is to include its type library in the project, then the programmer can browse and use all methods, properties and events of OmniRig. You can specify either the number of bytes in the reply or the terminating character. Pass 0 and a blank string if no reply is expected. I am not familiar with AutoIt, sorry. The first parameter passed to SendCustomCommand must be a byte array, not a string. I don't know how byte arrays are created in your language. " With OLEView.exe I opened the OmniRige.exe and found: procedure SendCustomCommand(Command: OleVariant; ReplyLength: Integer; ReplyEnd: OleVariant); I created the handle for the OmniRig object: $OmniRigEngine = ObjCreate("OmniRig.OmniRigX") ..and then when a certain button is pressed this function gets called: Func _TXVoiceMemo1() If Not IsObj($OmniRigEngine) Then ;checking if OmniRig is running/loaded SetError(1) Return 0 EndIf $OmniRigEngine.SendCustomCommand("0xFEFE94E0280001FD",0,"") ;<-error: The requested action with this object has failed. ->well, because I send a string. EndFunc Now how do I make a byte Array out of "FEFE94E0280001FD"? It is not $sCommad[1] = "FEFE94E0280001FD",and then $OmniRigEngine.SendCustomCommand($sCommand[1],0,"") , right? I tried and get the failed object error. if you want to play with the code: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=Betatest\omnirig_interface.Exe #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;Project: Omni-RigX Monitor with AutoIt v3 ;Original scritpt: https://www.autoitscript.com/forum/topic/30923-com-obj/?tab=comments#comment-221570 ;Original date: August 14,2006 ;Modified by: KF5WGB ;Date: September 14,2019 ;Credits: big_daddy, Moderator @ www.autoit.com #include <Array.au3> #include <GUIConstants.au3> Opt("GUIOnEventMode", 1) ; declare mode variables Global $PM_CW_U = 8388608 Global $PM_CW_L = 16777216 Global $PM_SSB_U = 33554432 Global $PM_SSB_L = 67108864 Global $PM_DIG_U = 13421772 Global $PM_DIG_L = 268435456 Global $PM_AM = 536870912 Global $PM_FM = 1073741824 Global $PM_RTTY_R = 1342117728 ;other ;more variables Global $oEvent, $Rig, $RigNumber, $OurRigNo, $NewRigNo, $OmniRigEngine, $Frequency_Rig, $Frequency_display, $front, $middle, $right $Form1 = GUICreate("Omni-RigX Monitor", 320, 160, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $Button1 = GUICtrlCreateButton("Configure", 24, 105, 75, 25, 0) GUICtrlSetOnEvent(-1, "_Configure") ;$Button2 = GUICtrlCreateButton("Start", 24, 240, 75, 25, 0) ;if you want a start button ;GUICtrlSetOnEvent(-1, "_StartOmniRig") ;position the label and remove the ;'s $Radio1 = GUICtrlCreateRadio("#1", 24, 30, 40, 17) GUICtrlSetState($Radio1, $gui_checked) ;use Rig #1 by default GUICtrlSetOnEvent(-1, "_SelectRig") $TX1 = GUICtrlCreateButton("TX1",90,30,40,20,0) ;create a TX button for future voice keyer (TX 1 - 8 ) GUICtrlSetOnEvent(-1, "_TXVoiceMemo1") ;function to call, sending command to trigger voicekeyer $Radio2 = GUICtrlCreateRadio("#2", 24, 60, 40, 17) GUICtrlSetOnEvent(-1, "_SelectRig") $Label1 = GUICtrlCreateLabel("RX: ", 160, 30, 150, 17) $Label2 = GUICtrlCreateLabel("TX: ", 160, 60, 150, 17) $Label3 = GUICtrlCreateLabel("0.00", 200, 30, 150, 17) $Label4 = GUICtrlCreateLabel("0.00", 200, 60, 150, 17) $Label5 = GUICtrlCreateLabel("Mode", 160, 100, 150, 17) $Label6 = GUICtrlCreateLabel("", 200, 100, 150, 17) $Label7 = GUICtrlCreateLabel("Status", 160, 120, 150, 17) $Label8 = GUICtrlCreateLabel("", 200, 120, 150, 17) $Group1 = GUICtrlCreateGroup("Rig", 10, 10, 300, 140) GUISetState(@SW_SHOW) _StartOmniRig() ;fire up Omnirig if @error Then MsgBox(48, "Error", "Unable to create OmniRig Object." & @CRLF & "OmniRig is not installed.") Exit EndIf While 1 Sleep(100) ;Run program until X is pressed WEnd Func _StartOmniRig() $OmniRigEngine = ObjCreate("OmniRig.OmniRigX") If Not IsObj($OmniRigEngine) Then SetError(1) Return 0 EndIf ;we want OmniRig interface V.1.1 to 1.99 ;as V2.0 will likely be incompatible with 1.x ;consolewrite($OmniRigEngine.InterfaceVersion & @CRLF) If $OmniRigEngine.InterfaceVersion < 101 Then MsgBox(48, "Error", "OmniRig is not installed or has a wrong version number") Exit ElseIf $OmniRigEngine.InterfaceVersion > 299 Then MsgBox(48, "Error", "OmniRig is not installed or has a wrong version number") Exit EndIf $oEvent = ObjEvent($OmniRigEngine, "Evt_") _SelectRig() EndFunc ;==>_StartOmniRig Func _SelectRig($NewRigNo = 1) If Not IsObj($OmniRigEngine) Then SetError(1) Return 0 EndIf If GUICtrlRead($Radio1) = $GUI_CHECKED Then $NewRigNo = 1 ElseIf GUICtrlRead($Radio2) = $GUI_CHECKED Then $NewRigNo = 2 EndIf $OurRigNo = $NewRigNo Switch $NewRigNo Case 1 $Rig = $OmniRigEngine.Rig1 Case 2 $Rig = $OmniRigEngine.Rig2 EndSwitch _ShowRigStatus() _ShowRigParams() EndFunc ;==>_SelectRig Func _ShowRigStatus() If Not IsObj($Rig) Then SetError(1) Return 0 EndIf ; ;Check if Rig is a IC7300 and toggle TX button ; if $Rig.Rigtype = "IC-7300" Then GUICtrlSetState($TX1, $GUI_Enable) Else GUICtrlSetState($TX1, $GUI_Disable) EndIf GUICtrlSetData($Label8, $Rig.StatusStr) GUICtrlSetData($Group1, $Rig.Rigtype) ; Write Object/Rig Info to console everytime the Rig is switched / just for dev and monitor reasons~~ Consolewrite("Software Version.......................: " & $OmniRigEngine.Softwareversion & @crlf) Consolewrite("Interface Version......................: " & $OmniRigEngine.InterfaceVersion & @CRLF) Consolewrite("Object filename in REG.................: " & ObjName($OmniRigEngine,4) & @crlf) Consolewrite("Object Name............................: " & ObjName($OmniRigEngine,1) & @crlf) Consolewrite("Object Description.....................: " & ObjName($OmniRigEngine,2) & @crlf) Consolewrite("Object Program ID......................: " & ObjName($OmniRigEngine,3) & @crlf) Consolewrite("Module/Program in which the Object runs: " & ObjName($OmniRigEngine,5) & @crlf) Consolewrite("Object CLSID codeclass.................: " & ObjName($OmniRigEngine,6) & @crlf) Consolewrite("Object IID Interface...................: " & ObjName($OmniRigEngine,7) & @crlf) consolewrite("Rig type...............................: " & $rig.RigType & @CRLF) consolewrite("Rig status.............................: " & $rig.StatusStr & @CRLF) consolewrite("Rig Mode...............................: " & $rig.Mode & @CRLF) consolewrite("VFO A..................................: " & $rig.FreqA & @CRLF) consolewrite("VFO B..................................: " & $rig.FreqB & @CRLF & @CRLF) ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ EndFunc ;==>_ShowRigStatus Func _ShowRigParams() If Not IsObj($Rig) Then SetError(1) Return 0 EndIf $Frequency_Rig = $Rig.GetRxFrequency ; Put the dots in the Freq readout $right = "." & StringRight($Frequency_Rig,3) $Frequency_Rig = StringTrimRight($Frequency_Rig,3) $middle = "." & StringRight($Frequency_Rig,3) $Frequency_Rig = StringTrimRight($Frequency_Rig,3) $front = StringRight($Frequency_Rig,3) $Frequency_display = $front & $middle & $right ; not needed, just for optics GUICtrlSetData($Label3, $Frequency_display) $Frequency_Rig = $Rig.GetTxFrequency ; Put the dots in the Freq readout $right = "." & StringRight($Frequency_Rig,3) $Frequency_Rig = StringTrimRight($Frequency_Rig,3) $middle = "." & StringRight($Frequency_Rig,3) $Frequency_Rig = StringTrimRight($Frequency_Rig,3) $front = StringRight($Frequency_Rig,3) $Frequency_display = $front & $middle & $right ; not needed, just for optics GUICtrlSetData($Label4, $Frequency_display) Switch $Rig.Mode Case $PM_CW_L, $PM_CW_U GUICtrlSetData($Label6, "CW") Case $PM_SSB_L GUICtrlSetData($Label6, "LSB") Case $PM_SSB_U GUICtrlSetData($Label6, "USB") Case $PM_FM GUICtrlSetData($Label6, "FM") Case $PM_AM GUICtrlSetData($Label6, "AM") Case $PM_DIG_U GUICtrlSetData($Label6, "USB DIGITAL") Case $PM_DIG_L GUICtrlSetData($Label6, "LSB DIGITAL") Case Else GUICtrlSetData($Label6, "Other") EndSwitch EndFunc ;==>_ShowRigParams Func _Configure() If Not IsObj($OmniRigEngine) Then SetError(1) Return 0 EndIf $OmniRigEngine.DialogVisible = True EndFunc ;==>_Configure Func Evt_StatusChange($RigNumber) If $RigNumber = $OurRigNo Then _ShowRigStatus() EndFunc ;==>Evt_StatusChange Func Evt_ParamsChange($RigNumber, $Params) If $RigNumber = $OurRigNo Then _ShowRigParams() EndFunc ;==>Evt_ParamsChange func _TXVoiceMemo1() If Not IsObj($Rig) Then SetError(1) Return 0 EndIf #cs NO documentation available from developer. Refers to Library in EXE file. From source code : procedure SendCustomCommand(Command: OleVariant; ReplyLength: Integer; ReplyEnd: OleVariant); Dev said: parameter passed to SendCustomCommand must be a byte array #ce local $sendarray[1] = ["0xFEFE94E0280001FD"] ;$Rig.SendCustomCommand($sendarray[0],0,"") ; does nothing $OmniRigEngine.SendCustomCommand($sendarray[0],0,"") ; (219) : ==> The requested action with this object has failed. ; $OmniRigEngine.SendCustomCommand($sendarray[0],0,"") ; $OmniRigEngine^ ERROR ConsoleWrite("Sending command to: " & $Rig.Rigtype & @crlf & "Command: " & $sendarray[0] & @CRLF) EndFunc Func _Exit() Exit EndFunc ;==>_Exit The program OmniRig is here: OmniRig If you install and run OmniRig for testing this script make sure one Rig is selected as an IC-7300. So what it all comes down to is: How do I create a Byte Array out of FEFE94E0280001FD and pass it on to the $OnmniRigEngine. As always, thanks for any help and advice 73, KF5WGB Link to comment Share on other sites More sharing options...
trancexx Posted September 14, 2019 Share Posted September 14, 2019 Byte array would be Binary("0xFE....") ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
KF5WGB Posted September 14, 2019 Author Share Posted September 14, 2019 41 minutes ago, trancexx said: Byte array would be Binary("0xFE....") trancexx, Hvala vam, Hvala vam, Hvala vam... Hope I got that right. That was quick and absolutely spot on. Again Hvala vam. I have a lot to learn about those Object things and Arrays. I thought creating objects only works with apps and dll's from Micro$oft. OLEview came in handy to get the functions/procedures from OmniRig. $Rig.SendCustomCommand(Binary("0xFEFE94E0280001FD"),0,"") works now. Thank you so much...Vielen Dank. Have a great weekend. 73 de KF5WGB Link to comment Share on other sites More sharing options...
trancexx Posted September 15, 2019 Share Posted September 15, 2019 22 hours ago, KF5WGB said: trancexx, Hvala vam, Hvala vam, Hvala vam... Hope I got that right. That was quick and absolutely spot on. Again Hvala vam. I have a lot to learn about those Object things and Arrays. I thought creating objects only works with apps and dll's from Micro$oft. OLEview came in handy to get the functions/procedures from OmniRig. $Rig.SendCustomCommand(Binary("0xFEFE94E0280001FD"),0,"") works now. Thank you so much...Vielen Dank. Have a great weekend. 73 de KF5WGB "Hvala vam" is too formal, "Hvala ti" would be more appropriate. Both would be "thank you" in English, because "thee", "thou", "ye" and whatnot all died with Shakespeare. ♡♡♡ . eMyvnE 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