Jump to content

Recommended Posts

Posted
3 hours ago, antonioj84 said:

I  have a device attach to a serial port

What device, what communication protocols. Is like @antonioj84 is not reading this right now, therefore my keyboard is not working, ...if my keyboard worked, @antonioj84 would have responded by now.  =P 

Share a little more about the device

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

Posted (edited)

hi Argumentum,  thank you for responding  the device is connected to com2  and it's  a vx820, a  pinpad. I  need some help starting. basically I would like to send a basic command and get an acknowlegment.

 

https://stackoverflow.com/questions/30023721/communicating-with-serial-port-verifone-vx520 

https://kr3l.wordpress.com/2008/12/07/serial-com-port-communication-with-autoit/

 

 

protocol.png

Edited by antonioj84
error
Posted
8 hours ago, antonioj84 said:

it's  a vx820

PERFORMANCE DRIVEN,
POWERFULLY VERSATILE
• Simplified, single-port connectivity offers USB, serial and Ethernet
connection options
• Pair with any terminal for a complete, consumer-facing solution
• Deliver targeted promotions and branding messages on the screen
• Integrated EMV and NFC
• Advanced end-to-end encryption

the Advanced end-to-end encryption part, may make the communication, to make no sense from a text readable point, and have to use their drivers and comm utilities.
Other ways of exploration would take a data analyzer to figure out what may be going on ( without more information from Verifone )
Are you sure that 8,n,1 at 9600 baud is the way to talk to the device ?, if it's something else, you will not communicate with the device to start with. Then again, if you don't have a set of commands from the maker ( or a set standard for the device type ), you can not have a meaningful interaction with the device.
If you can read java, https://sourceforge.net/p/unicentaopos/discussion/search/?q=vx820 may get you some support. Or, talk to the Verifone about their product. Maybe you can interact via TCP/IP with it. No clue.

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

Posted

hi Argumentum

The Manufacturer does not provide such info for security reason. here is an alternative,  a command to check if the serial com port  2  is  either in use or busy ? at the dos prompt  will fit the bill. Any help is appreciated.

Posted
13 hours ago, antonioj84 said:

check if the serial com port  2  is  either in use or busy

..ok, this  line of questions should go in the help part of the forums as is not related to this UDF ( from 2007 ).
Software is not magic, it runs on hardware. Having an idea of how the hardware works at a bit level, is important to have an idea of what is, or could be, going on with the stuff we plug in. I'd recommend you to watch this video as it has a description of how RS232 talk.

On a NT OS ( anything after win98 ) , a DOS prompt does not give you direct access to hardware therefore a CUI ( dos prompt ) really don't matter. I'd make a GUI myself.

To troubleshoot the serial port on your PC, you'd need a loopback connector 

Other than this, I have not worked with serial ports in a long time. I would not know what else to tell you.

Again, create a post in the help part of the forums and clearly explain your environment, your previous actions and your specific goal for a practical application ( other than "is the port in use by another software" ). 

PS: if all you want to use this for, is reading the magnetic data from a card, get a magnetic card reader.

 

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

  • 3 months later...
Posted

Here is a 64 bit version for someone to try. Any feedback would be appreciated.

The dll is COMMG64.DLL.

The example script is Commg64Example.au3 and the UDF is CommMG64.au3. The only changes to the AU3 scripts for the 64 bit version is that I have simply replaced CommMg.au3 with CommMG64.au3 and commg.dll with commg64.dll.

COMMG64.zip

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
  • 1 month later...
Posted

Good day.
I am using the commg.dll V2.83 and apparently I have a problem to establish comunicasion at speeds greater than 256000 baud.

I am using the Putty program with which I was able to communicate at speeds of 921600 and 2000000.

The IC also has communication to 115200 but this speed is not a problem.

I think it's possible that I'm missing something extra but I can not imagine what it is.

  • 1 month later...
Posted

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

  • 1 month later...
Posted
On 3/25/2018 at 6:37 AM, martin said:

Here is a 64 bit version for someone to try. Any feedback would be appreciated.

The dll is COMMG64.DLL.

The example script is Commg64Example.au3 and the UDF is CommMG64.au3. The only changes to the AU3 scripts for the 64 bit version is that I have simply replaced CommMg.au3 with CommMG64.au3 and commg.dll with commg64.dll.

COMMG64.zip

Just like Alan I can not find the .Au3 files for the Commg64Example. I can the example to receive from a device setup on my com port but I can not send commands. 

Posted
On 7/10/2018 at 1: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

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

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
  • 3 months later...
  • 3 months later...
Posted

Hi Everyone, 

I have a question about how shoud my function look to return hex bytes from com port. At this moment it returns number of bytes that have been read but where they go ? How to access them ? It would be perfect if they were returned as a hex string.

I'm sending data like "0xBCFD0101000000AE"

