Skip to content

esp-modbus v1 master read airflow abnormal (EPROT-13) #144

@yel-best

Description

@yel-best

Checklist

  • Checked the issue tracker for similar issues to ensure this is not a duplicate.
  • Provided a clear description of your suggestion.
  • Included any relevant context or examples.

Issue or Suggestion Description

use esp-modbus v1.0.13

ESP32S3 acts as a host to read the data of a device whose slave is an air pressure flow meter. It mainly reads the accumulated flow value of the device. The accumulated flow value is divided into high and low bits.

R 40009-10 0x08 2 SINGLE Hundreds of cumulative traffic
R 40011-12 0x0A 2 SINGLE Hundredth digit of cumulative traffic

Cumulative flow = cumulative amount above the hundredth place x 100 + cumulative amount below the hundredth place

But in actual situations, I use the following when defining the number:

     HOLD_OFFSET(holding_data0), PARAM_TYPE_FLOAT_CDAB, 4, OPTS(0, 0, 0), PAR_PERMS_READ_WRITE_TRIGGER},
    {CID_AIRFLOWMETER_SCGFL, STR("SCGFL"), STR(""), MB_DEVICE_ADDR2, MB_PARAM_HOLDING, 0x0B, 2,
     HOLD_OFFSET(holding_data0), PARAM_TYPE_FLOAT_CDAB, 4, OPTS(0, 0, 0), `PAR_PERMS_READ_WRITE_TRIGGER},```


if ((param_descriptor->param_type == PARAM_TYPE_FLOAT_CDAB))
{
    if (MD_VERIFY_VALUES(param_descriptor, (float *)temp_data_ptr) == ESP_OK)
    {
        TriphasePowerValue.meterMODBUSStatus = true;
        ESP_LOGW(TAG, "Characteristic #%d %s (%s) value = %.0f (0x%" PRIx32 ") read successful.",
                 (int)param_descriptor->cid,
                 (char *)param_descriptor->param_key,
                 (char *)param_descriptor->param_units,
                 *(float *)temp_data_ptr,
                 *(uint32_t *)temp_data_ptr);

        current_value = *(float *)temp_data_ptr;
    }
    else
    {
        TriphasePowerValue.meterMODBUSStatus = false;
    }
}`

` case CID_AIRFLOWMETER_SFRI:
          airflowmetervalue.airflowmeter_sfri = round(current_value * 3600 * 1000) / 1000;
          ESP_LOGD(TAG, "MB readings stored: for SFRI with value: %f", airflowmetervalue.airflowmeter_sfri);
          break;
case CID_AIRFLOWMETER_SCGFH:
    airflowmetervalue.airflowmeter_scgfh = round(current_value) * 100.0f;
    ESP_LOGW(TAG, "MB readings stored: for SCGFH with value: %.2f", airflowmetervalue.airflowmeter_scgfh);
    break;
case CID_AIRFLOWMETER_SCGFL:
    airflowmetervalue.airflowmeter_scgfl = round(current_value * 100.0f) / 100;
    ESP_LOGW(TAG, "MB readings stored: for SCGFL with value: %.2f", airflowmetervalue.airflowmeter_scgfl);
    airflowmetervalue.airflowmeter_cfr = airflowmetervalue.airflowmeter_scgfh + airflowmetervalue.airflowmeter_scgfl;
    ESP_LOGW(TAG, "MB readings stored: for CFR with value: %.2f", airflowmetervalue.airflowmeter_cfr);
        break;

The following is the result of the reading, which will be large or small. In fact, when using modbus pull to read, the high-order value is 3351 and there is no change. Only the value below the hundredth digit increases by 10.75...20.75.

Image

please help me

Data format of air pressure flow meter

The data format in the protocol is floating-point. Modbus sends the most significant word first. The data encoding order in this protocol is 3412, and the decoding order is 1234.
32 single-precision floating-point numbers are formatted according to IEEE 754, equivalent to 4 bytes, in the order 3-4-1-2.
After decoding into the order 1-2-3-4, the bits (most significant to least significant) are 31, 30, 29, ..., and 0.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions