Leaderboard
Popular Content
Showing content with the highest reputation on 09/15/2017 in all areas
-
Although serial ports are disappearing, they can still be useful. Here is a COMMs UDF. It provides an easy way to use serial ports without the restrictions and problems some methods have. USB to serial is ok, binary data is ok. This UDF requires my comMG.dll which can be in either the script folder or the Windows folder by default, or in the path specified using the function _CommSetDllPath. Note the following shortcomings: the dll link below is 32 bit so it will not work with a 64 bit apps, but there is a 64 bit version in my post around 25th March 2018 for people to try. The strings and character functions are all AnsiChar. Functions in the UDF are _CommVersion _CommListPorts _CommSetPort _CommPortConnection _CommClearOutputBuffer _CommClearInputBuffer _CommGetInputcount _CommGetOutputcount _CommSendString _CommGetString _CommGetLine _CommReadByte _CommReadChar _CommSendByte _CommSendBreak; not tested!!!!!!!!!! _CommCloseport _CommSwitch _CommReadByteArray _CommSendByteArray _CommsetTimeouts _CommSetXonXoffProperties _CommSetRTS (NB these will not work if Hardware handshaking is selected because _CommSetDTR then these lines are controlled by the data being sent.) _CommSetDllPath _CommGetLineStates -------------------------------------------------------------------------------------------------------------------------------- Go to Download Page For Commgv2 Download includes the dll and udf. Most recent changes 28th March 2014 - dll V2.83 Correct error setting 6 data bits as 7. 11th March 2014 dll V2.82 Allow data bits of 4 to 8 instead of only 7 and 8. 19th August 2013 dll v2.81 removes some unwanted eroor message popups. Might not remove popups for some Windows versions. 27th September 2012 Correct error closing port. New version of UDF if V2.90, new dll is commg.dll V2.79. Thanks to tfabris. 18th January 2012 Corrected typo in UDF V 2.87, and uploaded as V2.88 Increased max baud allowed by the dll from 200000 to 256000. New version now V2.78 17th January 2012 Modified thesleep addition to _CommGetLine so that reading data is not slowed down. 14th January 2012 Corrected _CommReadByte in UDF. Added sleep(20) to while loop in _CommGetLine to reduce CPU usage 20th December 2011 UDF version 2.86. - Changed function GetByte so it returned the error string given by the dll. Dll version 2.77 - removed an unwanted erro message dialogue from GetByte function. (Thanks funkey) 4th December 2011 New dll and example versions. Dll function SetPort corrected because it was not using the parameters passed for DTR and RTS. The example was setting flow control incorrectly: the settings for hardware handshaking and XON./XOFF were reversed. 25th August 2011 corrected function _CommClosePort. Example corrected for setting parity and flow 22nd December 2013 (thanks to MichaelXMike) mgrefcommg CommgExample.au31 point
-
Error handling in For loop
prasadstudy reacted to BrewManNH for a topic
Get rid of the line $i=$i-1. You're resetting the loop counter variable, so it will never get to the end.1 point -
Is this referring to the recent Harvey flooding in Houston or did you mean the Apollo 13 astronaut stating "Houston, we have a problem" ? Either way, please use the standard text format in stead of using bold on all your text typed. Jos1 point
-
Added an additional bool to make it work: #include <Array.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 338, 438) $aRankingEdit = GUICtrlCreateEdit("", 32, 32, 225, 193) GUICtrlSetData(-1, "https://www.autoitscript.com/testurlsimilar" & @CRLF & _ "https://www.autoitscriptasdf.com/autoitscript2.com/autoitscriptasdf.com" & @CRLF & _ "https://www.autoitscript3.com/autoitscript.com" & @CRLF & _ "https://www.autoitscript4.com/autoitscript5.com/autoitscript.com" & @CRLF & _ "www.autoitscript3.com/asdf" & @CRLF & _ "http://www.autoitscript3.com/autoitscript.com" & @CRLF & _ "autoitscript3.com/asd.com" & @CRLF & _ "autoitscriptasdf.com") $Button1 = GUICtrlCreateButton("Button1", 96, 264, 75, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $bFound = False $aFindofrowsReadUrl = "https://www.autoitscript.com/test213213" Local $aUrlArrayFind2 = StringRegExp($aFindofrowsReadUrl, '(?i)(?m)^(?:https?:\/\/)?(?:www\.)?(\w[^\/]+)',1) Local $sitelisturl = StringSplit(StringStripCR(GUICtrlRead($aRankingEdit)), @LF) For $i = 1 To UBound($sitelisturl) - 1 $sitenamestr = StringRegExp($sitelisturl[$i], '(?i)(?m)^(?:https?:\/\/)?(?:www\.)?(\w[^\/]+)', 3) $sitenames = $sitenamestr[0] If StringInStr($sitenames, $aUrlArrayFind2[0]) Then $bFound = True ConsoleWrite($sitenames & " This site " & $i & "." & "ranking" & @CRLF) ExitLoop EndIf Next If Not $bFound Then MsgBox(0,"", $aUrlArrayFind2[0] & " Not in rankings") EndIf EndSwitch WEnd1 point
-
You'll not get anything faster than this: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 ;#AutoIt3Wrapper_UseX64=y #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <SQLite.au3> Opt( "MustDeclareVars", 1 ) Global $pTable, $iCols, $hLV Example() Func Example() _SQLite_Startup() _SQLite_Open( "random_data.db" ) Local $iRows Local $sSQL = "SELECT * FROM RandomData;" _SQLite_GetTableEx( -1, $sSQL, $pTable, $iRows, $iCols ) $pTable += $iCols * ( @AutoItX64 ? 8 : 4 ) GUICreate( "Virtual ListView", 1650, 800 ) Local $idLV = GUICtrlCreateListView( "", 10, 10, 1650-20, 800-20, $LVS_OWNERDATA, BitOR( $WS_EX_CLIENTEDGE, $LVS_EX_DOUBLEBUFFER, $LVS_EX_FULLROWSELECT ) ) $hLV = GUICtrlGetHandle( $idLV ) ; Virtual listview Reduces flicker For $i = 0 To $iCols - 1 _GUICtrlListView_AddColumn( $idLV, "Col" & $i, 160 ) Next GUICtrlSendMsg( $idLV, $LVM_SETITEMCOUNT, $iRows, 0 ) GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" ) GUISetState( @SW_SHOW ) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd $pTable -= $iCols * ( @AutoItX64 ? 8 : 4 ) _SQLite_FreeTable( $pTable ) _SQLite_Close() _SQLite_Shutdown() EndFunc Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam ) Static $iPtrSize = @AutoItX64 ? 8 : 4, $hDLL = DllOpen( "kernel32.dll" ), $aDisplay[100][$iCols], $iFrom, $iTo Static $tText = DllStructCreate( "wchar[4094]" ), $pText = DllStructGetPtr( $tText ) Static $tagNMLVCACHEHINT = $tagNMHDR & ";int iFrom;int iTo" Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate( $tagNMHDR, $lParam ) $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) ) $iCode = DllStructGetData( $tNMHDR, "Code" ) Switch $hWndFrom Case $hLV Switch $iCode Case $LVN_GETDISPINFOW Local $tNMLVDISPINFO = DllStructCreate( $tagNMLVDISPINFO, $lParam ) If Not BitAND( DllStructGetData( $tNMLVDISPINFO, "Mask" ), 1 ) Then Return ; 1 = $LVIF_TEXT Local $iItem = DllStructGetData( $tNMLVDISPINFO, "Item" ) - $iFrom If $iItem < 0 Or $iItem > $iTo - $iFrom Then Return Local $iSubItem = DllStructGetData($tNMLVDISPINFO,"SubItem") Local $sItem = $aDisplay[$iItem][$iSubItem] Local $l = StringLen( $sItem ) DllStructSetData( $tText, 1, $sItem ) DllStructSetData( $tNMLVDISPINFO, "Text", $pText ) DllStructSetData( $tNMLVDISPINFO, "TextMax", ( $l <= 4094 ? $l : 4094 ) ) Return Case $LVN_ODCACHEHINT Local $tNMLVCACHEHINT = DllStructCreate( $tagNMLVCACHEHINT, $lParam ) $iFrom = DllStructGetData( $tNMLVCACHEHINT, "iFrom" ) $iTo = DllStructGetData( $tNMLVCACHEHINT, "iTo" ) Local $pFrom, $pStr, $iLen, $tWstr For $i = $iFrom To $iTo $pFrom = $pTable + $i * $iCols * $iPtrSize For $j = 0 To $iCols - 1 $pStr = DllStructGetData( DllStructCreate( "ptr", $pFrom + $j * $iPtrSize ), 1 ) $iLen = DllCall( $hDLL, "int", "MultiByteToWideChar", "uint", 65001, "dword", 0, "ptr", $pStr, "int", -1, "ptr", 0, "int", 0 )[0] $tWstr = DllStructCreate( "wchar[" & $iLen & "]" ) DllCall( $hDLL, "int", "MultiByteToWideChar", "uint", 65001, "dword", 0, "ptr", $pStr, "int", -1, "struct*", $tWstr, "int", $iLen ) $aDisplay[$i-$iFrom][$j] = DllStructGetData( $tWstr, 1 ) Next Next Return EndSwitch EndSwitch Return $GUI_RUNDEFMSG #forceref $hWnd, $iMsg, $wParam EndFunc Func _SQLite_GetTableEx( $hDB, $sSQL, ByRef $pTable, ByRef $iRows, ByRef $iCols ) If __SQLite_hChk($hDB, 2) Then Return SetError(@error, 0, $SQLITE_MISUSE) Local $tSQL8 = __SQLite_StringToUtf8Struct($sSQL) If @error Then Return SetError(3, @error, 0) Local $avRval = DllCall($__g_hDll_SQLite, "int:cdecl", "sqlite3_get_table", _ "ptr", $hDB, _ ; An open database "struct*", $tSQL8, _ ; SQL to be executed "ptr*", 0, _ ; Results of the query "int*", 0, _ ; Number of result rows "int*", 0, _ ; Number of result columns "long*", 0) ; Error msg written here If @error Then Return SetError(1, @error, $SQLITE_MISUSE) ; DllCall error $pTable = $avRval[3] $iRows = $avRval[4] $iCols = $avRval[5] EndFunc Func _SQLite_FreeTable( $pTable ) DllCall($__g_hDll_SQLite, "int:cdecl", "sqlite3_free_table", "ptr", $pTable) If @error Then Return SetError(1, @error, $SQLITE_MISUSE) ; DllCall error EndFunc1 point
-
Hi Can you please check the following: Please download the Source package from my website and uzip it in a directory you want. Then delete the AutoIt_Studio_Helper.exe from the extraced folder. (So the ISN is forced to run the .au3 file) Then launch AutoIt_Studio.au3 and try again. If the error still appears, please post the error message again. It should now contain more debug infos for me... thx1 point
-
Need Help... Reading The Registry For Reboot Needs
MaxTrax reacted to Mike Caouette for a topic
In case anyone is interested... here is the final script: -Mike ; ---------------------------------------------------------------------------- ; ; AutoIt Version: reboot_needed_agent.au3 ; Author: Michael Caouette ; ; Script Function: ; This script reads 2 registry locations to see if reboots are pending ; due to patch installs. If the machine needs to be rebooted, it prompts ; the user with the option to reboot ; ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <GUIConstants.au3> Autoitsetoption ("TrayIconHide",1) ;------Read the first value to see if the machine has pending reboots $reboot_check1 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\UpdateExeVolatile", "Flags") ;0 -> no restart is pending ;1 -> a software update removal is pending a restart ;2 -> a software update installation is pending a restart ;3 -> Both install and removal are pending a restart ;------Read the second value to see if the machine has pending reboots SetError(0) $b_Value = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager", "PendingFileRenameOperations") If @error Then $reboot_check2 = 0 Else $reboot_check2 = 1 EndIf ;------If either check says that a reboot is needed, then prompt the user If $reboot_check1 <> 0 or $reboot_check2 == 1 Then ;Computer needs to be rebooted ;MsgBox(0, "Reboot Needed", "Pending a restart") $inst_win = GUICreate("Reboot Recommended", 300, 125,-1,-1,$WS_Caption) $go = GUICtrlCreateButton ("Reboot Now" , 30, 80, 75, 25) $quit = GUICtrlCreateButton ("Not at this time" , 150, 80, 100, 25) $message = GUICtrlCreateLabel("This computer has had updates installed,", 20,10) $message1 = GUICtrlCreateLabel("and needs to be rebooted", 20,30) $message2 = GUICtrlCreateLabel("Please take time to reboot your computer.", 20,50) GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit If $msg = $go Then Shutdown(6) If $msg = $quit Then ExitLoop WEnd GUIDelete($inst_win) Exit else ;Compueter does NOT need a reboot ;MsgBox(0, "Reboot Not Needed", "No restart needed") EndIf1 point