It should return "0xBCFD02000000FFAE" <- i want this to be returned as a result of function
    

 

Func SendAndRead($data, $numBytesToRead,  $readType =  1)
    $bBinData = Binary($data)
    $iNumbytes = BinaryLen($bBinData)
    $tBinData = DllStructCreate("byte["&$iNumbytes&"]")
    DllStructSetData($tBinData, 1, $bBinData)
    
    $iRet = _CommSendByteArray(DllStructGetPtr($tBinData),$iNumbytes,1)
    If (@error Or $iRet = -1) And $Initialized = 1 Then MsgBox($MB_SYSTEMMODAL, "Error while sending", "!Error: " &  @error,  1)

    $iRet = _CommReadByteArray(DllStructGetPtr($tBinData),$numBytesToRead,$readType)
    If (@error Or $iRet = -1) And $Initialized = 1 Then 
        MsgBox($MB_SYSTEMMODAL, "Error while reading", "!Error: " &  @error,  1)
        Finalize()
    EndIf
    
    Return $iRet
EndFunc

Anyone can help ? :)

Thanks !

Posted

Your last $iRet, as you noted, returns the number of bytes read.  After that, you need to get the received data from the buffer.  Add another line such as:

$iRet = DllStructGetData($tBinData, 1)

I hope that works; I'm kinda sketchy on structs, myself.

Alan

Posted (edited)
On 4/24/2019 at 4:51 PM, adnadeau said:

Your last $iRet, as you noted, returns the number of bytes read.  After that, you need to get the received data from the buffer.  Add another line such as:

$iRet = DllStructGetData($tBinData, 1)

I hope that works; I'm kinda sketchy on structs, myself.

Alan

Hi Alan,

Thanks for replay, unfortunately it is not working 😕 
I gott parse error
 

==> Unable to parse line.: 
$iRet = DllStructGetData($tBinData, 1)? 
$iRet = DllStructGetData($tBinData, 1)^ ERROR

 

Edited by Majkel
Posted

I rewrote your function as a stand-alone script.  It works okay.

#include <CommMG64.au3>

$Result = _SendAndRead(0x12345678, 4, 1)
MsgBox(0x0, "$iRet", "Result = " & $Result)

Func _SendAndRead($data, $numBytesToRead,  $readType =  1)
    Local $Initialized
    $bBinData = Binary($data)
ConsoleWrite("Line " & @ScriptLineNumber & ": $bBinData = " & $bBinData & @CRLF)

$iNumbytes = BinaryLen($bBinData)
ConsoleWrite("Line " & @ScriptLineNumber & ": $iNumbytes = " & $iNumbytes & @CRLF)

$tBinData = DllStructCreate("byte["&$iNumbytes&"]")
;ConsoleWrite("Line " & @ScriptLineNumber & ": $tBinData = " & $tBinData & @CRLF)

    DllStructSetData($tBinData, 1, $bBinData)

    $iRet = _CommSendByteArray(DllStructGetPtr($tBinData),$iNumbytes,1)
    If (@error Or $iRet = -1) And $Initialized = 1 Then MsgBox(0x0, "Error while sending", "!Error: " &  @error,  1)

    $iRet = _CommReadByteArray(DllStructGetPtr($tBinData),$numBytesToRead,$readType)
    If (@error Or $iRet = -1) And $Initialized = 1 Then
        MsgBox(0x0, "Error while reading", "!Error: " &  @error,  1)
        ;Finalize()
    EndIf
    $iRet = DllStructGetData($tBinData, 1)
    Return $iRet
EndFunc

Regards,

Alan

  • 2 weeks later...
Posted
On 4/26/2019 at 8:20 PM, adnadeau said:

I rewrote your function as a stand-alone script.  It works okay.

#include <CommMG64.au3>

$Result = _SendAndRead(0x12345678, 4, 1)
MsgBox(0x0, "$iRet", "Result = " & $Result)

Func _SendAndRead($data, $numBytesToRead,  $readType =  1)
    Local $Initialized
    $bBinData = Binary($data)
ConsoleWrite("Line " & @ScriptLineNumber & ": $bBinData = " & $bBinData & @CRLF)

$iNumbytes = BinaryLen($bBinData)
ConsoleWrite("Line " & @ScriptLineNumber & ": $iNumbytes = " & $iNumbytes & @CRLF)

$tBinData = DllStructCreate("byte["&$iNumbytes&"]")
;ConsoleWrite("Line " & @ScriptLineNumber & ": $tBinData = " & $tBinData & @CRLF)

    DllStructSetData($tBinData, 1, $bBinData)

    $iRet = _CommSendByteArray(DllStructGetPtr($tBinData),$iNumbytes,1)
    If (@error Or $iRet = -1) And $Initialized = 1 Then MsgBox(0x0, "Error while sending", "!Error: " &  @error,  1)

    $iRet = _CommReadByteArray(DllStructGetPtr($tBinData),$numBytesToRead,$readType)
    If (@error Or $iRet = -1) And $Initialized = 1 Then
        MsgBox(0x0, "Error while reading", "!Error: " &  @error,  1)
        ;Finalize()
    EndIf
    $iRet = DllStructGetData($tBinData, 1)
    Return $iRet
