Skip to content

Conversation

@jacson-junior
Copy link

Problem

ModBoss currently only batches mappings that are perfectly contiguous (no gaps between addresses). This results in excessive Modbus requests when schemas have small gaps between register mappings.

Example: A schema with mappings at registers 0-5, 12-23, 36-37, 40-41, 46-49, 51-53, and 130-147 generates 7 separate requests even though many of these could be combined with minimal overhead.

Solution

Added configurable gap tolerance that allows ModBoss to batch mappings with small gaps between them. When a gap is within tolerance, registers in the gap are read but their values are discarded.

@bencoppock
Copy link
Contributor

Love the look of this!

I'm away from my computer today, but I'll take a look when I'm back at it (maybe next week). Thanks for the PR!

@bencoppock
Copy link
Contributor

@jacson-junior sorry it's taken me so long to get back to this. I've had some thoughts in the meantime! I'd like to have this functionality included. However, there are a couple things I think we could tweak in our approach:

1. Non-readable registers
I think we should be careful to only read gaps if all of the gap addresses are labeled as readable in the schema. In other words, if any addresses in a particular gap are either labeled as write-only or are not included in the schema at all, then we shouldn't query across that gap (I'm thinking it's not necessarily safe).

2. Specify :max_gap at runtime
Whether or not to query across gaps doesn't seem intrinsically part of the schema itself—that would force all possible reads against any given schema to follow identical gap rules.

Instead, my inclination is to move the :max_gap option to ModBoss.read/4 so that it can be specified differently for different reads even against the same schema.

I'd love your thoughts on this. Would you be interested in making that happen?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants