Jump to content

Serial Port /COM Port UDF


martin
 Share

Recommended Posts

@imakidder, I am going to ask a really stupid question and assume you have already checked this out but... You ARE CLOSING "serial monitor" on the Arduino software before you run your autoit script right? Only one singe connection can be made to the serial port as far as I could tell, if my serial monitor was running, my arduino code would not work. You probably already checked this, but had to ask. Also is it possible that your script is not closing down therefore it's causing multiple attempts to connect to your serial port when you run it a second time and erroring out?

Edited by BatMan22
Link to comment
Share on other sites

AH. Definitely, not a stupid question. Actually I think both of those happened and a few times that is what prevented me from debugging the script. One reason I knew the serial monitor was a problem was because I couldn't see the com port properties under "mode" on CMD. When I closed out of the serial monitor, I could see the properties again. Plus I restarted my computer a few times just to refresh the system.

SOOO, I think I did figure it out. I realized on the link I posted. an error message popped up and  instead of printing the variable "COMPort", I was able to print the actual error code in the message box. Based on the comments Martin placed in the CommMg64.au3 code (Thank you for commenting with much detail!) I learned that the DLL files were not being referenced. In using the function _CommSetDllPath I set the right path and it seems to work fluidly. I think I broke my encoder so I wasn't able to get active data but it worked with the sample code I shared on the previous page!

@BatMan22 Thank you for the insight and the message!

@martin Thank you for some awesome code!

Link to comment
Share on other sites

  • 5 months later...

AFAICT the legacy serial (COMx:) support is limited to 256 kbaud and 300 kbaud is a non-standard baudrate.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • 3 months later...

Checking this UDF I've done a littel refactorizatoin of your code @martin

Hope changes will  be usefully.

 

COMMGvv2.zip

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 Codefor 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 APIErrorLog.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 TaskSchedulerIE 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 stuffOnHungApp handlerAvoid "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"
:naughty:  :ranting:, 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

Link to comment
Share on other sites

  • 2 weeks later...

 

On 7/10/2018 at 2:08 PM, adnadeau said:

Hi Martin,

Thanks for taking the time to redo your ,dll to 64 bit.  I've been switching over some of my scripts with mostly some success.  Here's what I have so far.

Here's what works so far in my scripts in 64 bit mode:
_CommGetVersion(1)
_CommSendString()
_CommGetInputCount()
_CommReadByteArray()
_CommSetPort()
_CommClosePort()
_CommListPorts(0)

Here's what doesn't work:
_CommGetString()

I haven't tried any other functions.

Your .zip file contains Commg64Example.exe; not the .au3 version.  I just got garbage with your .exe.

I took your original 32 bit Commg.au3 & changed it over, but it still returned garbage.   I tried another of my scripts which use _CommGetString() with same results.

I'm using a 64 bit laptop, Windows 7, & testing the scripts as .au3s

Alan

 

On 9/11/2018 at 12:02 AM, martin said:

Hello Adnadeau,

Apologies for the delay - I rarely visit the Autoit forums now.  Thanks for the feedback.

I will investigate what you have told me and I will correct the files in the zip. It might be a couple of weeks before I get back with something.

Martin

 

Hello Alan,

Hello Martin,

 

I read in old comments about x64-commg.dll, and found this useful hint, but couldn't find, if this problem is already solved. I used the x64-commg.dll for some years for AT-Commands to send SMS by GSM-Modem. Now i tried the same in a x64-AutoIT-application and get just '???' (questionmarks) when executing _CommGetString().

the code is like this:

_CommSendString('AT' & @CR, 1)
sleep(100)
_CommGetString()

So i used _CommGetString for kind of validating the commands before sending the next command. The output comes directly from the USB-GSM-Modem and shows OK or ERROR: xx". Since i'm trying to use the x64-commg.dll (commg.dll V2.79) the output are just '?' in different number, like Alan described in his post.

