Read COM3 Port Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
vanheartnet098
Posts: 61
Joined: 01 Sep 2020, 09:49

Read COM3 Port

Post by vanheartnet098 » 01 Sep 2020, 11:28

Hi I am new to AHK and I am making a AHK project that related to COM Port, I Have a Relay board connected to a COM port pins ( im also using RS232 for an alternative)
Those 2 pins at the picture are the only pins that connected to the wires going to the relay board that im using it has 12volts.

I only need the data that saying the power is OFF or ON, if the power from the relay has been cut (12v).

I Already looked into some posts in the forum but no luck, and also I already seen and read what aobrien posted but I can't figure out how I can apply it to my project, when i tried it the Read_data and Recieved_Data are always blank except with the RS232_FileHandle its always 312 or 308.

I tried this short one:

Code: Select all

	port := FileOpen("COM3", "w")  ; Open for writing only, not reading/appending.
	port.Write("1")  ; Write an ASCII digit 1 (binary Ord("1"), i.e. 49).
	port.WriteChar(0)  ; Write a single byte (binary 1).
	port.__Handle  ; This flushes the write buffer.
	port.Close() ; and close the Port
	msgbox, % port
it returns blank if the RS232 usb is plugin but even thought the Power is ON or OFF its still return blank

But if I unplug the RS232 it returns 0.

I hope someone could help me with this...

Thank You in advance. Have a nice day..
Last edited by vanheartnet098 on 03 Sep 2020, 11:30, edited 1 time in total.


vanheartnet098
Posts: 61
Joined: 01 Sep 2020, 09:49

Re: Read COM3 Port

Post by vanheartnet098 » 01 Sep 2020, 22:29

Thank you for your reply bobo

I did my best tried everything with all the script but none are working as im expecting...

I dont have a device that needs to communicate to the comport just a way to give me signals or triggers whenever the power source (relay) connected to the rs232 has been cut. Its just a plain electricity 12volts coming from a power supply of a computer. 2 wires to be exact, 1 is 12v and 1 is ground.

The two pins above are the ones that connected to a relay.

User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: Read COM3 Port  Topic is solved

Post by AlphaBravo » 02 Sep 2020, 09:56

The script posted here looks promising, I briefly tested an output on Pin 4 DTR and it worked, 7 volts or so to ground (Pin 5), I don't have small jumpers at the moment to test inputs, please check it and report if it works for you.
obviously you need to replace "COM2" with "COM3" in your case.

vanheartnet098
Posts: 61
Joined: 01 Sep 2020, 09:49

Re: Read COM3 Port

Post by vanheartnet098 » 02 Sep 2020, 22:05

AlphaBravo wrote:
02 Sep 2020, 09:56
The script posted here looks promising, I briefly tested an output on Pin 4 DTR and it worked, 7 volts or so to ground (Pin 5), I don't have small jumpers at the moment to test inputs, please check it and report if it works for you.
obviously you need to replace "COM2" with "COM3" in your case.
Ty so much for your effort... i really appreciate it. Thanks to this i can now continue with my project...

This is all i need.

More power to you. Godbless my friend 🥳🥳🥳

SUMARATRO
Posts: 2
Joined: 14 May 2023, 05:20

Re: Read COM3 Port

Post by SUMARATRO » 03 Jun 2023, 04:08

Hello try this simple code that using windows command tool : mode.com

Code: Select all

ComObjCreate("WScript.Shell").Run("mode /c com3: baud=9600 data=8 parity=n stop=1") ; serial port 3
port := FileOpen("com3", "r") ; open com3
number := port.ReadLine() ; reads the value from the serial port and stores it in the number variable
port.Close() ; close port
if you autohotkey gets freeze try this initialization by PuTTY :

Code: Select all

; set PuTTY location
putty := "C:\Program Files\PuTTY\putty.exe"
; check if PuTTY exists
if InStr(FileExist("%putty%"),"D")
; if it does not exist, display a message and exit
{
MsgBox, install PuTTY
ExitApp
}
; set PuTTY location
putty := "C:\Program Files\PuTTY\putty.exe"
; run PuTTY with serial COM3 port settings
Run %putty% -serial COM3 -sercfg 9600,8,n,
; wait for PuTTY to open
WinWaitActive ahk_exe putty.exe
; send letter s to COM3 port via PuTTY
Send s
Sleep 2000
Send s
; wait 2 seconds
Sleep 2000
; close PuTTY window
WinClose ahk_exe putty.exe
Be sure that you have in arduino code in void loop this :

Code: Select all

void loop()
{
Serial.begin(9600);
input = Serial.readString(); 
}

User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: Read COM3 Port

Post by iilabs » 03 Oct 2023, 22:00

Hello and thank you for this interesting topic!

How would I do this in Reverse?

For example I’m trying to have ahk read two variables coming in on the Com17 (sometimes Com15 depends on when I plug in my microcontroller). I would like to use this data for ahk code to do stuff I normally cannot do with the mouse and keyboard libraries I.e. activate windows etc.

Post Reply

Return to “Ask for Help (v1)”