digitalpetri / modbus

Modbus TCP, Modbus RTU/TCP, and Modbus RTU/Serial for Java 17+.
Eclipse Public License 2.0
654 stars 222 forks source link

where could I store per connection variables? #17

Closed galoko closed 6 years ago

galoko commented 6 years ago

where could I store per connection variables? I mean lets picture the situation: device connects to my slave server, write multiple registers and then read holding registers, I generate values in holding registers based on written registers values. So where exactly should I keep these values in-between of onWriteMultipleRegisters and onReadHoldingRegisters calls? I'm kinda out of options here or so it seems

kevinherron commented 6 years ago

I'm not sure what you mean you're out of options... you have infinite options. I purposely do not implement any kind of process/register map abstraction because everyone's use case is different.

Put them in a Map<Integer, Integer> or get as complicated as you'd like?

galoko commented 6 years ago

well, this is a first thing that comes to mind, but if only I could use AttributeMap interface of Channel so I could actually store my context in a connection, that would be much better, isn't it?

kevinherron commented 6 years ago

Modbus register and status values are not traditionally per-connection - it's supposed to be a global address space.

kevinherron commented 6 years ago

If ServiceRequest gave you access to the Netty Channel would that work for you?

edit: Mmm, might not be that easy, this interface has to work for RTU support as well, where there won't be a Channel.

galoko commented 6 years ago

That would be perfect, thank you. In fact this is how I changed your code in order to continue with my project, but I felt a little off about it.

edit: well, it can return null for RTU for all I care, I use only TCP right now, so... at least it's better than nothing