epsilonrt / libmodbuspp

Much more than a C++ wrapper for libmodbus
https://epsilonrt.fr/modbuspp
GNU Lesser General Public License v3.0
73 stars 44 forks source link

RtuLayer::parity and RtuLayer::stop #7

Closed Uskok closed 3 years ago

Uskok commented 4 years ago

Hi,

how the following function could parse "19200N1"?

  // ---------------------------------------------------------------------------
  // static
  char RtuLayer::parity (const std::string & settings) {
    char p = 'E';
    size_t s = settings.length();

    if (s >= 2) {
      char c = settings[s - 2];
      if ( (c == 'E') || (c == 'O')) {
        return c;
      }
    }
    return p;
  }

and stop bit could be 1 or 2 independent of N

  // ---------------------------------------------------------------------------
  // static
  int RtuLayer::stop (const std::string & settings) {

    if (parity (settings) == 'N') {

      return 2;
    }
    return 1;
  }
epsilonrt commented 4 years ago

She can not ! The standard modbus OSL clearly states in paragraph "2.5.1 RTU Transmission Mode" that the absence of parity requires 2 stop bits (in order for each character to have 11 bits long).

Uskok commented 4 years ago

Thank you for the fast response. What is written in the document is nice but is not reality in the practice. My Modbus slave has parameters 19200 8N1. libModbus library allow to enter 19200 8N1 as parameters.

epsilonrt commented 4 years ago

Even parity must be provided; Could you give me the make and model of your slave?

Uskok commented 4 years ago

Thanks, the testing device: https://www.osensa.com/pdf/DATASHEET-DMK-0071A-4%20FTX-910-PWR+R.pdf

I have two additional chillers in the system both coming from the factory with the settings 19200 8N1. I am able to make small application base only on libmodbus and the communication is correct.

epsilonrt commented 4 years ago

An ISO9001 certified industrial product that does not meet the standards it uses ... the stop bit is a bit at rest, two devices not having the same setting can communicate without problem, but the minimum time between frame and maximum time between characters are set on the basis of 11bits per character.

Uskok commented 4 years ago

I changed two functions listed above and I have small running test example. Both server and device have the same setting 19200 8N1. The setting of the Osensa device I can see with origin software. I can understand your argument where you are referring to a document, but I can't understand why you are restricting something what is allowed in the libModbus library.