Jump to content
Sign in to follow this  
RichardL

MSComm object not created in a3x

Recommended Posts

Local $sAxName
Local $oMSComm

$sAxName = "MSCOMMLib.MSComm.1"
$oMSComm = ObjCreate($sAxName)
MsgBox(0, Default, StringFormat("Name: %s, Obj %d, Err %d", $sAxName, IsObj($oMSComm), @error))

I'm talking to serial ports (for Arduino) using the MSComm object.  It all runs fine from SciTE or .exe.  If I compile to .a3x the object is not created.  I could manage without .a3x but I like it because it compiles faster.
 

 

Share this post


Link to post
Share on other sites

Are you running the ax3 with the x86 or x64 AutoIt3.exe version? 
Might Want to play with that as that is the only reason I can think of that could case this.

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.
  :)

Share this post


Link to post
Share on other sites

Ah yes, I tend no to think of x86/x64.  The PC is W7-X64.  The x64 option makes it more complicated:

64.a3x - fail
64.exe - fail
86.a3x - fail
86.exe - good

I know the MSComm control is a VB6 item so may have issues with x64.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Exit
      Au3toCmd  ---  Avoid false positives
      Since many virus scanners sometimes prevent a "compiled autoit EXE" from being executed as "false positive", the "*.A3X" format is a suitable format to avoid this problem.
      In order to simplify this procedure, I wrote the Au3toCmd script. Here a *.Cmd file is generated from a *.Au3 file. The necessary files Autoit3.exe and *.A3x are added to the "*.Cmd" file as "alternate data streams".
      Now the Autoit Script can be called by clicking on the cmd file and the anti-virus scanners do not recognize the "false positive".
      If the short-term flashing of the CMD window bothers you, you can click the desktop shutcut that runs in a minimized window.
      Unfortunately, because of the "alternate data streams", this CMD file cannot be distributed via FTP or email.
      Only a USB stick or removable disk formatted with NTFS can be used.
      To solve this problem, Au3toCmd can be used to create a ZIP file that is email and FTP compatible.  Only possible on Win10 due to Powershell 5.0
      Expand this ZIP file on the target system and execute the "*.ADS.Run-me-first.cmd" script. The original CMD file is created again and the auxiliary files are deleted.
      Edit (2020.05.16)  The new version also accepts A3X and EXE files. This means that A3X and EXE files that have been compiled with special options can be used. As a side effect, other EXE files can also be included in the CMD file and therefore not detectable by virus scanners.
      Edit (2020.07.18)  Desktop shortcuts created automatically. Just delete them, if you don't like them.
      Edit (2020.07.22)  Using codepage 1252 
      Here the source of Au3toCmd.au3 
      This is a nice example of peaceful interaction between Autoit (*. au3), Dos (*. cmd), Powershell (*. ps1) and VSBasic (*. vbs)
      ;============================================================================================================== ; Script Name: Au3toCmd.au3 ; Description: Creates a CMD file from any AU3/A3X/EXE file. ; The CMD file will contain the compiled version (A3X) of the AU3 input file ; and the AUTOIT3.EXE file as alternate data streams. ; Alternativly it will contain any EXE file. ; This avoids the problem with the false positives of the virus scanners. ; To avoid the short-term flashing of the CMD window, a shortcut is created on the desktop ; that runs in a minimized window. ; ; Syntax: Au3toCmd (input-file) ; Default: none ; Parameter: Name of an AU3/A3X/EXE file (optional) ; Requirement(s): When using Zip feature: Powershell 5.0 or higher (Windows 10 is ok) ; Example: Au3toCmd testfile.au3 ; ; Author: Exit ( http://www.autoitscript.com/forum/user/45639-exit ) ; SourceCode: http://www.autoitscript.com/forum/index.php?showtopic=201562 Version: 2020.07.22 ; COPYLEFT: © 2020 Freeware by "Exit" ; ALL WRONGS RESERVED ;============================================================================================================== #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <File.au3> #include <String.au3> Global $rc, $sSourcepath, $sTargetpath, $sA3Dir, $aPathSplit, $sDrive, $sDir, $sFileName, $sExtension, $sIconPath = "", $iIconNumber = 0 Exit _Main() Func _Main() $sA3Dir = RegRead("HKLM\SOFTWARE\AutoIt V3\AutoIt", "InstallDir") If Not (FileExists($sA3Dir & "\autoit3.exe") And FileExists($sA3Dir & "\au3check.exe") And FileExists($sA3Dir & "\Aut2Exe\Aut2exe.exe")) Then Exit MsgBox(16 + 262144, Default, "Error: Autoit not installed on this system.", 0) _Sourcepath() _IconPath() $sTargetpath = $sDrive & $sDir & $sFileName & ".cmd" FileDelete($sTargetpath) FileDelete($sTargetpath & ".ADS.*") If Not FileWriteLine($sTargetpath, _ "@echo off & cd /D %~dp0 & cls" & @CRLF & _ "for /f ""delims="" %%F in ('dir /R %~nx0 ^| find /C ""$DATA"" ') do set mycount=%%F" & @CRLF & _ "if .%mycount% == .0 echo Invalid copy of %~nx0. No ADS found. & pause & goto :eof " & @CRLF & _ "if .%mycount% == .1 wmic process call create ""%~f0:prog %*"" " & @CRLF & _ "if .%mycount% == .2 wmic process call create ""%~f0:prog %~f0:a3x %*"" ") Then _ Return MsgBox(16 + 262144, Default, "Error: Cannot write to output file '" & $sTargetpath & "'", 0) Switch $sExtension Case ".au3" If ShellExecuteWait($sA3Dir & "\au3check.exe", ' -q "' & $sSourcepath & '"') Then _ Exit MsgBox(16 + 262144, Default, "Error: Input file """ & $sSourcepath & """ has Errors.", 0) ShellExecuteWait($sA3Dir & "\Aut2Exe\Aut2exe.exe", "/In " & $sSourcepath & " /out " & $sTargetpath & ":a3x") FileCopy($sA3Dir & "\Autoit3.exe", $sTargetpath & ":prog") Case ".a3x" FileCopy($sSourcepath, $sTargetpath & ":a3x") FileCopy($sA3Dir & "\Autoit3.exe", $sTargetpath & ":prog") Case ".exe" FileCopy($sSourcepath, $sTargetpath & ":prog") EndSwitch FileCreateShortcut($sTargetpath, @DesktopDir & "\" & $sFileName & ".lnk", $sDrive & $sDir, "", "", $sIconPath, "", $iIconNumber, 7) If MsgBox(4 + 32 + 256 + 262144, Default, $sTargetpath & " and " & @LF & @DesktopDir & "\" & $sFileName & ".lnk created." & @LF & @LF & "Create a portable ZIP file " & @LF & $sTargetpath & ".ADS.zip ?", 0) = 6 Then _CreateZip($sTargetpath) If MsgBox(4 + 32 + 256 + 262144, Default, "Run " & $sTargetpath & " ?", 0) = 6 Then ShellExecute(@DesktopDir & "\" & $sFileName & ".lnk") EndFunc ;==>_Main Func _CreateZip($sTargetpath) If RunWait(@ComSpec & " /c " & 'powershell Compress-Archive -?', "", @SW_HIDE) Then Return MsgBox(64 + 262144, Default, "Zip file cannot be created because the software ""Powershell 5.0"" is not available." & @CRLF & "Install Powershell 5.0 or higher and try again.", 0) Local $sRem = (StringRight($sSourcepath, 4) = ".exe") ? "rem " : "" FileDelete($sTargetpath & ".ADS.*") FileWriteLine($sTargetpath & ".ADS.Run-me-first.cmd", _ "@echo off" & @CRLF & _ "%~d0 & cd %~dp0" & @CRLF & _ "chcp 1252" & @CRLF & _ "set name1=%~n0" & @CRLF & _ "set name1=%name1:~0,-21%" & @CRLF & _ "set compare1=%cd% " & @CRLF & _ "set compare2=%compare1:AppData\Local\Temp=other% " & @CRLF & _ "if .%compare1%==.%compare2% goto :skip" & @CRLF & _ "echo off & cls " & @CRLF & _ "echo. " & @CRLF & _ "echo Please extract ALL files from ZIP file first and then run this CMD again. Press any key to exit." & @CRLF & _ "Pause > NUL: & goto :eof" & @CRLF & _ ":skip " & @CRLF & _ "rem echo on " & @CRLF & _ "ren %name1%.cmd.ADS.cmd %name1%.cmd" & @CRLF & _ $sRem & "type %name1%.cmd.ADS.a3x > %name1%.cmd:a3x" & @CRLF & _ $sRem & "del %name1%.cmd.ADS.a3x" & @CRLF & _ "type %name1%.cmd.ADS.prog > %name1%.cmd:prog" & @CRLF & _ "del %name1%.cmd.ADS.prog" & @CRLF & _ "move /Y %name1%.cmd .." & @CRLF & _ "cd .. " & @CRLF & _ "rem echo name1: ---%name1%--- ---%cd%--- ---%~dp0%---" & @CRLF & _ "move /Y %~dp0\%name1%.cmd.ADS.ico .\%name1%.ico" & @CRLF & _ "rem dir /R %name1%.* " & @CRLF & _ "rem pause " & @CRLF & _ 'echo Set oWS = WScript.CreateObject("WScript.Shell") > ~~.vbs' & @CRLF & _ 'echo Set oLink = oWS.CreateShortcut("%userprofile%\desktop\%name1%.lnk") >> ~~.vbs' & @CRLF & _ 'echo oLink.TargetPath = "%cd%\%name1%.cmd" >> ~~.vbs' & @CRLF & _ 'echo oLink.Arguments = "" >> ~~.vbs' & @CRLF & _ 'echo oLink.Description = "Invoke %name1%.cmd" >> ~~.vbs ' & @CRLF & _ 'echo oLink.HotKey = "" >> ~~.vbs' & @CRLF & _ 'echo oLink.IconLocation = "%cd%\%name1%.ico" >> ~~.vbs' & @CRLF & _ 'echo oLink.WindowStyle = "7" >> ~~.vbs' & @CRLF & _ 'echo oLink.WorkingDirectory = "" >> ~~.vbs' & @CRLF & _ 'echo oLink.Save >> ~~.vbs' & @CRLF & _ 'cscript ~~.vbs >NUL: ' & @CRLF & _ 'del ~~.vbs ' & @CRLF & _ "rem pause " & @CRLF & _ "echo off & cls " & @CRLF & _ "echo. " & @CRLF & _ "@if not exist ""%userprofile%\desktop\%name1%.lnk"" echo ""%userprofile%\desktop\%name1%.lnk"" not created due to pathname with special characters. " & @CRLF & _ "@if exist ""%userprofile%\desktop\%name1%.lnk"" echo ""%userprofile%\desktop\%name1%.lnk"" created. " & @CRLF & _ "@if not exist ""%cd%\%name1%.cmd"" echo ""%userprofile%\desktop\%name1%.lnk"" not created due to pathname with special characters. " & @CRLF & _ "@if exist ""%cd%\%name1%.cmd"" echo ""%cd%\%name1%.cmd"" created. " & @CRLF & _ "echo. " & @CRLF & _ "echo. " & @CRLF & _ "echo Press any key to terminate." & @CRLF & _ "Pause > NUL: " & @CRLF & _ "del .\%name1%.cmd.ADS.zip" & @CRLF & _ "rd /S /Q %name1%.cmd.ADS " & @CRLF & _ "rem End of script" & @CRLF) If Not $sRem Then FileWrite($sTargetpath & ".ADS.a3x", FileRead($sTargetpath & ":a3x")) FileWrite($sTargetpath & ".ADS.cmd", FileRead($sTargetpath)) FileWrite($sTargetpath & ".ADS.prog", FileRead($sTargetpath & ":prog")) If $sExtension = ".exe" Then _CreateIconfile() Else FileWrite($sTargetpath & ".ADS.ico", FileRead($sIconPath)) EndIf ShellExecuteWait("Powershell", "Compress-Archive -Path " & $sTargetpath & ".ADS.* -Update -DestinationPath " & $sTargetpath & ".ADS.zip", "", "open", @SW_HIDE) If Not FileExists($sTargetpath & ".ADS.zip") Then MsgBox(64 + 262144, Default, "Zip file cannot be created because authorisation problems.", 0) FileDelete($sTargetpath & ".ADS.a3x") FileDelete($sTargetpath & ".ADS.cmd") FileDelete($sTargetpath & ".ADS.prog") FileDelete($sTargetpath & ".ADS.ico") FileDelete($sTargetpath & ".ADS.Run-me-first.cmd") EndFunc ;==>_CreateZip Func _Sourcepath() If $cmdline[0] > 0 Then $sSourcepath = $cmdline[1] Select Case FileExists($sSourcepath) Case FileExists($sSourcepath & ".au3") $sSourcepath = $sSourcepath & ".au3" Case FileExists($sSourcepath & ".a3x") $sSourcepath = $sSourcepath & ".a3x" Case FileExists($sSourcepath & ".exe") $sSourcepath = $sSourcepath & ".exe" Case Else $sSourcepath = FileOpenDialog("Enter AU3/A3X/EXE Inputfile ", "", "Autoit Files(*.au3;*.a3x;*.exe)", 3) If @error Then Exit MsgBox(16 + 262144, Default, "Error: No Inputfile given", 0) EndSelect $sSourcepath = _PathFull($sSourcepath) $aPathSplit = _PathSplit($sSourcepath, $sDrive, $sDir, $sFileName, $sExtension) If DriveGetFileSystem($sDrive) <> "NTFS" Then Exit MsgBox(16 + 262144, Default, "Sorry: Input filesystem must be 'NTFS'", 0) If StringInStr($sSourcepath, " ") Then Exit MsgBox(16 + 262144, Default, "Sorry: Pathnames with embedded blanks not yet supported.", 0) FileChangeDir($sDrive & $sDir) EndFunc ;==>_Sourcepath Func _IconPath() $sIconPath = "" If FileExists($sDrive & $sDir & $sFileName & ".ico") Then $sIconPath = $sDrive & $sDir & $sFileName & ".ico" Local $aTemp = _StringBetween(FileRead($sSourcepath), "#", ".ico") If Not @error Then $aTemp = StringSplit($aTemp[0], "=, ") If FileExists($aTemp[$aTemp[0]] & ".ico") Then $sIconPath = $aTemp[$aTemp[0]] & ".ico" EndIf EndIf ;~ MsgBox(64 + 262144, Default, "$sIconPath: >" & $sIconPath & "<", 0) If FileExists($sDrive & $sDir & $sFileName & ".exe") Then $sIconPath = $sDrive & $sDir & $sFileName & ".exe" ;~ MsgBox(64 + 262144, Default, "$sIconPath: >" & $sIconPath & "<",0) EndFunc ;==>_IconPath Func _CreateIconfile() FileWriteLine($sTargetpath & ".ADS.ps1", _ '### Pause' & @CRLF & _ 'Function ExtractIcon' & @CRLF & _ '{Param([Parameter(Mandatory=$true)][string]$exe,[string]$ExtractPath)' & @CRLF & _ '$Filepath = (Get-ChildItem -Path $exe -Filter *.exe -ErrorAction SilentlyContinue) | Select -First 1' & @CRLF & _ '[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null' & @CRLF & _ '$baseName = [System.IO.Path]::GetFileNameWithoutExtension($Filepath.FullName)' & @CRLF & _ 'Write-Progress "Extracting Icon" $baseName' & @CRLF & _ '[System.Drawing.Icon]::ExtractAssociatedIcon($Filepath.FullName).ToBitmap().Save("$ExtractPath.png")' & @CRLF & _ '$b = [System.Drawing.Bitmap]::FromFile("$ExtractPath.png")' & @CRLF & _ '$icon = [System.Drawing.Icon]::FromHandle($b.GetHicon())' & @CRLF & _ '$file = New-Object System.IO.FileStream("$ExtractPath", "OpenOrCreate")' & @CRLF & _ '$icon.Save($file);$file.Close();$icon.Dispose()}' & @CRLF & _ 'ExtractIcon -exe "' & $sSourcepath & '" -Extractpath "' & $sTargetpath & '.ADS.ico"' & @CRLF & _ '### Pause' & @CRLF) RunWait(@ComSpec & " /c " & "Powershell -ExecutionPolicy Bypass " & $sTargetpath & ".ADS.ps1", @SW_HIDE) FileDelete($sTargetpath & ".ADS.ps1") FileDelete($sTargetpath & ".ADS.ico.png") EndFunc ;==>_CreateIconfile ; End of Au3toCmd.au3 script The script can be called with a file name of an AU3 script as a parameter.
      If no name is entered, a query is made.
      Suggestions for improvement and bug reports are welcome.
    • By Inpho
      Hi All,
      I didn't know where to put this; my apologies if this is the wrong location.
      When you plug a Samsung mobile device (phone, tablet, etc.) into the USB of a Windows PC, you can right-click the device in My Computer and select Properties. Here, it will show you the correct serial number of the device. Clearly Windows doesn't use adb to get the SN so I'm stuck at how to get the SN without adb and where the device doesn't have a drive letter assigned to it.
      When I last picked this up, I tried seemingly everything I could from wmi(?) and winmgmts(?) but either it's hidden cloak-and-dagger style or I can't see the forest for the trees...
      Does anyone know what API Windows uses when getting the serial number of a device Windows calls a Portable Media Player?

    • By jantograaf
      Hi all,
      I'm trying to write a script that connects with a VBA/COM API to get the status of a connected phone. I've been looking up and down this forum for tips or other user's experiences, but I can't seem to find anything (even remotely) similar. It shouldn't be so hard to do, however.
      Software I'm trying to connect to
      I'm trying to integrate CallCenter by using their API, which is documented over here : JustRemotePhone API Reference
      Things I've tried
      I've tried using ObjCreate but I don't get any result, it always returns the same (negative) error.
      #Version 1 tried ObjCreate("JustRemotePhone.RemotePhoneService") #Version 2 tried ObjCreate("JustRemotePhoneCOM.RemotePhoneService") #Version 3 tried ObjCreate("JustRemotePhoneCOM.RemotePhoneService.Application") None of the three versions I tried seem to deliver any result other than a negative error value which basically says that the given class is not valid.
      I am starting to get the hang of AutoIt by now, but unmanaged programming languages and object-oriented stuff is still quite a grey zone for me. If anyone could help me 'talk' to this application, I'd be immensely grateful!
      Thanks in advance and kind regards from Belgium!
       
      Jan
    • By mikered82
      Hello!
      Could someone help me please with a UDF/library/example to communicate with Arduino thru USB using V-USB Driver (HID Device).
      I want to implement remote control for PC (TV Tuner remote). Arduino would read and decode data from an IR Sensor then send the decoded data to the PC thru USB.
      Thanks! Any help much appreciated!!
    • By MazeM
      Hi
      here's another UDF for the serial port. It is very similar to CommAPI using kernel32.dll, but all code is packed into a single file without any dependencies, not even using WinAPI.au3. It differs from existing UDF that it doesn't allow a timeout when reading, instead it always returns immediately, either with the requested amount ob bytes read or with a failure status. And of course there is a function provided to query the amount of available bytes in the receive buffer. The reason behind this design decision: You can do 1000 other things in the main loop while checking from time to time if enough data bytes arrived. There's no point to block the program waiting for the serial port.
      It is currently a work-in-progress, as I didn't test all functions yet. The code was developed and tested on Windows 7 64 bit.  The ComUDF-Tests.au3 shows some tests and basic usage of the UDF. Maybe there's no reason to use this UDF, given the existence of the others UDFs, but I did it to get to know DllCall better - I use structs no only to pass but also to get data back (I don't use the array returned by DllCall to read that data, unless required). You're welcome to test it on older and newer Windows versions.
      Here's a list of the implemented functions:
      ; _ComListPorts ; _ComOpenPort ; _ComSetTimeouts ; _ComClosePort ; ; _ComSetBreak ; _ComClearBreak ; _ComGetInputcount ; _ComGetOutputcount ; _ComClearOutputBuffer ; _ComClearInputBuffer ; ; _ComSendByte ; _ComReadByte ; _ComSendBinary ; _ComReadBinary ; ; _ComSendChar ; _ComReadChar ; _ComSendCharArray ; _ComReadCharArray ; _ComSendString ; _ComReadString ; ; __ComClearCommError ; __PurgeComm Maze
       
      ComUDF.au3
      ComUDF-Tests.au3
×
×
  • Create New...