Page 1 of 1

Modbus slave byte ordering

Posted: Fri Apr 14, 2023 6:14 am
by Delffiini
Hi,

I made ModbusTCP slave based on the esp-idf examples.

It works but the floating point byte order is not understood by the connected Modbus master.

I need to make an extra data array just for the Modbus data transfer. Is there any way just change the byte order in esp-idf Modbus library?

This is my solution at the moment:
  1. void DataExchange::updateModbusArray()
  2. {
  3.     for(int i=0; i < _numElements; i++)
  4.     {
  5.         _modbusArray[i*4+0] = *((char*)_dataArray + i*4+2);
  6.         _modbusArray[i*4+1] = *((char*)_dataArray + i*4+3);
  7.         _modbusArray[i*4+2] = *((char*)_dataArray + i*4+0);
  8.         _modbusArray[i*4+3] = *((char*)_dataArray + i*4+1);
  9.     }
  10. }
BR, Ilkka

Re: Modbus slave byte ordering

Posted: Fri Apr 14, 2023 9:35 am
by MicroController
Is there any way just change the byte order in esp-idf Modbus library?
There may be, cf. viewtopic.php?f=2&t=23040

Re: Modbus slave byte ordering

Posted: Wed Apr 19, 2023 7:47 am
by Delffiini
Hi,I cannot edit the esp-idf managed component directly. Is there any other way..?

Just mean the function :

Code: Select all

static esp_err_t mbc_serial_master_get_parameter(uint16_t cid, char* name, uint8_t* value_ptr, uint8_t *type)