Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 07/02/2018 in all areas

  1. Hey guys, the code that I've written/borrowed below is mostly an example of using the commUDF listed at the bottom, just applied to an Arduino with accompanying Arduino code. Uses Serial communication to turn on a LED, then reads a response from the arduino and prints it in the console. I hope it helps Autoit Code: #include <CommMG.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $CMPort = 3 Global $CmBoBaud = 9600 Global $sportSetError = '' Global $CmboDataBits = 8 Global $CmBoParity = "none" Global $CmBoStop = 1 Global $setflow = 2 _CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow) If @error Then MsgBox(16, "Error!", "Can't connect to Arduino on port - " & $CMPort) Exit EndIf _CommSetRTS(0) _CommSetDTR(0) While 1 ; Just use to call function, doesn't need to be a loop. LED_ON() Sleep(100) LED_OFF() Sleep(100) WEnd Func LED_ON() _CommSendString("1") ;Sends the Arduino a string of "1" to turn on LED Local $ret = _CommGetLine(@CR, 100, 100) ; Waits for up to 100 for a carriage return response from Arduino. ConsoleWrite($ret & @CRLF) ;Print to Console. EndFunc ;==>LED_ON_OFF Func LED_OFF() _CommSendString("0") ;Sends Arduino string of "0" to turn off the LED Local $ret = _CommGetLine(@CR, 100, 100) ; Waits for up to 100 for a carriage return response from Arduino. ConsoleWrite($ret & @CRLF) ;Print to Console. EndFunc ;==>LED_BLINK_10 Arduino Code: int led = 12; void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(led, OUTPUT); } void loop() { // put your main code here, to run repeatedly: if (Serial.available()) { int data = Serial.read(); if (data == '1') //On { digitalWrite(led, HIGH); //writeslow(); Serial.print("The LED is on!"); } if (data == '0') //Off { digitalWrite(led, LOW); Serial.print("The LED is OFF!"); } } } Serial/Com port UDF this is all based on
    1 point
  2. dave12077

    Disable Controls

    I have seen several threads where others have asked about disabling controls, but not having them greyed out. The problem is disabling the control is greyed out due to default windows behavior. My work around for this was to create an array of the controls I would like to disable. Then i create small, borderless, guis, on top of each control, and disable the gui, that makes the control "unclickable ". The lock function returns an array with the handles to the guis created over each control, and to unlock the controls, delete the guis. There are probably other ways, probably better ways, I just wanted to share the way I got around this problem. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <WinAPISys.au3> #include <ComboConstants.au3> ; create enum values for index of array of controls we will want to disable Const Enum $__CTRL_FIRSTNAME, $__CTRL_LASTNAME, $__CTRL_EMAIL, $__CTRL_CBO, $__CTRL_CHECK, $__CTRL_RAD1, $__CTRL_RAD2, $__CTRL_NOTES, $__CTRL_COUNT ; create array for controls we will want to disable Local $aEditControls[$__CTRL_COUNT] ; build the gui Local $hGui = GUICreate("Test", 700, 400) Local $lblFirst = GUICtrlCreateLabel('First Name : ', 10, 10, 60, 20, $SS_RIGHT) $aEditControls[$__CTRL_FIRSTNAME] = GUICtrlCreateInput('', 80, 10, 250, 20) Local $lblLast = GUICtrlCreateLabel('Last Name : ', 360, 10, 60, 20, $SS_RIGHT) $aEditControls[$__CTRL_LASTNAME] = GUICtrlCreateInput('', 430, 10, 250, 20) Local $lblEmail = GUICtrlCreateLabel('Email : ', 10, 40, 60, 20, $SS_RIGHT) $aEditControls[$__CTRL_EMAIL] = GUICtrlCreateInput('', 80, 40, 250, 20) $aEditControls[$__CTRL_CBO] = GUICtrlCreateCombo("", 430, 40, 80, 20, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "Item1|Item2|Item3") $aEditControls[$__CTRL_CHECK] = GUICtrlCreateCheckbox("Locked", 550, 40, 120, 20) $aEditControls[$__CTRL_RAD1] = GUICtrlCreateRadio("Radio1", 430, 70, 100, 25) $aEditControls[$__CTRL_RAD2] = GUICtrlCreateRadio("Radio2", 550, 70, 100, 25) Local $lblAddress = GUICtrlCreateLabel('Notes : ', 10, 100, 60, 20, $SS_RIGHT) $aEditControls[$__CTRL_NOTES] = GUICtrlCreateEdit('', 80, 100, 600, 100) Local $cmdLock = GUICtrlCreateButton('Lock Controls', 80, 220, 90, 30) Local $cmdUnlock = GUICtrlCreateButton('Unlock Controls', 590, 220, 90, 30) GUISetState(@SW_SHOW) Local $nMsg Local $aLockedCtrls[0] While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _UnlockControls($aLockedCtrls) Exit Case $cmdLock $aLockedCtrls = _LockControls($aEditControls) Case $cmdUnlock _UnlockControls($aLockedCtrls) EndSwitch WEnd ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LockControls ; Description ...: Locks controls ; Syntax ........: _LockControls(Byref $aCtrls) ; Parameters ....: $aCtrls - array of controls to lock ; Return values .: an array of handles to the GUIs covering the controls ; =============================================================================================================================== Func _LockControls(ByRef $aCtrls) Local $aGuiHandles[UBound($aCtrls)] ; create array to hold gui Local $aSize[0] ; array for control position Local $hParent = 0 ; control parent Local $hWnd = 0 ; control handle For $i = 0 To UBound($aCtrls) - 1 $hWnd = GUICtrlGetHandle($aCtrls[$i]) If $hWnd <> 0 Then $hParent = _WinAPI_GetParent($hWnd) ; get size and position of the control $aSize = ControlGetPos($hParent, '', $aCtrls[$i]) ; create gui over the control $aGuiHandles[$i] = GUICreate('', $aSize[2], $aSize[3], $aSize[0], $aSize[1], $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) _WinAPI_SetParent($aGuiHandles[$i], $hParent) GUISetState(@SW_SHOW, $aGuiHandles[$i]) GUISetState(@SW_DISABLE, $aGuiHandles[$i]) EndIf Next WinActivate($hParent) Return $aGuiHandles EndFunc ;==>_LockControls ; #FUNCTION# ==================================================================================================================== ; Name ..........: _UnlockControls ; Description ...: unlocks controls previously locked ; Syntax ........: _UnlockControls(ByRef $aLockedGuis) ; Parameters ....: $aLockedGuis - array of of gui handles that was used to lock the controls [returned from _LockControls()] ; Return values .: none ; =============================================================================================================================== Func _UnlockControls(ByRef $aLockedGuis) ; lock parent window to prevent flashing GUISetState(@SW_LOCK, _WinAPI_GetParent($aLockedGuis[0])) ; delete the guis For $i = 0 To UBound($aLockedGuis) - 1 GUIDelete($aLockedGuis[$i]) Next ; unlock parent window GUISetState(@SW_UNLOCK, _WinAPI_GetParent($aLockedGuis[0])) EndFunc ;==>_UnlockControls
    1 point
  3. Hello. You also could do this. Local $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='DropDown']/option","",True) ;~ _ArrayDisplay($aElements) For $i=0 to UBound($aElements)-1 ConsoleWrite(_WD_ElementAction($sSession, $aElements[$i], 'text') & @CRLF) ConsoleWrite(_WD_ElementAction($sSession,$aElements[$i], 'attribute', 'value') & @CRLF) Next Saludos
    1 point
  4. To be able to pass an AutoIt array to C# or VB.NET the C#/VB variable to receive the array must be an array of objects. An AutoIt array is an array of variants (a safearray). The corresponding C#/VB variable is an array of objects. I think that's all.
    1 point
  5. The zip-file contains two small dll-files used in this post above (C++ code near bottom of the post, 10 lines). I'm using Avira and it doesn't detect any viruses. You can delete the dll-files and recreate them with Visual Studio. C++ code in the zip-file.
    1 point
  6. @Earthshine I think your AV software is acting up or reporting a false postive.
    1 point
  7. Look also in this thread
    1 point
  8. Here a example using GUICtrlCreateTreeView and some functions of GuiTreeView.au3:
    1 point
×
×
  • Create New...