Modbus slave byte ordering

Delffiini
Posts: 2
Joined: Fri Apr 14, 2023 6:06 am

Modbus slave byte ordering

Postby Delffiini » Fri Apr 14, 2023 6:14 am

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

MicroController
Posts: 1709
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Modbus slave byte ordering

Postby MicroController » Fri Apr 14, 2023 9:35 am

Is there any way just change the byte order in esp-idf Modbus library?
There may be, cf. viewtopic.php?f=2&t=23040

Delffiini
Posts: 2
Joined: Fri Apr 14, 2023 6:06 am

Re: Modbus slave byte ordering

Postby Delffiini » Wed Apr 19, 2023 7:47 am

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)

Who is online

Users browsing this forum: No registered users and 122 guests