Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 09/21/2020 in all areas

  1. In the moment there are two UDF's for serial communication: >Serial Port / COM Port UDF (needs comMG.dll) >Serial Communication using kernel32.dll The first UDF is very popular, but it has the disadvantage, that an unknown DLL needs to be used. The second UDF use the Windows API, but it has much less features. So, I decided to create an another UDF for my requirements. You can find the result here: http://www.autoitscript.com/wiki/CommAPI It is a further development of the second UDF and has (almost) all functions of the first UDF. Feel free to fix any existing bugs and to extend it with additional functions.
    1 point
  2. Hi abberration It freezes/crash because you spend too long time inside Func WM_COMMAND() Help file GUIRegisterMsg : Warning: blocking of running user functions which executes window messages with commands such as "MsgBox()" can lead to unexpected behavior, the return to the system should be as fast as possible !!! _ArrayDisplay() takes some time to display its content, and as it's (indirectly) called from WM_COMMAND() ... also _FileListToArrayRec() takes time too. A solution (successfully tested) is to move code from WM_COMMAND to While... Wend loop, by modifying this part of code : ... Global $text, $arrPos, $bButton_Clicked = False While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_NONE If $bButton_Clicked Then _OrganizeFolder($arrWinList[$arrPos][1]) $bButton_Clicked = False EndIf Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) ; if button is clicked, give popup confirming it. ;_ArrayDisplay($arrWinList) ; once a button is pressed, _arraydisplay locks up Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit $hWndFrom = $ilParam $iIDFrom = _WinAPI_LoWord($iwParam) $iCode = _WinAPI_HiWord($iwParam) If $iCode = $BN_CLICKED Then $text = _GUICtrlButton_GetText ( $hWndFrom ) $arrPos = _ArraySearch($arrWinList, $text) ; _OrganizeFolder($arrWinList[$arrPos][1]) ; <======== commented $bButton_Clicked = True ; <======== a flag, read within While... Wend loop EndIf EndFunc ... That's the 2nd time I use $GUI_EVENT_NONE (first time was a couple of days ago), seems to work fine
    1 point
  3. The response's data type is "application/x-www-form-urlencoded".
    1 point
  4. So... just skip this line $_lv_sRslt = StringRegExpReplace($_lv_sData, "(?m)^.+:=.+;.*(*SKIP)(*F)|//\V+", "")
    1 point
  5. There are several ways to do that. The easiest one is to create the 2 gui and show/hide them on demand, this makes it simple to assign a function to a control as needed by the event mode Example below - but please remember that the help file and the wiki are your best friends #include <GuiConstants.au3> Opt("GUIOnEventMode", 1) $GUI = GUICreate("Test GUI",400,100,-1,-1,BitOR($WS_POPUP, $WS_DLGFRAME, $WS_EX_TOPMOST), 0) WinSetOnTop ($GUI, "",1) $UNLOCK_BITLOCKER = GUICtrlCreateButton("Unlock BitLocker", 20, 20, 200, 25) GUICtrlSetOnEvent($UNLOCK_BITLOCKER,"UNLOCK_BITLOCKER_FUNCTION") GUISetState(@SW_SHOW) $test = GUICreate("Microsoft BitLocker",720, 165, -1,-1,BitOR($WS_DLGFRAME, $WS_EX_TOPMOST), 0) WinSetOnTop ("Microsoft BitLocker", "",1) GUICtrlCreateLabel("Please enter the BitLocker recovery key and then click on the OK button:",10,10,700,35) GUICtrlSetFont (-1,-1, 800) $BitLockerRecoveryKey = GUICtrlCreateInput("", 10, 50, 700, 35) $idBtn = GUICtrlCreateButton("OK", 10, 100, 160, 35) GUICtrlSetOnEvent($idBtn,"_testkey") GUISetState(@SW_HIDE) While 1 Sleep(1000) WEnd Func UNLOCK_BITLOCKER_FUNCTION() GUISetState(@SW_SHOW, $test) EndFunc Func _testkey() $BitLockerRecoveryKey2= GUICtrlRead($BitLockerRecoveryKey) $ReturnCode = RunWait("cmd.exe /c manage-bde -unlock c: -recoverypassword " & $BitLockerRecoveryKey2,"",@SW_HIDE) If $ReturnCode = "0" then MsgBox(262208,"Microsoft BitLocker","The BitLocker recovery volume is now unlocked.") GUIDelete("Microsoft BitLocker") Else MsgBox(262160,"Microsoft BitLocker","An invalid BitLocker recovery key was specified. Please try again.") GUISetState(@SW_HIDE, $test) EndIf EndFunc
    1 point
  6. Whatever way is the most suitable to use, this should always be done anyway, as it is THE best coding practice
    1 point
  7. Using UBound($Array) or $Array[0] is not a question of "better coding practice". It depends on how the array was created. Let's take a 1-Dim array as an example. In functions you can often specify the structure with a parameter, see $STR_NOCOUNT / $STR_COUNT. If the number of elements is specified in the [0] index, then use $Array[0]. If index [0] already contains the first data element then use UBound (simplified description). @Burgaud : This is important, e.g. when applying StringSplit to an empty string. IsArray() indicates Success, but @error does not. #include <Array.au3> Global $sStr, $aArr, $sDelimiter, $iAtError $sDelimiter = "," ; ---- string is empty ---- $sStr = "" $aArr = StringSplit($sStr, $sDelimiter) $iAtError = @error ConsoleWrite("> >> String = " & $sStr & @CRLF) ConsoleWrite(" >> @error = " & $iAtError & " (0=No Error , 1=Error)" & @CRLF) ConsoleWrite(" >> IsArray = " & IsArray($aArr) & " (1=Success , 0=Failure) " & @CRLF) ; ---- string is not empty ---- $sStr = "Have,a,nice,day" $aArr = StringSplit($sStr, $sDelimiter) $iAtError = @error ConsoleWrite("> >> String = " & $sStr & @CRLF) ConsoleWrite(" >> @error = " & $iAtError & " (0=No Error , 1=Error)" & @CRLF) ConsoleWrite(" >> IsArray = " & IsArray($aArr) & " (1=Success , 0=Failure) " & @CRLF)
    1 point
  8. Hi all, I got this code and would like to be able to change Baud Rate and instead of sending character by character i would like to be able (if possible) to send whole string. But i don't know how to change it. I am taking input from file and processing whole line (this is done in FilesHandling.au3). To execute this i am just calling SendData("FileName", int) in "main" script. Any help very appreciated. #include <WinAPI.au3> #include <Array.au3> #include "FilesHandling.au3" ;init DLL function, we need handle to call the function $h = DllCall("Kernel32.dll", "hwnd", "CreateFile", "str", "\\.\COM19", "int", BitOR($GENERIC_READ,$GENERIC_WRITE), "int", 0, "ptr", 0, "int", $OPEN_EXISTING, "int", $FILE_ATTRIBUTE_NORMAL, "int", 0) $handle=$h[0] Func SendData($FileName, $LineNumber) ;string to be send $c = readFile($FileName, $LineNumber) $cLenght = StringLen($c) $aArray = StringSplit($c, "") ;_ArrayDisplay($aArray, "", Default, 64) For $i = 1 To $cLenght writeChar($handle, $aArray[$i], $cLenght) Next ;move to next line writeChar($handle, @CR,1) EndFunc ;write a single char func writeChar($handle,$c,) $stString = DLLStructCreate("char str") $lpNumberOfBytesWritten = 0 DllStructSetData($stString, 1, $c) $res = _WinAPI_WriteFile($handle, DllStructGetPtr($stString, "str"), 1,$lpNumberOfBytesWritten) if ($res<>true) then ConsoleWrite ( _WinAPI_GetLastErrorMessage() & @LF) EndIf EndFunc
    1 point
  9. I posted a COM phone dialer a while back as an answer to another post. It used the MSComm component and I have since learned that many people will not have the MSComm ocx file on thier system (unless they once had VB6 installed). It is a royalty component and therefore cannot be redistributed. Fortunately, there is a freeware version created to be a full emulation of that control that you can download and install from HardAndSoftware. You'll find the download link here: NetComm Update: New Location Edit: Note, this needs the post 3.1.1 beta for COM support Here is the Microsoft MSComm example: ; Set a COM Error handler -- only one can be active at a time (see helpfile) $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $sNumberToDial = "5551212" Dial($sNumberToDial) Exit Func Dial($pNum, $time2wait = 5000) dim $FromModem = "" $DialString = "ATDT" & $pNum & ";" & @CR $com = ObjCreate ("MSCommLib.MSComm") With $com .CommPort = 3 .PortOpen = True .Settings = "9600,N,8,1" .InBufferCount = 0 .Output = $DialString EndWith $begin = TimerInit() While 1 If $com.InBufferCount Then $FromModem = $FromModem & $com.Input;* Check for "OK". If StringInStr($FromModem, "OK") Then;* Notify the user to pick up the phone. MsgBox(0, "Phone", "Please pick up the phone and either press Enter or click OK") ExitLoop EndIf EndIf If (TimerDiff($begin) > $time2wait) Then MsgBox(0, "Error", "No response from modem on COM" & $com.CommPort & " in " & $time2wait & " milliseconds") Exit EndIf WEnd $com.Output = "ATH" & @CR $com.PortOpen = False $com = 0 EndFunc;==>Dial Func MyErrFunc() ; Set @ERROR to 1 and return control to the program following the trapped error SetError(1) MsgBox(0, "Error", "Error communicating with modem on COM" );& $com.CommPort) Exit EndFunc;==>MyErrFunc Here is the freeware NETComm example: ; Set a COM Error handler -- only one can be active at a time (see helpfile) $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $sNumberToDial = "5551212" Dial($sNumberToDial) Exit Func Dial($pNum, $time2wait = 5000) dim $FromModem = "" $DialString = "ATDT" & $pNum & ";" & @CR $com = ObjCreate ("NETCommOCX.NETComm") With $com .CommPort = 3 .PortOpen = True .Settings = "9600,N,8,1" .InBufferCount = 0 .Output = $DialString EndWith $begin = TimerInit() While 1 If $com.InBufferCount Then $FromModem = $FromModem & $com.InputData;* Check for "OK". If StringInStr($FromModem, "OK") Then;* Notify the user to pick up the phone. MsgBox(0, "Phone", "Please pick up the phone and either press Enter or click OK") ExitLoop EndIf EndIf If (TimerDiff($begin) > $time2wait) Then MsgBox(0, "Error", "No response from modem on COM" & $com.CommPort & " in " & $time2wait & " milliseconds") Exit EndIf WEnd $com.Output = "ATH" & @CR $com.PortOpen = False $com = 0 EndFunc;==>Dial Func MyErrFunc() ; Set @ERROR to 1 and return control to the program following the trapped error SetError(1) MsgBox(0, "Error", "Error communicating with modem on COM" );& $com.CommPort) Exit EndFunc;==>MyErrFunc Enjoy, Dale Edit: Added note about need for AutoIt beta and link to it Edit2: Created seperate examples for MSComm and NETComm... NETComm uses the property .InputData instead of .Input -- thanks KenE!
    1 point
  10. Just add the Ascii code for Ctrl Z "AT+CMGS=123456789" & Chr(26) You can find that in any Ascii table, but the control codes are simply Ctl A = 1, Ctrl B = 2 ... Ctrl Z = 26
    1 point
×
×
  • Create New...