Jump to content

Recommended Posts

  • 2 months later...
Posted

Hi, yes you can!

File: CommUtilities.au3

Func: _CommAPI_CreateModeString

String: Case 11 To 256000

Change 256000 value to 3000000

Its works! But no more 3000000 baud.

  • 10 months later...
Posted (edited)

So far this works with the latest Windows 10 (1909)

Does anyone know if this UDF supports reading a Comport that is already open by another program? I have seen references to it on the internet when you can eavesdrop on a serial port that is already open. Is this doable with this UDF?  

Anther thing I am struggling with are the return codes. I call _CommAPI_OpenCOMPort() on a non-existent port and it returns a -1 which, according to the documentation, then requires a call to _WinAPI_GetLastError() which in turn return 2 which is invalid return type. In looking through the return codes I don't see any that would signify things like "port does not exist", "port already opened" or things like that. Aren't those errors available?

Edited by Trax
  • 3 months later...
Posted

Hi, I run this script:

#include <CommInterface.au3>
#include <MsgBoxConstants.au3>

Local Const $iPort = 5
Local Const $iBaud = 115200
Local Const $iParity = 0
Local Const $iByteSize = 8
Local Const $iStopBits = 1

Local $hFile =_CommAPI_OpenCOMPort($iPort, $iBaud, $iParity, $iByteSize, $iStopBits)
_CommAPI_ClearCommError($hFile)
_CommAPI_PurgeComm($hFile)

_CommAPI_TransmitString($hFile, "*IDN?") ;Identify your-self

Local $sResult =_CommAPI_ReceiveString($hFile, 5000);Recieve string

_CommAPI_ClosePort($hFile)

MsgBox($MB_SYSTEMMODAL, "Title", $sResult, 5)

But bump into this error:

C:\Program Files (x86)\AutoIt3\Include\CommInterface.au3 (1) : ==> Unable to parse line.: 
<!DOCTYPE html> 
<^ ERROR
>Exit code: 1    Time: 0.3675

I downloaded all 6 files from https://www.autoitscript.com/wiki/CommAPI and put them in the "Include" folder under AutoIt directory.

How can I workaround on this error? My system is 64 bit though.

  • 3 months later...
Posted
  On 6/12/2020 at 8:23 AM, guner7 said:

Hi, I run this script:

#include <CommInterface.au3>
#include <MsgBoxConstants.au3>

Local Const $iPort = 5
Local Const $iBaud = 115200
Local Const $iParity = 0
Local Const $iByteSize = 8
Local Const $iStopBits = 1

Local $hFile =_CommAPI_OpenCOMPort($iPort, $iBaud, $iParity, $iByteSize, $iStopBits)
_CommAPI_ClearCommError($hFile)
_CommAPI_PurgeComm($hFile)

_CommAPI_TransmitString($hFile, "*IDN?") ;Identify your-self

Local $sResult =_CommAPI_ReceiveString($hFile, 5000);Recieve string

_CommAPI_ClosePort($hFile)

MsgBox($MB_SYSTEMMODAL, "Title", $sResult, 5)

But bump into this error:

C:\Program Files (x86)\AutoIt3\Include\CommInterface.au3 (1) : ==> Unable to parse line.: 
<!DOCTYPE html> 
<^ ERROR
>Exit code: 1    Time: 0.3675

I downloaded all 6 files from https://www.autoitscript.com/wiki/CommAPI and put them in the "Include" folder under AutoIt directory.

How can I workaround on this error? My system is 64 bit though.

Expand  

You have to open the link in the browser, copy the content and save in a file in your computer. That happed probably because you clicked on "Save link as", so the browser save the html page, not the file.

Posted
_CommAPI_GetCOMPorts()

 

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:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 8 months later...
Posted

According to what I read in the "Features" session, this UDF is capable of LPT ports management.

"Possibility of parallel communication (parallel port, LPT port)"

Can someone give an example...I cannot figure it out how can i connect on a LPT port :(

Thank you so much!

Posted

Hello @manutz88 It seems to be is not implemented. You would need to modify _CommAPI_CreateModeString function to support LPT string.

 

Saludos

  • 1 year later...
Posted

Hello. Does anyone know why, in the _CommAPI_GetCOMPorts function, in the following line of code:

Local $oItems = $oWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%(COM%)'", "WQL", 48)

the number 48 = 16 (Return Immediately) + 32 (ForwardOnly) is passed as a parameter? If I pass 0, the call doesn't return until the query completes (I think is more helpfull), and I can also get the number of items returned without ForwardOnly ($oItems.Count exists and doesn't return an error like passing the Forward Only parameter does).

I attached my modified version (I change function name so I can use both functions) for anyone interested. The differences:

  • autostart of WMI service if not running
  • detection of LPT and COM ports
  • can filter out LPT ports
  • can filter out ports without port number
  • can return array of ports detected as port numbers, port names (COMx/LPTx), or bi-dimensional array with port number, port type (COM or LPT), hardware ID, port description

 

_CommAPI_GetPorts.au3Fetching info...

  • 2 months later...
Posted

Hello,
Is there a way to work with events instead of pulling the serial port? So every time one byte arrives a function can receive that byte, this way I can implement a circular buffer for a more advanced communication protocol.
Thanks

Posted (edited)
  On 6/16/2023 at 1:49 PM, Chuckero said:

Is there a way to work with events

Expand  

look at one of the first posts ( https://www.autoitscript.com/forum/topic/155674-commapi-serial-and-parallel-communication-with-windows-api/?do=findComment&comment=1126366 ) and you'll see that your question makes little sense. I don't use this but looking at the code, all you have to do is to code your own events on reception. You'd have to pull from _CommAPI_ReceiveData() every so often ( with AdLib or timer or your imagination ) and trigger your event for the rest of the script. The data will be there but you'll have to read to be aware of the data been there. Should not be a big deal.

 

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

  • 2 weeks later...
Posted
  On 6/16/2023 at 2:43 PM, argumentum said:

look at one of the first posts ( https://www.autoitscript.com/forum/topic/155674-commapi-serial-and-parallel-communication-with-windows-api/?do=findComment&comment=1126366 ) and you'll see that your question makes little sense. I don't use this but looking at the code, all you have to do is to code your own events on reception. You'd have to pull from _CommAPI_ReceiveData() every so often ( with AdLib or timer or your imagination ) and trigger your event for the rest of the script. The data will be there but you'll have to read to be aware of the data been there. Should not be a big deal.

 

Expand  

I understood. So, there is no way to work with events, I have to work with pulling the serial port at a high frequency, or at least, high enough to not let the input buffer fill up.

 

Posted
  On 6/29/2023 at 1:05 PM, Chuckero said:

So, there is no way to work with events, I have to work with pulling the serial port at a high frequency, or at least, high enough to not let the input buffer fill up.

Expand  

You can always fork ( look in my signature for examples ). That way, one script as the serial com handler and the other, the GUI that receives the data from the other via IPC. Therefore, even thought AutoIt is slow to handle so may things in a single thread, with this approach you'd have as many threads/cores working for you as you feel you need to have, to make it in time to handle anything. Or most anything, again, gotta be creative :)   

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

  • 4 months later...
Posted

Have you tried Service UDF?

 

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 11/3/2023 at 11:00 AM, mLipok said:

Have you tried Service UDF?

 

Expand  

negative. I use this udf as windows task scheduler but the result is the same as service. It can enumerate the serial port, but it cannot open it

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
×
×
  • Create New...