Serial I/O hardware & Generic Serial Plugin

General HouseBot discussion. Any issues that don't fit into any of the other topics belong here.
Post Reply
NW27
Member
Posts: 16
Joined: Mon Jul 18, 2011 6:55 pm

Serial I/O hardware & Generic Serial Plugin

Post by NW27 »

Hi,

I have some I/O boards (8 inputs & 8 outputs) that are controlled via a RS232 or RS485.
They work in a polled mode and they expect a PC to continually talk to them to keep the outputs set accordingly. Approximately every 500mS
It's a 10 byte data stream that roughly looks like "STX, LEN, Address, Type, Data, Checksum, ETX" all a combination of HEX and ASCII.
In the data section is a byte with the bit information for the outputs and a byte with the bit information of the inputs.
If the PC stops talking to the device, it times out and turns all of the outputs OFF.
Basically a software watchdog. Don't want to leave the sprinklers ON if the PC crashes :(

So, can the Generic Serial Plugin be setup to handle this style of communications??? Continuous polling?
I realize it won't straight of the bat, it's more can a driver/plugin be created that will do this?
If so, what do I need to do?

Neil.

P.S.
My normal programming language is Pascal but I do have a basic understanding of basic & C.
Richard Naninck
HouseBot Guru Extraordinaire
Posts: 1121
Joined: Tue Sep 28, 2004 7:49 am
Location: The Netherlands

Re: Serial I/O hardware & Generic Serial Plugin

Post by Richard Naninck »

Yes, the Generic Serial Device can do that.

First read up on how to set it up.. this forum has many large threads discussing how this should be done, but the help file should also be sufficient.

After you have setup the hardware device and the generic serial device, you can create a script device and write yourself a vbscript that does all that. Many examples on how this is done can also be found on this forum.
You can use a NULL device to setup properties for the status of your relais states and to send commands to your script. I wouldn't use tasks for this.
Steve Horn
HouseBot Guru
Posts: 750
Joined: Wed Apr 02, 2003 8:10 pm
Location: Pelham AL

Re: Serial I/O hardware & Generic Serial Plugin

Post by Steve Horn »

Another option would be to offload the continuous looping/polling/refreshing to a microcontroller (i.e. Arduino or equiv.) and let it do the repetitive stuff. Then send commands from HB via the generic serial arrangement Richard described to do whatever changes are required to the I/O boards and its ins and outs. So you'd have RS232 from HB to the Arduino, and RS232 from the Arduino to the I/O boards. The Arduino (programmed in a subset of C) would refresh the I/O every 500ms while monitoring its input serial port (from HB) awaiting a change in commands. You would establish the protocol (command format) between HB and Arduino, program the Arduino to act on them accordingly to do whatever the I/O boards need to change port status.
Steve
NW27
Member
Posts: 16
Joined: Mon Jul 18, 2011 6:55 pm

Re: Serial I/O hardware & Generic Serial Plugin

Post by NW27 »

Hi Steve,

Thanks for replying. In another life, I was a embedded hardware developer and I actually designed this board and wrote the firmware.
My point being, I could change the firmware so that it didn't require polling but this negates the software based watchdog functionality.
As per the example of the water based sprinkler system running non stop for the weekend, because HB stopped for what ever reason - PC died, operating system crashed or even HB stopped/locked up. So many reasons are possible.
Being a designer of industrial control equipment, I cannot go backwards to a system that doesn't have a fail safe.

By the way, the boards also have a hardware based watchdog, just in case the local embedded processor on the PCB does a dummy spit.

Neil.
Steve Horn
HouseBot Guru
Posts: 750
Joined: Wed Apr 02, 2003 8:10 pm
Location: Pelham AL

Re: Serial I/O hardware & Generic Serial Plugin

Post by Steve Horn »

I understand what you're saying. That's why I like the idea of offloading the polling/updating/heartbeat functionality to a simple cheap controller. You're not relying on Windows, HB, or VBScript to stay up and do something every half second. Richard is a wizard at HB and VBScript so I'll defer to him on what HB and VBScript can do. But if its like my Win box, HB server, and scripts, I don't think I'd want to place my faith in them running 24x7. But that may just be my configuration.
Steve
Richard Naninck
HouseBot Guru Extraordinaire
Posts: 1121
Joined: Tue Sep 28, 2004 7:49 am
Location: The Netherlands

