Hi All,
I've recently moved to HS2 from 1.7 where I had a number of custom written plugins to talk to serial devices around my house (ie. furnace controllers, sprinkler relay controllers, outdoor lighting controller, AV receiver, and intercom system)
Since all of my plugins would have to be re-written in .NET (or at least to the HS2 API) I decided to start playing around with some scripts to control these devices.
I've come up with a method of supporting two-way, asynchronous communication with serial devices using only a single script. Well, OK, you do need to add a line of code to startup.txt and shutdown.txt to call the open and close subroutines in the script. I don't think this is anything radically new but thought I'd share what I've come up with.
This is a work in progress but I'm posting to get feedback on my methods before I spend too much more time on it. This method seems to work well as long as the device sends status messages that end with some termination character or string.
Basic Setup:
1. Add line: hs.RunEx "DenonAVR.txt", "OpenAVR", "" to startup.txt to Open Com Port.
2. Add line: hs.RunEx "DenonAVR.txt", "CloseAVR", "" to shutdown.txt to Close Com Port.
3. Edit "hc" and "port" constants in DenonAVR.txt to match the house code and port you'll be using.
4. Create HS devices to hold status (See Devices.txt for a list of HS devices the script currently uses)
5. The code in subroutine "ProcessResponse" in DenonAVR.txt processes messages from the device and places status in HS devices.
6. A call to subroutine "SendCommand" in DenonAVR.txt sends a command to the device. (hs.RunEx "DenonAVR.txt", "SendCommand", "PW?")
This has been running for several days with my AVR-4308CI and seems to be reliable. I think this method could be used to monitor and control just about any serial device.
Please provide feedback and post modifications if you have a better way of doing this.
Thanks,
Ken
I've recently moved to HS2 from 1.7 where I had a number of custom written plugins to talk to serial devices around my house (ie. furnace controllers, sprinkler relay controllers, outdoor lighting controller, AV receiver, and intercom system)
Since all of my plugins would have to be re-written in .NET (or at least to the HS2 API) I decided to start playing around with some scripts to control these devices.
I've come up with a method of supporting two-way, asynchronous communication with serial devices using only a single script. Well, OK, you do need to add a line of code to startup.txt and shutdown.txt to call the open and close subroutines in the script. I don't think this is anything radically new but thought I'd share what I've come up with.
This is a work in progress but I'm posting to get feedback on my methods before I spend too much more time on it. This method seems to work well as long as the device sends status messages that end with some termination character or string.
Basic Setup:
1. Add line: hs.RunEx "DenonAVR.txt", "OpenAVR", "" to startup.txt to Open Com Port.
2. Add line: hs.RunEx "DenonAVR.txt", "CloseAVR", "" to shutdown.txt to Close Com Port.
3. Edit "hc" and "port" constants in DenonAVR.txt to match the house code and port you'll be using.
4. Create HS devices to hold status (See Devices.txt for a list of HS devices the script currently uses)
5. The code in subroutine "ProcessResponse" in DenonAVR.txt processes messages from the device and places status in HS devices.
6. A call to subroutine "SendCommand" in DenonAVR.txt sends a command to the device. (hs.RunEx "DenonAVR.txt", "SendCommand", "PW?")
This has been running for several days with my AVR-4308CI and seems to be reliable. I think this method could be used to monitor and control just about any serial device.
Please provide feedback and post modifications if you have a better way of doing this.
Thanks,
Ken
Comment