EndFunc

Regards,

Alan

I don't know what kind of magic is it that but i just copied Your function and it works ! 

But when i added this line to my function then it returns parse Error. (Don't know why 🙄)

Anyway it works, thanks for help ! :D

_
Regards,
Michal

  • 7 months later...
Posted (edited)

Hi,

for a little project I need to send some commands to a device over the com port

Quote

;FIRST channel commands:
;OFF command : FF 01 00 (HEX) or 255 1 0 (DEC)
;ON command : FF 01 01 (HEX) or 255 1 1 (DEC)

I'm using the following lines

_CommSendstring(Chr(255) & Chr(1) & Chr(1),1)
_CommSendstring(Chr(255) & Chr(1) & Chr(0),1)

The first line (ON command) works like expected, but the second line not. After doing some reserach with a serial port monitor, I found out that Chr(0) seems to be an emtpy string which makes OFF command incomplete.   Any idea why Chr(0) doesn't work? Any suggestions to make it work?  Thx in advance :)

EDIT: I found the following code

$bBinData = Binary("0xFF0100")
$iNumbytes = BinaryLen($bBinData)
$tBinData = DllStructCreate("byte["&$iNumbytes&"]")
DllStructSetData($tBinData, 1, $bBinData)
$iRet = _CommSendByteArray(DllStructGetPtr($tBinData),$iNumbytes,1)

 

 

 

Edited by Unikat2000
  • 2 weeks later...
Posted

If you want to send a binary zero then sending a string won't work.  You need to use _CommSendByte, or if you have a few bytes to send you can use _CommSendByteArray.

There is an example of _CommSendByteArray here

https://www.autoitscript.com/forum/topic/128546-serial-port-com-port-udf/?do=findComment&comment=1130587

 

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
  • 2 weeks later...
Posted

Hello All, I have been working on this autoit script for about a month now and refused to post to the forum about it until I knew I couldn't figure it out. I have read nearly all 33 pages of this topic but can't seem to debug my issue. I wish I was more of a programmer than what I am but I am not, I just kindof understand programming logic.

For a simple overview I want to receive an integer, either positive or negative, from my Arduino and output it into  another application. I have figured out the ControlClick into the other application but I am having a bear trying to figure out the CommMG64 and why it isn't working for me. Eventually I would like the Autoit to react to the continuous stream of data from the arduino as a control system but for now I just want to understand how to read my data from the Arduino aka the "-95".

When I run the Autoit script below, all that is entered into the word document is "0". However, once, I was trying to send the string, "Degrees Counted = " from the Arduino Serially and it printed "DERG="(without the quotes) to my applicaiton. I got very excited but nothing transpired after that.

I haven't been using a GUI so that could be an issue, since many of the other questions and examples use them. I really didn't think that would be an issue and I don't need one at the moment, so I was avoiding it.

I ran the example code in a new script, with an #include <CommMG64.au3> at the top and it executed just fine. So, I am thinking my script should be able to access it just as well.

Here is my auotit script

#include <GUIConstants.au3>
#include <MsgBoxConstants.au3>
#include <CommMG64.au3>
;#RequireAdmin

_CommSetPort(4, '', 9600, 8, 0, 1, 2)
local $nextline = _CommGetLine(@CR,0,0)

$hWin = WinGetHandle("Document1 - Word")
WinActivate($hWin)
ControlClick($hWin, "", "[CLASS:_WwG; INSTANCE:1]" , "Left", 1,221, 142)

Send($nextline)
Send("{enter}")

Here is the Arduino script. This is just using example data.

void setup() {
Serial.begin(9600);
}

void loop() {
  delay(100); 
  //Serial.println("Degrees Counted = ");
  Serial.println(-95);
}

I just tried copying the autoit and arduino script from the link below by changing the com port, and library to the updated commMG64.au3 version. I still get the error that it can't connect to COM4.

I wrote this last night then I changed my code above to have an iflow of 2 and it all worked. I was able to get data streaming last night but it changed this morning and now won't work I didn't change anything from last night, that I know of. I also checked out my COM port on CMD, checked "mode" and reset COM4 to 9600 because it automatically changes to 115200 but that didn't do the trick either. I am open to anything to get this going and any type of feedback.

Please help with any comments of why what I have wouldn't be working or links to where I could better look for answers.

Martin, this looks to be an exceptional script and I was wicked excited that it started working last night but right back into frustration that it has stopped again. I can wait to get this up and running. Thank you for providing this.

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