Hi all. I'm after some advice on developing nodes. Firstly I have read the guidelines
however most of the info is unfinished.
I am creating some nodes that are essentially PLC Read and PLC Write nodes. These nodes share a configuration node. Their operations are asynchronous (as they send a read/write request to the PLC then upon receiving a reply, send a message to the next node). Fairly straightforward right?
So, while developing, I have many thoughts about how best to handle the likes of timeouts, read errors, disconnections etc. How should dynamic requests be made via input message, should I retain the original msg
and send this along with my data??? Many thoughts, difficult to put into easily answerable questions I suspect. I'll try tho...
Best means of accepting input...
- Should I use topic and payload
msg.topic = "D5" /*address*/; msg.payload = 5 /*count*/;
. This seems ideal however it's limiting. What if I need to include data or a timeout parameter. - should I use an object for payload to pass in the parameters? E.g.
msg.payload = {address:"D5", count:10}
- should I leave the original payload and request the input msg has distinct properties e.g.
msg.address="D5"; msg.count = 10;
or an object added to msg?
What to send in output...
Is it preferred that an asynchronous node outputs only to payload? Should all properties of my nodes asynchronous response (e.g. .success, .data, . responseTime, .errorCode) be all contaied in one object? In payload?
To send or not to send...
My first version would simply not call node.send(msg)
if there was a timeout, or bad response from PLC etc however, this means the next node has no opportunity to act on a bad response.
So my second version sends the results and additional properties would indicate a bad response e.g. msg.quality = "BAD";
this then led me to think, should I encapsulate all of my response into the payload? Is there a preferred convention?
Other thoughts include...
When should my node raise an error. If the PLC response is bad? Times out? At first this seemed ideal however the catch node would be going nuts if the user is polling at say 0.1sec while the PLC is turned off / disconnected.
Should a node that is essentially asynchronous store the original msg (and all the properties a user might have tagged on to it) then send this original msg with my nodes results appended? The user may have added some info to the msg for use after my node has done its job!
Thanks in advance for any advice or thoughts on this topic.
Steve.