Leer un medidor de panel por Modbus RTU: ¿cómo se convierten 43 66 99 9A en 230.6 V?
Traducido del English por IA ·
Llevo 24 años dirigiendo plantas y nunca he tenido que decodificar una trama Modbus a mano, así que aquí estamos.Uno de nuestros técnicos de mantenimiento construyó un pequeño registrador: un Arduino Uno con una placa MAX485 que lee el medidor de panel en la línea 4 (Modbus RTU, 9600 8N1, dirección de esclavo 1). El Uno envía los valores por serie a una Raspberry Pi que los publica en Hermetry. Se marchó a otro trabajo antes de terminar la parte de decodificación.El Uno envía esta petición y recibe respuesta cada vez, así que el cableado funciona:
TX: 01 03 00 00 00 02 C4 0B
RX: 01 03 04 43 66 99 9A 3A 1E
El propio panel muestra 230.6 V en L1. No veo cómo esos bytes se convierten en 230.6. ¿Qué parte de la respuesta es el valor y cómo lo convierto en un número que pueda enviar?
24 years running plants and I have never had to decode a Modbus frame by hand, so here we are.
One of our maintenance techs built a small logger: Arduino Uno with a MAX485 board reading the panel meter on line 4 (Modbus RTU, 9600 8N1, slave address 1). The Uno passes the values over serial to a Raspberry Pi that publishes them to Hermetry. He left for a new job before finishing the decoding part.
The Uno sends this request and gets a reply every time, so the wiring works:
TX: 01 03 00 00 00 02 C4 0B
RX: 01 03 04 43 66 99 9A 3A 1E
The panel itself shows 230.6 V on L1. I can’t see how those bytes turn into 230.6. What part of the reply is the value, and how do I turn it into a number I can send?
Traducido del English por IA ·
¿43 66 es la tensión en hexadecimal? 0x4366 es 17254, ¿quizás hay que dividir entre algo?
Is 43 66 the voltage in hex? 0x4366 is 17254, so maybe divide by something?
Traducido del English por IA ·
¿De qué medidor se trata? El mapa de registros del manual indica si un valor es un float o un entero escalado.
Which meter is it? The manual’s register map says whether a value is a float or a scaled integer.
Traducido del English por IA ·
Encontré el manual en la puerta del panel. «Tensión L1, dirección 0x0000, float, 2 registros».
Found the manual in the panel door. «Voltage L1, address 0x0000, float, 2 registers.»
Traducido del English por IA ·
Entonces los 2 registros forman un float de 32 bits. Desgloso tu respuesta:
01 slave address
03 function (read holding registers)
04 byte count, 4 bytes follow
43 66 99 9A data: register 0 = 0x4366, register 1 = 0x999A
3A 1E CRC
Juntando los cuatro bytes de datos como 0x4366999A y leyéndolos como float IEEE 754: signo 0, el exponente da 2^7 = 128, la mantisa es aproximadamente 1.8016, y 128 x 1.8016 = 230.6. Así que el 0x4366 de Wilson es solo la primera mitad del float, por eso al dividir nunca sale bien.En el Uno los bytes llegan primero el más significativo, pero el AVR es little endian, así que hay que invertirlos antes de copiarlos en un float:
uint8_t b[4] = { rx[6], rx[5], rx[4], rx[3] }; // 9A 99 66 43
float v;
memcpy(&v, b, 4);
Serial.print("{"l1.voltage":");
Serial.print(v, 1);
Serial.println("}");
Algunos medidores envían los dos registros en orden inverso (word swap). Si obtienes algo como 1.2e-23 en lugar de un voltaje, intercambia rx[3..4] con rx[5..6]. Y comprueba también el CRC antes de confiar en una respuesta.
Then the 2 registers are one 32-bit float. Splitting your reply:
01 slave address
03 function (read holding registers)
04 byte count, 4 bytes follow
43 66 99 9A data: register 0 = 0x4366, register 1 = 0x999A
3A 1E CRC
Put the four data bytes together as 0x4366999A and read them as an IEEE 754 float: sign 0, exponent gives 2^7 = 128, mantissa about 1.8016, and 128 x 1.8016 = 230.6. So Wilson’s 0x4366 is the first half of the float, which is why dividing never comes out right.
On the Uno the bytes arrive most significant first but the AVR is little endian, so reverse them before copying into a float:
uint8_t b[4] = { rx[6], rx[5], rx[4], rx[3] }; // 9A 99 66 43
float v;
memcpy(&v, b, 4);
Serial.print("{"l1.voltage":");
Serial.print(v, 1);
Serial.println("}");
Some meters send the two registers the other way round (word swapped). If you ever get something like 1.2e-23 instead of a voltage, swap rx[3..4] with rx[5..6]. Check the CRC before trusting a reply too.
Traducido del English por IA ·
Vale la pena enviar un contador de errores junto con las lecturas, modbus.crc_errors o similar. En nuestras instalaciones, que ese contador subiera siempre fue la primera señal de un cable A/B suelto.
Worth sending an error counter next to the readings, modbus.crc_errors or similar. On our sites that counter going up was always the first sign of a loose A/B wire.
Traducido del English por IA ·
230,6 en el panel de control, coincide con el medidor. Pasé este hilo al técnico que se hizo cargo y añadió las otras fases y la verificación CRC en una tarde. Wilson, yo también probé primero tu idea de dividir, así que estás en buena compañía.
230.6 on the dashboard, matching the panel. I passed this thread to the tech who took over and he added the other phases and the CRC check in an afternoon. Wilson, I tried your divide idea first too, so you’re in good company.
- Debes estar registrado para responder a este debate.
Únete a la conversación
Inicia sesión para preguntar y responder, dar me gusta a las publicaciones útiles y marcar la respuesta que resolvió tu problema. Cada aportación suma puntos y niveles.

