mlw19mlw91 Posted September 6, 2020 Posted September 6, 2020 I have the following code which I pulled from a website on how to automate an HP turntable for 3d scanning: #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <GuiComboBox.au3> #include "CommInterface.au3" #include <Timers.au3> $arm = 0 ; variable to coordinate between scan button and Deviare callback $numberOfScans = 40 ; we stop after 40 $doScan = 0 ; used as a signal by Deviare callback, so that the GUI thread knows to run another scan $hGUI = GUICreate("DAVID Laserscanner 5 Turntable Automator",500,120) $x_coordinate = GUICtrlCreateInput("120", 220, 20, 90, 20, $ES_NUMBER ) $y_coordinate = GUICtrlCreateInput("300", 220, 45, 90, 20, $ES_NUMBER ) GUICtrlCreateLabel("X coordinate of Scan button in DAVID:", 20, 20+2) GUICtrlCreateLabel("Y coordinate of Scan button in DAVID:", 20, 50+2) GUICtrlCreateLabel("COM Port:", 20, 80+2) $comboBoxCOM = GUICtrlCreateCombo("", 220, 70, 90, 20) For $i = 1 To 100 $sVar = RegEnumVal("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM", $i) If @error <> 0 Then ExitLoop Local $sVar2 = RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM", $sVar) $isCom = StringInStr($sVar2,"COM") ; check for presence of the substring "COM" in the key if ($isCom <> 0) then GUICtrlSetData($comboBoxCOM,$sVar2) _GUICtrlComboBox_SetEditText($comboBoxCOM,$sVar2) EndIf Next Local $idScan = GUICtrlCreateButton("Scan", 350, 20, 100, 32) Local $idStop = GUICtrlCreateButton("Abort", 350, 57, 100, 32) GUISetState(@SW_SHOW, $hGUI) ; Display the GUI. $comObject = ObjCreate("DeviareCOM.NktSpyMgr") ; Create an COM object to access the Deviare interface $comObject.Initialize $eventObject=ObjEvent($comObject,"Deviare2_","DNktSpyMgrEvents") ; events from comObject are now passed to eventObject I recieve the following error when I try to run the code (Image attached) it says: Line 32 $comObject.initialize $comObject^ ERROR Error: Variable must be of type "Object" How on earth do I fix this? I tried downgrading to the previous version of autoIT but no luck :(
Danp2 Posted September 6, 2020 Posted September 6, 2020 Check the value of @error following the call to ObjCreate. Most likely this command is failing due to a missing / unregistered DLL. Latest Webdriver UDF Release Webdriver Wiki FAQs
mlw19mlw91 Posted September 6, 2020 Author Posted September 6, 2020 ok manually registered every .dll that I could from t he autoit3 installation. I did not go into the .lib files although I explored them with 7zip and saw a bunch of .dll's. Two dll's failed to register, I believe they were: "C:\Program Files (x86)\AutoIt3\AutoItX\AutoItX3.PowerShell.dll" and "C:\Program Files (x86)\AutoIt3\AutoItX\AutoItX3.Assembly.dll" Not sure what's going on ? the arduino connected to the com port is not being used by any other program
mlw19mlw91 Posted September 6, 2020 Author Posted September 6, 2020 ^ I should have mentioned that the error happens even before the slection of any COM port, the script just doesn't run at all
Developers Jos Posted September 6, 2020 Developers Posted September 6, 2020 You really need to add the "COM Error Handling" and do some proper error checking in your script. See helpfile for detailed info. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
mlw19mlw91 Posted September 6, 2020 Author Posted September 6, 2020 ok when I add the full code from here at the beginning of my script: I end up with this: expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <GuiComboBox.au3> #include "CommInterface.au3" #include <Timers.au3> $arm = 0 ; variable to coordinate between scan button and Deviare callback $numberOfScans = 40 ; we stop after 40 $doScan = 0 ; used as a signal by Deviare callback, so that the GUI thread knows to run another scan $hGUI = GUICreate("DAVID Laserscanner 5 Turntable Automator",500,120) $x_coordinate = GUICtrlCreateInput("120", 220, 20, 90, 20, $ES_NUMBER ) $y_coordinate = GUICtrlCreateInput("300", 220, 45, 90, 20, $ES_NUMBER ) GUICtrlCreateLabel("X coordinate of Scan button in DAVID:", 20, 20+2) GUICtrlCreateLabel("Y coordinate of Scan button in DAVID:", 20, 50+2) GUICtrlCreateLabel("COM Port:", 20, 80+2) $comboBoxCOM = GUICtrlCreateCombo("", 220, 70, 90, 20) For $i = 1 To 100 $sVar = RegEnumVal("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM", $i) If @error <> 0 Then ExitLoop Local $sVar2 = RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM", $sVar) $isCom = StringInStr($sVar2,"COM") ; check for presence of the substring "COM" in the key if ($isCom <> 0) then GUICtrlSetData($comboBoxCOM,$sVar2) _GUICtrlComboBox_SetEditText($comboBoxCOM,$sVar2) EndIf Next Global $oGlobalCOMErrorHandler = ObjEvent("AutoIt.Error", "_ErrFuncGlobal") ; Global COM error handler Global $oIE = ObjCreate("InternetExplorer.Application") $oIE.xyz FunctionLocal() $oIE.xyz Exit Func FunctionLocal() Local $oLocalCOMErrorHandler = ObjEvent("AutoIt.Error", "_ErrFuncLocal") ; Local COM error handler $oIE.xyz EndFunc ; Global COM error handler Func _ErrFuncGlobal($oError) ; Do anything here. ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> Global COM error handler - COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_ErrFunc ; Local COM error handler Func _ErrFuncLocal($oError) ; Do anything here. ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> Local COM error handler - COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_ErrFunc Local $idScan = GUICtrlCreateButton("Scan", 350, 20, 100, 32) Local $idStop = GUICtrlCreateButton("Abort", 350, 57, 100, 32) GUISetState(@SW_SHOW, $hGUI) ; Display the GUI. $comObject = ObjCreate("DeviareCOM.NktSpyMgr") ; Create an COM object to access the Deviare interface $comObject.Initialize $eventObject=ObjEvent($comObject,"Deviare2_","DNktSpyMgrEvents") ; events from comObject are now passed to eventObject While 1 ; Loop until the user exits. Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idScan $numberOfScans = 0 Scan() Case $idStop $numberOfScans = 40 $doScan = 0 $arm = 0 EndSwitch $position = MouseGetPos () ; read current mouse position Tooltip ($position[0] & ", " & $position[1]) ; make a tool tip displaying current mouse position Sleep (50) ; limit the CPU load by restricting the number of GUIGetMsg calls per second if $doScan = 1 Then $doScan = 0 Scan() EndIf WEnd Func Scan () $numberOfScans = $numberOfScans + 1 $str = GUICtrlRead($comboBoxCOM) ; get value of COM port from ComboBox $ret = StringRegExp($str, '\d+', 1) ; strip the 'COM' from the string Local $iPort = $ret[0] Local $iBaud = 9600 Local $iParity = 0 Local $iByteSize = 8 Local $iStopBits = 0 ; note: some hardware does not support 1.5 stop bits. ; it is tempting to write 1 for stop bits but: ; ONESTOPBIT 0 1 stop bit. ; ONE5STOPBITS 1 1.5 stop bits. ; TWOSTOPBITS 2 2 stop bits. Local $sCommand = "2" & @CRLF Local $hFile = _CommAPI_OpenCOMPort($iPort, 9600, $iParity, $iByteSize, $iStopBits) If $hFile = 0 Then MsgBox(64, "Error in _CommAPI_OpenCOMPort" & @error, _WinAPI_GetLastErrorMessage()) Else _CommAPI_ClearCommError($hFile) If @error Then MsgBox(32, "Error in _CommAPI_ClearCommError" & @error, _WinAPI_GetLastErrorMessage()) EndIf _CommAPI_PurgeComm($hFile) If @error Then MsgBox(32, "Error in _CommAPI_PurgeComm" & @error, _WinAPI_GetLastErrorMessage()) EndIf _CommAPI_TransmitString($hFile, $sCommand) If @error Then MsgBox(32, "Error in _CommAPI_TransmitString" & @error, _WinAPI_GetLastErrorMessage()) EndIf Local $sResult = _CommAPI_ReceiveString($hFile, 5000) If @error Then Switch @error Case 0 MsgBox(64, "Result5", SetError(@error, @ScriptLineNumber)) Case -1 MsgBox(32, "Error5", _WinAPI_GetLastErrorMessage()) Case -2 MsgBox(32, "Timeout5", SetError(@error, @ScriptLineNumber)) Case Else MsgBox(32, "Error5", "Error " & @error & " in line " & $sResult) EndSwitch EndIf _CommAPI_ClosePort($hFile) If @error Then Switch @error Case 0 MsgBox(64, "Result6", SetError(@error, @ScriptLineNumber)) Case -1 MsgBox(32, "Error6", _WinAPI_GetLastErrorMessage()) Case -2 MsgBox(32, "Timeout6", SetError(@error, @ScriptLineNumber)) Case Else MsgBox(32, "Error6", "Error " & @error & " in line " & $sResult) EndSwitch EndIf EndIf Sleep (3000) ; now that we sent a turn command, lets wait a moment to give the table time to settle ; also, on slower computers it sometimes takes a little longer before the scan button is enabled again MouseClick($MOUSE_CLICK_LEFT, GUICtrlRead($x_coordinate), GUICtrlRead($y_coordinate), 1) Sleep (2000) ; David acts the same at the beginning and the end of the scan. wait before arming the callback $arm = 1 ; arm the callback EndFunc Volatile Func Deviare2_OnProcessStarted($process) ; for reference on the proc object: http://www.nektra.com/products/deviare-api-hook-windows/doc-v2/interface_i_nkt_process.html if ($process.Name == "HP3DScan5.exe") then $hook = $comObject.CreateHook("kernel32.dll!CreateFileW", 0) $hook.Attach($process, True) $hook.Hook() EndIf EndFunc Volatile Func Deviare2_OnFunctionCalled($hook, $process, $callInfo) $Params = $callInfo.Params ; get the params member of the callInfo structure $First = $Params.First ; get the first parameter passed to CreateFile $present = StringInStr($First.value,"font") ; check for presence of the substring "font" in the parameter. if ($present <> 0) then if $arm = 1 Then ; we are waiting for the end of a scan and have reached it $arm = 0 if $numberOfScans < 40 Then ConsoleWrite ( $Params.First.name & $Params.First.value & @CRLF ) $doScan = 1 ;signal GUI to scan EndIf EndIf EndIf EndFunc ; User's COM error function. Will be called if COM error occurs ; from https://www.autoitscript.com/forum/topic/134615-the-requested-action-with-this-object-has-failed/ $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Initialize a COM error handler Func MyErrFunc() Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & hex($oMyError.number,8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) Endfunc Now I do not get an error message, but the program does not open at all, I just get the spinning wheel for 1 second then two flashes of the spinning wheel
Developers Jos Posted September 6, 2020 Developers Posted September 6, 2020 (edited) Try running the source from SciTE with F5 and see what is happening and whether that tells you something more as there are consolewrite() statements there that probably go nowhere now when it is compiled. I don't have that none-standard #include "CommInterface.au3", so can really test the code. Edited September 6, 2020 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Danp2 Posted September 6, 2020 Posted September 6, 2020 28 minutes ago, mlw19mlw91 said: ok manually registered every .dll that I could from t he autoit3 installation Actually, I was referring to the DLL associated with "DeviareCOM.NktSpyMgr", not the Autoit DLLs. 😃 Latest Webdriver UDF Release Webdriver Wiki FAQs
mlw19mlw91 Posted September 6, 2020 Author Posted September 6, 2020 ok I installed the DAVAIR package (I think the one you suggest, it sais "Devair2-master.zip" I get the following from the console? >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /test /run /prod /ErrorStdOut /in "C:\Users\micha\Downloads\3D Scanner Turntable for DAVID5 (now HP 3D Scan)-20200906T135842Z-001\3D Scanner Turntable for DAVID5 (now HP 3D Scan)\David5 Table.au3" /UserParams +>11:46:00 Starting AutoIt3Wrapper (19.1127.1402.0} from:SciTE.exe (4.2.0.0) Keyboard:00000409 OS:WIN_10/ CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\micha\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\micha\AppData\Local\AutoIt v3\SciTE - *** Compile in Test mode skipping Tidy; Au3Stripper; Resource updating and Versioning to speed up the process. *** >Running AU3Check (3.3.14.5) from:C:\Program Files (x86)\AutoIt3 input:C:\Users\micha\Downloads\3D Scanner Turntable for DAVID5 (now HP 3D Scan)-20200906T135842Z-001\3D Scanner Turntable for DAVID5 (now HP 3D Scan)\David5 Table.au3 "C:\Users\micha\Downloads\3D Scanner Turntable for DAVID5 (now HP 3D Scan)-20200906T135842Z-001\3D Scanner Turntable for DAVID5 (now HP 3D Scan)\David5 Table.au3"(2,124) : error: syntax error (illegal character) MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & '#include' & @CRLF & @CRLF & 'Return:' & @CRLF & # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ "C:\Users\micha\Downloads\3D Scanner Turntable for DAVID5 (now HP 3D Scan)-20200906T135842Z-001\3D Scanner Turntable for DAVID5 (now HP 3D Scan)\David5 Table.au3"(4,68) : error: syntax error (illegal character) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : #include = ' & # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Users\micha\Downloads\3D Scanner Turntable for DAVID5 (now HP 3D Scan)-20200906T135842Z-001\3D Scanner Turntable for DAVID5 (now HP 3D Scan)\David5 Table.au3 - 2 error(s), 0 warning(s) !>11:46:00 AU3Check ended. Press F4 to jump to next error.rc:2 +>11:46:00 AutoIt3Wrapper Finished. >Exit code: 2 Time: 1.456 before installing I got some different error code I can't remember because I lost it
mlw19mlw91 Posted September 6, 2020 Author Posted September 6, 2020 ^OOPS! sorry I only got the .DLL's from the devair thing I didn't "install" it. Are the DLL's sufficient?
mlw19mlw91 Posted September 6, 2020 Author Posted September 6, 2020 ALso I get the following pop up message box when I run the script outside of the editor: Debug line ~2 Section: include Return: include
mlw19mlw91 Posted September 6, 2020 Author Posted September 6, 2020 gosh sorry for all of the posts I also get this error message after I close the initial debug window (see attached)
mLipok Posted September 6, 2020 Posted September 6, 2020 (edited) https://sites.google.com/site/janbeck/interception-of-win32-and-user-dll-api-calls-using-autoit-and-deviare https://github.com/nektra/Deviare2/releases https://www.nektra.com/products/deviare-api-hook-windows/ Edited September 6, 2020 by mLipok Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24
Developers Jos Posted September 6, 2020 Developers Posted September 6, 2020 31 minutes ago, mlw19mlw91 said: gosh sorry for all of the posts I also get this error message after I close the initial debug window (see attached) So ....have you looked at the line which you are pointed to? Also install the Full SciTE4AutoIt3 installer so au3check will always ran for you doing initial basic syntax checking... and do not compile the script until it is done, but rather use F5 in SciTE! Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
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