wglockner (Customer) asked a question.

I am receiving a timeout error while trying to connect the SL4848-CR using Modbus RTU and RS485 with the P1AM-200.

I am trying to change the analog high and low registers. After writing code with Arduino IDE that creates the client and then attempts to write to the registers, I receive a timeout error. I thought it could be a register offset issue by I have no luck with that. I am able to compile the code and send it to the PLC but when the write command is given, I receive the error. I have included my code below. The exact error reads: Failed to write heater-1 for Analog High Adjustment Connection timed out". Any help would be appreciated.

 

 

#include <P1AM.h>

#include <ArduinoRS485.h>

#include <ArduinoModbus.h>

 

 #define HEATER_1_ADDRESS 1

 #define HEATER_2_ADDRESS 2

 #define HEATER_3_ADDRESS 3

 #define HEATER_4_ADDRESS 4

 #define ON_LINE_CONFIGURATION_ADDR 2065

 #define ANALOG_HIGH_ADJUSTMENT_ADDR 0xAC55//44117

 #define ANALOG_LOW_ADJUSTMENT_ADDR 44118

 #define OUTOUT_1_LEVEL_ADDR 44115

 #define HEATING_PERIOD_ADDR 1

 unsigned long long data;

 

void setup() {

  Serial.begin(9600);

  while (!Serial);

  Serial.println("Modbus RTU Client Toggle");

 

  // start the Modbus RTU client

  if (!ModbusRTUClient.begin(9600)) {

    Serial.println("Failed to start Modbus RTU Client!");

    while (1);

  }

  // for (heater) id 1: write the value of 0x14ED which is 5357 * 2.8uA or ~15mA,

  // to the holding register at address 0xAC55 for Analog High Adjustment

  if (!ModbusRTUClient.holdingRegisterWrite(HEATER_1_ADDRESS, ANALOG_HIGH_ADJUSTMENT_ADDR, 0x0000)) {

    Serial.print("Failed to write Failed to write heater-1 for Analog High Adjustment");

    Serial.println(ModbusRTUClient.lastError());

  }

}


wglockner likes this.
  • FACTS_AdamC (AutomationDirect)

    I would check first that your serial configuration settings match between the P1AM side and the SL4848-CR.

     

    Your P1AM settings are currently 9600 baud, 8 data bits, no parity, and 1 stop bit

    The defaults listed in chapter 7 of the SL4848-CR manual are 9600 baud, 7 data bits, Even parity, and 1 stop bit.

     

    Selected as Best
  • FACTS_AdamC (AutomationDirect)

    I would check first that your serial configuration settings match between the P1AM side and the SL4848-CR.

     

    Your P1AM settings are currently 9600 baud, 8 data bits, no parity, and 1 stop bit

    The defaults listed in chapter 7 of the SL4848-CR manual are 9600 baud, 7 data bits, Even parity, and 1 stop bit.

     

    Selected as Best
    • pauljurczak (Customer)

      What about:

       

      When using the P1AM Serial with a library that has its own begin() function, i.e. ArduinoModbus, manually configure the mode of the ports with serial_port_config() before calling the library's begin() function.

       

      and this code:

      1. #include <P1AM_Serial.h>
      2.  
      3. ModbusRTUClientClass rtu_client(Port1); // Create modbus client on port 1
      4.  
      5. void setup() {
      6.  
      7. serial_port_config(1, RS232_MODE); // Set port 1 to RS232 prior to starting modbus client
      8.  
      9. rtu_client.begin(115200); // Start modbus client on port 1
      10. }

      from https://github.com/facts-engineering/P1AM_Serial? The code posted above had none of that.

      Expand Post
      • FACTS_AdamC (AutomationDirect)

        Explicitly doing so like you suggest is probably more proper and is certainly more readable. However in this case, it actually isn't needed. The Arduino Modbus library automatically creates ModbusRTUClient in the library and defaults to using port1 for serial. Since the P1AM-Serial hardware defaults to using RS485 anyway, the OP's code will end up working without some of the config you suggest.

        Expand Post