My first pass at the working code is below. The simple design point is to call an executable once with the "ON" parameter and have the low voltage activate and stay on until the executable is called again later with the "OFF" parameter. The challenge is that the exe needs to return from first call, but doing so with a clean exit closes the port and releases RTS. Something needs to hang around and keep the port open. But then, I need to be able to talk to it when the "OFF" command is received to drop RTS.
I'm trying to find two ways of improvement. First, what is the most efficent way for a process to "hang around"? I'm using sleep loops now, but there's got to be something more system friendly out there. Second, what is best way to communicate with the spawned process to direct it to exit? I'm brute force killing it now, but once again I'm sure there's a better way. Any suggestions, examples or code snippets would be most appreciated.
The switching app:
Local $RTSLineApp $RTSLineApp=@ScriptDir & "/RTShigh.exe" ;fully qualify Switch StringLower($CmdLineRaw) Case "on" If ProcessExists("RTShigh.exe") Then ;don't run more than one instance Exit(0) Else Run($RTSLineApp) EndIf Case "off" ProcessClose("RTShigh.exe") ;kill process to close port, drop RTS Case Else MsgBox(0,"Usage", "Must be ON or OFF.") EndSwitch Exit
The RTS app/ spawned process:
#include "CommMG.au3" ;shoutout to Martin, CommMG guru #include <misc.au3> Local $PortErr Local $myx $myx = _CommSetPort(4,$PortErr) ;open COM4, default RTS high If @error Then MsgBox(16, "Error" & @error, $PortErr) Exit(@error) EndIf While 1 Sleep(5000) WEnd
Thanks for any advice you can offer.