Exists already a fix for this issue or do i need to use a different _CommMG.au3 ? (I'm using CommMG.au3 V2.90)

 

Best regards and thank you very much,

Jeff

 

 

Link to comment
Share on other sites

@Danyfirex and I, we are working On ATCmd.au3 UDF. 

WILL BE FINISHED THIS MONTH.

 

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 Codefor 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 APIErrorLog.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 TaskSchedulerIE 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 stuffOnHungApp handlerAvoid "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"
:naughty:  :ranting:, 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

Link to comment
Share on other sites

15 hours ago, mLipok said:

@Danyfirex and I, we are working On ATCmd.au3 UDF. 

WILL BE FINISHED THIS MONTH.

 

Sounds nice,

Will it also support the x64-compiled AutoIT-Projects ?

If you need some Input, let me know, if it is based on commg.dll and _CommMG.au3. (For the x86-Version, i have really good stable functions)

Attached, you can find selfwritten _SMS.au3 

 

It is not totally commented yet and default country-code for SMS (if phone-number not starting by "00" or "+" is "+49" for germany.


Function-List:

_SIM_CheckModem($e_DebugConsol, $e_DLLFile, $e_COMPort)
_SIM_CheckSIMCard($e_DebugConsol, $e_DLLFile, $e_COMPort)
_SIM_CheckSIMCardPin($e_DebugConsol, $e_DLLFile, $e_COMPort, $e_SIMPin)
_SIM_SMSSend($e_DebugConsol, $e_DLLFile, $e_COMPort, $e_SIMPin, $e_SMSPhoneNo, $e_SMSMsg="", $e_SMSFlash=False, $e_SMSValid=145)

; BASE-Function
_fSIM($e_DebugConsol, $e_DLLFile, $e_ComPort, $e_SIMAction=0, $e_SIMPin="", $e_SMSPhoneNo="", $e_SMSMsg="", $e_SMSFlash=False ,$e_SMSValid=145)

 

Best regards,

Jeff

 

_SMS.au3

Link to comment
Share on other sites

Link to comment
Share on other sites

Thanks  @Danyfirex

sorry I mean, using this x64 dll, I can compile in AU3 , 32 bits, or just can compile in au3 x64. The Windows/PC are 64 bits.

 

I´m asking as with the old 32 bits dll, I only could compile in 32 bits. But with the 64, maybe due to other constrains, in some scripts I would have to use 32 bitx compilation.

Edited by joseLB
Link to comment
Share on other sites

Link to comment
Share on other sites

13 hours ago, joseLB said:

Thanks  @Danyfirex

sorry I mean, using this x64 dll, I can compile in AU3 , 32 bits, or just can compile in au3 x64. The Windows/PC are 64 bits.

 

I´m asking as with the old 32 bits dll, I only could compile in 32 bits. But with the 64, maybe due to other constrains, in some scripts I would have to use 32 bitx compilation.

 

On a x64 Windows you are able to compile Autoit-Scripts with x64 and x86.. and generally also run both versions. If you compile a Script with x64, the you need to use x64-DLL-files in your script, otherwise for x86-AutoIt-scripts you are using the x86-DLLs (e.g. commg.dll)

 

 

Link to comment
Share on other sites

In our solution we are using only: kernel32.dll

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 Codefor 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 APIErrorLog.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 TaskSchedulerIE 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 stuffOnHungApp handlerAvoid "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"
:naughty:  :ranting:, 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

Link to comment
Share on other sites

  • 2 years later...

It's my firts post in here so HELLO to everyone.

I have read down whole thread, but i cant figure out why my code not working:
 

_CommSwitch(12)
_Comm12()
;ConsoleWrite ("Com12:" & _CommPortConnection() &@CRLF)
_CommSendString("com 12 ok")
_CommSwitch(14)
_Comm14()
;ConsoleWrite ("Com14:" & _CommPortConnection() &@CRLF)
_CommSendString("com 14 ok")
_CommSwitch(12)
;ConsoleWrite ("Com12:" & _CommPortConnection() &@CRLF)
_CommSendString("com 12 ok 2")

_CommClosePort()

Func _Comm12()
    Local $sportSetError

    _CommSetDllPath("C:\Program Files (x86)\AutoIt3\Include\commg.dll")
    _CommSetPort(12, $sportSetError, 38400, 8, 0, 1, 2)

    If $sportSetError <> '' Then
      MsgBox(262144, 'Setport error: ', $sportSetError)
    EndIf
EndFunc


Func _Comm14()
    Local $sportSetError

    _CommSetDllPath("C:\Program Files (x86)\AutoIt3\Include\commg.dll")
    _CommSetPort(14, $sportSetError, 38400, 8, 0, 1, 2)

    If $sportSetError <> '' Then
      MsgBox(262144, 'Setport error: ', $sportSetError)
    EndIf
EndFunc

 The problem is that i get msgbox :

image.png.9bb4040ac6ea6cb6cc4f9a18981b5936.png

I am runing on Win10 X64 but using 32bit version of dll and CommMG.

Thank You for Your chelp.

cnc_war

Link to comment
Share on other sites

Hi all!

I'm use USB to RS485/RS422 Converter from HuMANDATA. This converter can reach baud rates 12Mbps and also support custom baud rate. 
Is it possible to use this device (actually high baud rate) in AutoIt?

Edited by RAMzor
Link to comment
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
 Share

×
×
  • Create New...