Giter Club home page Giter Club logo

Comments (6)

corneliusclaussen avatar corneliusclaussen commented on July 22, 2024

The original implementation returned immediately when the expected number of bytes were received, it only waited for the timeout if bytes were missing. Not sure if that broke with a recent commit or so

from everest-core.

barsnick avatar barsnick commented on July 22, 2024

I believe this check:

// do we have space in the rx buffer left?
if (bytes_read_total >= rxbuf_len) {
// no buffer space left, but more to read.
break;
}

should be done after this block, not before:
int bytes_read = read(fd, rxbuf + bytes_read_total, rxbuf_len - bytes_read_total);
if (bytes_read > 0) {
bytes_read_total += bytes_read;
}

Because, in the current code, if you have reached the buffer space limit, you wait one more select timeout to break out of the loop, instead of breaking out immediately (since no more data is being read anyway).

This is just a visual review, untested.

from everest-core.

golovasteek avatar golovasteek commented on July 22, 2024

As far as I see we always request the response of the maximum possible size

uint8_t rxbuf[MODBUS_MAX_REPLY_SIZE];
int bytes_read_total = read_reply(rxbuf, sizeof(rxbuf));

So we always will wait for time out if we want shorter response.

from everest-core.

corneliusclaussen avatar corneliusclaussen commented on July 22, 2024

As far as I see we always request the response of the maximum possible size

uint8_t rxbuf[MODBUS_MAX_REPLY_SIZE];
int bytes_read_total = read_reply(rxbuf, sizeof(rxbuf));

So we always will wait for time out if we want shorter response.

The read_reply function will not always fill the buffer, it is just the maximum size

from everest-core.

corneliusclaussen avatar corneliusclaussen commented on July 22, 2024

Because, in the current code, if you have reached the buffer space limit, you wait one more select timeout to break out of the loop, instead of breaking out immediately (since no more data is being read anyway).

This is just a visual review, untested.

Correct, this should be fixed. It should however only occur on transfers with 261 bytes, everything smaller will always have the "within_message_timeval" message timeout

from everest-core.

corneliusclaussen avatar corneliusclaussen commented on July 22, 2024

The default is configurable with a default of 100ms. In many implementations this can probably be reduced quite a bit, but I do not have enough hardware to find a good value. It is the inter character timeout once the peer started to send the reply message. It should be really quick.
If we want to make it faster we would need to calculate before hand how many bytes the reply should be, then we can stop immediatly when those are received without waiting until nothing more is received. We would however need to deal with modbus devices that just send more bytes then expected (this happens).

So for now I'd suggest to just reduce the 100ms timeout in your config if that is too long. You should be able to keep the initial timeout on a larger value. My guess is your power meter takes a long time to respond, but once it has sent the first bytes it will be quick sending the remaining bytes right?

In this case, it should not always wait for the first timeout:

The select should return whenever there is at least one byte available for reading, then the reading should not block and return some bytes (let's assume it was the complete reply).
The loop runs again, waiting for select (but now with the shorter timeout). If that times out, we assume there are no more bytes coming and return.

So there is always the "within_message_timeout_ms" timeout at the end, but it is not very easy to get rid of this one, as the read_reply does not know how many bytes to read. But since this is short, I do not think it is an issue.

@golovasteek Did you find another solution in the mean time? Would that resolve your issue?

from everest-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.