Re: Serial I/O hardware & Generic Serial Plugin

Post by Richard Naninck »

software warchdogs are very important, but I am with Steve on this one. A micro controller should watch and the software (HouseBot) should be the heartbeat. I designed my own wireless central heating control based on an MC and HouseBot. HouseBot sends an "on" signal and the MC turn the central heating on via a relais. Then a 5 minute timer in the MC code starts which resets anytime a heartbeat is received. HouseBot sends one every minute. If I turn the heating off, HouseBot sends an Off command but if the PC fails and HouseBot stops working, the 5 minute timer times out and the heating stops as well. This would work fine for your sprinkler system. It would dramatically down your load on the system and would be as fail safe but even more robust.
NW27
Member
Posts: 16
Joined: Mon Jul 18, 2011 6:55 pm

Re: Serial I/O hardware & Generic Serial Plugin

Post by NW27 »

Hi Richard & Steve,

The in between controller (ie arduino) doesn't act as a software watchdog. Remember, I can reprogram the I/O board to any protocol.
An advantage of the polling, is that if the I/O interface is for some reason reset (physically turned off/on, power glitch etc etc), it knows what state to put the outputs back too.
I can implement your idea Richard in regards to the outbound communications to the I/O board. Perhaps if the heart beat message also sent the status of what the outputs should be?

What about the inbound, does the HB interface query what the inputs are or does it just rely on a received message indicating a state change.
If it just relies on a receive message, how about if after a heart beat message from HB the I/O responded with the current state of all inputs?
ie
IP1=0<CR><LF>
IP2=1<CR><LF>
IP3=0<CR><LF>
etc

When HB receives a message ie IP1=0 and it already knows that IP1=0 does it do something with this, ie fire an event or does it know that it is the same state, so no events are fired. As an example, it kept getting IP1=0 it might keep trying to turn the TV ON via an IR command.

All of the above is now just a different format of polling. :? But perhaps in a more HB friendly format.

Neil.

P.S. Sending/Receiving a 10 character message at 9600 baud every 100mS isn't even a tiny load on a IBM PC running at 4.7MHz. That's how long I've been doing this style of thing for. Think of you browsing the internet, @1.5MB/S and your network card @ 100MB/S. It doesn't blink an eye.
Steve Horn
HouseBot Guru
Posts: 750
Joined: Wed Apr 02, 2003 8:10 pm
Location: Pelham AL

Re: Serial I/O hardware & Generic Serial Plugin

Post by Steve Horn »

That is more Richard than Steve, so I'll let him respond to the best way to handle the HB end of your application. But I'd think that the inbound (to HB) can be anything you want it to be, as you'll program its functionality in VBScript (I assume, though may be other ways).

Regarding speed... I just have an innate distrust of anything Windows and by extension, applications that run under Windows, including VBScript. I would prefer to offload the, for lack of a better term, "looping" function to a microcontroller (middleware) that has a simple program in flash memory. But that's just me...
Steve
Richard Naninck
HouseBot Guru Extraordinaire
Posts: 1121
Joined: Tue Sep 28, 2004 7:49 am
Location: The Netherlands

Re: Serial I/O hardware & Generic Serial Plugin

Post by Richard Naninck »

First off I would send just one message containing all relais states like:
010000100
All 10 relais in just one message without mentioning the IP. You would receive one message and parse it into 10 states in your vbscript. If the script is continuously running, you can hold the states of all relais in your script and match any changes in script. If a change occurs, you could act on it. Set the states of your relais in seperate properties and only update these properties on a state change.
If you can program you IO board, you could reply on a heartbeat signal with an OK or whatever OR with the states when a change occured.
I know the load isn't that much but if you have 33 com ports going with loads of traffic going on and 33 scripts are handling all the messages, this would ask for a smarter update.
So I would send a heartbeat mnessage every minute. Your relais board would reply with OK every minute unless a state change occurs.. then the relais board would just send one message containing all states and your script would handle them. This keeps your comms alive between HB and your board and only handles changes when they occur.
If you can program micro controllers, then such a script wouldn't be that hard to write either. If you need help on HB specifics, I could give you pointers or sample code when needed.
If the relais board times out on a 5 minute no heartbeat timer, you could drop all relais for instance.
Post Reply