McDudeAbides Posted July 19, 2012 Posted July 19, 2012 Hello. This is my first post and I am unfamaliar with the correct protocol. If I leave something out, please let me know what I can provide to help get an answer. My primary objective is to control the 110v power to a zone amplifier. I am using a PowerSwitch device which is triggered by low voltage. I am using the RTS lead (pins 5 & 7) on a RS232 serial cable via a Prolific USB/Serial adapter to provide the switch voltage.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 ExitThe 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) WEndThanks for any advice you can offer.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now