Modbus Module Changes

I'm thinking about changing the way that the Modbus Module handles data. Right now it simply has a large (size is configurable) data table. Each configured modbus command writes the results of it's query into some index of that data table. The data table is an array of DAX_INT's in the server. The bitwise modbus functions would write to bits in the data table that are indexed as bits. In other words bit 16 is the first bit in the second word of the data table.

I started out with this idea because I thought that it would be easy to share data between ports and modbus commands.  One modbus port could be reading data from a certain place and  another port could produce that data to a master connected to another port.  The single data table idea is just antiquated.  It makes other parts of the system complicated and configuring the modbus commands are tedious.

The idea that I'll probably move to is removing the data table index from the modbus command configuration and replacing it with a tag name and index configuration.  The module would then create the tags on the server for each individual tag that was specified in these commands.  If the function code of the command was one that reads words then the created tag would be DAX_INT, if the function code was bit oriented then the tag would be DAX_BOOL.  The system would keep up with the index / count values in the commands to know how big to make the tags.

It will be much easier to force each command to create it's own individual tags but if I do just a bit more work I can have different commands writing to different places in the same tag.  This would almost duplicate the capability of sharing the data table that I discussed above except that bits would be bits and words would be words.  The simplicity in implementing this idea seems sufficient to offset the rare occasions when sharing bits from one slave in words to a master become necessary.  Besides this could easily be implemented in logic with another module.

Word sharing or bit sharing will be pretty easy though if I allow multiple commands to share a single tag.  Say for example there is a modbus slave that has 16 words of data that we want to read.  There are 4 of these slaves and we want to share those 64 words of data with a remote Modbus TCP client.  We can assign all four master commands to the tag (let's call it mod_flows).  So the first slaves data goes in mod_flows[0].  The second goes in mod_flow[16] and so on.  Then the configuration for the TCP server uses the mod_flows tag as well but it exposes all 64 words.

Another feature that I am thinking about adding is a trigger for a modbus master command. Right now there are three settings for a modbus master to determine when to send the request.  The first is OFF which means don't send it at all.  The second is CONTINUOUS which sends the request every time the port is polled (actually there is an interval so that it doesn't have to happen every time it's polled but a multiple of times).  The last is an ON CHANGE condition where the request is sent when the data that the command is associated with is changed then the command is sent.  I want to add a trigger as well.  Probably a BOOL tag that would be set up so that when it is set the command will be sent and then the modbus module would reset the bit.

I also need to add some status information from each port.  I'll probably allow the user to specify the name of this tag on a per port basis and it'll be an array for now, but hopefully we'll have custom data types in the very near future that I can use for this.  I think I'll also have a status tag for the whole module too.