Switch on modbus-devices before reading, then off

Hello everyone,
I have an FX30s with some Modbus RTU I/O modules. It reads data nicely according to the configured read intervals. However, as our system is powered from battery, we need to switch off the IO modules in between reads. Our flow would be:

  1. Before the modbus service needs to read from a device: Switch on the modbus devices via DO3
  2. Wait until the devices have powered up, e.g. 4 seconds
  3. Read the relevant modbus registers
  4. Power off the IO devices again

Would this be possible via configuration somehow? I guess not so I would probably want something that can do this:

  1. Switch on the devices with an edge action triggered by the util/counter
  2. Wait x seconds
  3. Somehow trigger an asynchronous read on the registers and perform the required conversion
  4. Switch off the IO devices and set the util/counter for triggering the next run

What is the simplest way of achieving this without abusing the Octave architecture more than necessary?

Thanks for any help. :slight_smile:

Hi again,
Another approach could be to:

  1. just switch off the modbus devices while leaving the modbus service with a bunch of timeouts.
  2. When switching on the modbus devices I will leave them on until the error resource for each of my modbus registers reads zero. For this to work well the registers must be configured for a pretty fast sampling.
  3. Then forward the values to my virtual resource holding the measured readings.
  4. After that I can then switch off the modbus devices until it is time for a new reading.

Do you think this will work well? Could the setup be improved so that it is more in line with the intended deisgn patterns of Octave? :smiley:

Hello Jes,

Thank you for getting in touch, and glad to see you pushing the use case forward.

You can proceed as you suggested at first with some asynchrounous reads, without using the periodic Modbus service. How to implement this in details will depend on the number of registers that you have to read.

The key starting point will be that you can control the Modbus read requests as indicated here: https://docs.octave.dev/docs/modbus-guides#sending-requests-to-the-server-device
To trigger this from an Edge action, you can use the example provided here: https://docs.octave.dev/docs/modbus-guides#reading-or-writing-a-modbus-register-via-an-edge-action, adapting it to the Read request.

You could have a main Edge Action (EA), running based on the counter to:

  • control DO3
  • trigger the util/delay/set to 4 (seconds)

Another EA triggered by util/delay/value (which triggers 4 (or N) seconds after it was “set”:

  • will trigger the Modbus Read request

Observe /modbus/UART1/rht_modbus/request/value and process it in a 3rd EA that could also control D03 back to off.

Let me know if that would suit your use case

A.

Thanks Amons,
I got it working but with a little twist so that it just polls and then switches off when there is no longer a modbus timeout. Thanks a lot for the help, it was good knowing that it should be possible and not have to fear a dead end.

Do you know if it is possible to do multiple modbus reads in one single request without requiring the registers to be contiguous? I tried using an array of register addresses and a corresponding array of read lengths but that did not seem to work.
/Jes

Hello Jes,

I’ll check with the team but I don’t think there is a way to do multiple Modbus requests at once, for different register groups

A.

Hello again :slight_smile:
Not being able to just queue all the modbus reads at once will complicate things quite a bit. Instead I consider to just configure the cyclic polling intervals for 1 second and then just let it timeout when the IO devices are off.
I don’t think this is pretty but the code becomes much simpler as I can handle everything from within a relatively small edge action. If I could just have a single handle for switiching the cycling polling on and off, this approach could become prettier as well. Can I write to the modbus configuration from an edge action or is there a better way to achieve this?

/Jes

Technically speaking, you can write to the modbus/config from an Edge Action, but I would not necessarily recommend that approach.

How many resource groups do you want to read ?
If there are not too many, it would be good to be able to programmatically sequence the system using the modbus/request “Read” approach

Hi Jes,

As long as your device is running Octave version 3.0.0 or greater, you can make multiple asynchronous read or write requests in a single push to server/request/send. The requests simply need to be in an array:

`[{<request 0>}, {<request 1>}, ... {<request N>}]`

The result will arrive at server/request/result in a single push, after all requests have been attempted. The individual results will also be an array:

`[{<result 0>}, {<result 1>}, ... {<result N>}]`

NOTE: It is recommended to use the "id" field in the request/response to reliably match a result to a request.

Thanks,
Ian

1 Like

Hi Amons,

I just tried implementing an EA for setting the refresh rate based on the IO3 state. It actually seems to work very nice. I do understand that it may not quite reflect the intentions you had when designing the system but I really like that it takes very little custom code.

I will also give Ian’s approach with multiple asynchronous requests a go. Perhaps it will be quite straightforward as well. Thanks for the suggestion, Ian.