Communication via com port

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Draken
Posts: 58
Joined: 08 Dec 2022, 01:19

Communication via com port

15 May 2024, 05:11

@mark_pickhard
viewtopic.php?style=17&t=120880

Hello, I'm trying to use the Com communication from the above post. I built a code that should connect, according to the defined parameters, and successively send "i", "0", Enter key, "1" and Enter key again. The script runs without error, but when I connect via the classic terminal on the device there is no change, there will be a problem somewhere. I suppose it should work except for sending the Enter key. If I use the test code for the library the communication works correctly. Thank you.

Code: Select all

#Requires AutoHotkey v2.0
#Include "AutoHotkey v2 COM Library.ahk"

Port := "COM1"
Baud := "115200"
Parity := "N"
Bits := "8"

ComHandle := ComOpen(Port, Baud, Parity, Bits, 1) ; 1 stop bit
ComWriteString(ComHandle, "i")
Sleep 1000
ComWriteString(ComHandle, "0")
Sleep 1000
ComWriteByte(ComHandle, Ord(Chr(13)))
Sleep 1000
ComWriteString(ComHandle, "1")
Sleep 1000
ComWriteByte(ComHandle, Ord(Chr(13)))
MsgBox("Done")
mark_pickhard
Posts: 3
Joined: 29 Aug 2023, 14:26

Re: Communication via com port

15 May 2024, 08:36

I've used similar DLL code with v1 without issue, but I couldn't get it to work reliably with v2. For my project I ended up using code like this:

Code: Select all

  ComPort := FileOpen(Com1_9_Port . ":", "w")
  ComPort.Write("testing...")
  ComPort.Close()
The baud, bits, etc. needs to be set from the Windows command line interface using the "mode" command. Not ideal, but it worked much better for me. I only needed to send, so opened using "w" and only used Write.
Draken
Posts: 58
Joined: 08 Dec 2022, 01:19

Re: Communication via com port

15 May 2024, 11:56

@mark_pickhard
Hello, thank you for the reply, but I'm not sure how to edit the script, could you be specific on how to edit my script to make it functional? Thank you.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Draken and 27 guests