smarmengol / Modbus-Master-Slave-for-Arduino

Modbus Master-Slave library for Arduino
GNU Lesser General Public License v2.1
473 stars 328 forks source link

How to read coils? #49

Closed pxnky closed 4 years ago

pxnky commented 4 years ago

Hi,

I am successfully able to write values to this sketch from a USB to RS485 converter connected to a Mac and using the python pymodbus REPL. The problem is I am not able to read the values back in any way, am I doing something wrong?

When I try to read the arduino resets (millis starts over) and I don't get a response ever on the master side.

#include <ModbusRtu.h>
#include <openGLCD.h>

#define TXEN  53

Modbus bus;
uint16_t modbus_array[5];

void setup() {
  // put your setup code here, to run once:
  GLCD.Init();
  GLCD.SelectFont(System5x7);
  GLCD.CursorTo(0, 0);

  bus = Modbus(1,0,TXEN);

  bus.begin(19200);

}

void loop() {
  modbus_array[5] = modbus_array[5] + 1;
  bus.poll(modbus_array,sizeof(modbus_array)/sizeof(modbus_array[0]));

  GLCD.print("Clock time: ");
  GLCD.print(millis());
  GLCD.print("\n0 = ");
  GLCD.print(modbus_array[0]);
  GLCD.print("\n1 = ");
  GLCD.print(modbus_array[1]);
  GLCD.print("\n2 = ");
  GLCD.print(modbus_array[2]);
  GLCD.print("\n3 = ");
  GLCD.print(modbus_array[3]);
  GLCD.print("\n4 = ");
  GLCD.print(modbus_array[4]);
  GLCD.print("\n5 = ");
  GLCD.print(modbus_array[5]);
  GLCD.CursorTo(0, 0);
}

Trying to read:

> client.read_discrete_inputs address=1 count=1 unit=1
{
    "original_function_code": "2 (0x2)",
    "error": "[Input/Output] No Response received from the remote unit/Unable to decode response"
}

> client.read_coils address=1 count=5 unit=1
{
    "original_function_code": "1 (0x1)",
    "error": "[Input/Output] No Response received from the remote unit/Unable to decode response"
}
smarmengol commented 4 years ago

I don't support anything outside the Modbus library and I don't know this "python pymodbus REPL" software.