gleasontech (Customer) asked a question.

problems connecting P1AM-100, with P1AM-100-ETH module to HM1: CM5-T7W , getting PLC-001: PLC Communication Timeout error, the only thing that I change was IP address, and MAC address from ETH module
  1. /*
  2. Modbus TCP Server for P1AM-ETH with
  3. access to P1 Input/Output Modules
  4. This sketch creates a Modbus TCP Server for up to 8 connections.
  5. Slot1 Inputs are mapped to Modbus Input Bits 100001 to 100008.
  6. Slot2 Outputs are controlled by Modbus Coil Bits 000001 to 000008.
  7. Modbus Holding Register 400001 is always incrementing.
  8. The P1AM-100 cpu will require external 24vdc power
  9. for the IO modules to function. This example uses
  10. Serial.print() to display status information. The
  11. Serial Monitor must be running for the sketch to start.
  12. Required Libraries which need to be installed.
  13. https://github.com/arduino-libraries/ArduinoModbus
  14. https://github.com/arduino-libraries/ArduinoRS485
  15. use left side serial port
  16. 01/04/2025 5:00PM
  17. */
  18.  
  19. #include <SPI.h>
  20. #include <Ethernet.h>
  21. #include <P1AM.h>
  22.  
  23. #include <ArduinoRS485.h> // ArduinoModbus depends on the ArduinoRS485 library
  24. #include <ArduinoModbus.h>
  25.  
  26. byte mac[] = { //Use the �Reserved MAC� printed on the right-side label of your P1AM-ETH.
  27. 0x60, 0x52, 0xD0, 0x08, 0x17, 0x47
  28. };
  29. IPAddress ip(192,168,1,177); //IP Address of the P1AM-ETH module.
  30. boolean MB_C[16]; //Modbus Coil Bits
  31. boolean MB_I[16]; //Modbus Input Bits
  32. int MB_HR[16]; //Modbus Holding Registers
  33. int MB_IR[16]; //Modbus Input Registers
  34.  
  35. EthernetServer server(502);
  36. EthernetClient clients[8];
  37. ModbusTCPServer modbusTCPServer;
  38. int client_cnt;
  39.  
  40. void setup() {
  41. Serial.begin(115200);
  42. while (!Serial){}// wait for serial port to connect.
  43. Serial.println("Modbus TCP Server and Module I/O Example");
  44. while (!P1.init()){} ; //Wait for P1 Modules to Sign on
  45. Ethernet.begin(mac, ip);
  46. server.begin(); // start the server to begin listening
  47.  
  48. if (!modbusTCPServer.begin()) { // start the Modbus TCP server
  49. Serial.println("Failed to start Modbus TCP Server!");
  50. while (1); //If it can't be started no need to contine, stay here forever.
  51. }
  52.  
  53. modbusTCPServer.configureCoils(0x00, 16); //Coils
  54. modbusTCPServer.configureDiscreteInputs(0x00, 16); //Discrete Inputs
  55. modbusTCPServer.configureHoldingRegisters(0x00, 16); //Holding Register Words
  56. modbusTCPServer.configureInputRegisters(0x00, 16); //Input Register Words
  57.  
  58. Serial.println("Done with setup()");
  59. }
  60.  
  61. void loop() {
  62. EthernetClient newClient = server.accept(); //listen for incoming clients
  63. if (newClient) { //process new connection if possible
  64. for (byte i = 0; i < 8; i++) { //Eight connections possible, find first available.
  65. if (!clients[i]) {
  66. clients[i] = newClient;
  67. client_cnt++;
  68. Serial.print("Client Accept:"); //a new client connected
  69. Serial.print(newClient.remoteIP());
  70. Serial.print(" , Total:");
  71. Serial.println(client_cnt);
  72. break;
  73. }
  74. }
  75. }
  76.  
  77. //If there are packets available, receive them and process them.
  78. for (byte i = 0; i < 8; i++) {
  79. if (clients[i].available()) { //if data is available
  80. modbusTCPServer.accept(clients[i]); //accept that data
  81. modbusTCPServer.poll();// service any Modbus TCP requests, while client connected
  82. }
  83. }
  84. for (byte i = 0; i < 8; i++) { // Stop any clients which are disconnected
  85. if (clients[i] && !clients[i].connected()) {
  86. clients[i].stop();
  87. client_cnt--;
  88. Serial.print("Client Stopped, Total: ");
  89. Serial.println(client_cnt);
  90. }
  91. }
  92.  
  93. //Read from P1-08SIM Input Module and then write into Modbus memory
  94. int Slot1_Inputs = P1.readDiscrete(1,0); //Read from P1-08SIM Input Simulator Module
  95. for (int i=0;i<8;i++){
  96. MB_I[i]=Slot1_Inputs&(1<<i);
  97. }
  98. updateInputs(); //Write current state of the Modbus Inputs into MB_I[]
  99.  
  100. //Read from Analog Input Modules and then write into Modbus memory
  101. updateInputRegisters(); //Write current state of the Modbus Inputs into MB_IR[]
  102.  
  103. updateCoils(); //Read current state of the Modbus Coils into MB_C[]
  104. for (int i=0;i<8;i++){
  105. P1.writeDiscrete(MB_C[i],2,i+1);//Data,Slot,Channel ... Channel is one-based.
  106. }
  107. updateHoldingRegisters(); //Read current state of the Modbus Registers into MB_HR[]
  108. MB_HR[0]++; //TestApp, increment the Modbus Register 400000 just to have data changing.
  109. modbusTCPServer.holdingRegisterWrite(0,MB_HR[0]);
  110. }
  111.  
  112. void updateCoils() {//Read the Coil bits from the Modbus Library
  113. for (int i=0;i<16;i++){
  114. MB_C[i] = modbusTCPServer.coilRead(i);
  115. }
  116. }
  117.  
  118. void updateInputs() { //Write the Input bits to the Modbus Library
  119. for (int i=0;i<16;i++){
  120. modbusTCPServer.discreteInputWrite(i,MB_I[i]);
  121. }
  122. }
  123.  
  124. void updateHoldingRegisters() {//Read the Holding Register words from the Modbus Library
  125. for (int i=0;i<16;i++){
  126. MB_HR[i] = modbusTCPServer.holdingRegisterRead(i);
  127. }
  128. }
  129.  
  130. void updateInputRegisters() { //Write the Input Registers to the Modbus Library
  131. for (int i=0;i<16;i++){
  132. modbusTCPServer.inputRegisterWrite(i,MB_IR[i]);
  133. }
  134. }

P1AM-ETH moduleCmore-CM5-T7W com setup to P1AM-100


  • ADC TechnologyGroup_01 (AutomationDirect)

    You have changed the P1AM-ETH from 192.168.1.177 to now 192.168.2.177

    But the C-more is trying to connect to 192.168.1.177

     

    So you have caused yourself further problems now because the devices are on different subnets.

     

    https://reference.arduino.cc/reference/en/libraries/ethernet/ethernet.begin/

    Ethernet.begin(mac);

    Ethernet.begin(mac, ip);

    Ethernet.begin(mac, ip, dns);

    Ethernet.begin(mac, ip, dns, gateway);

    Ethernet.begin(mac, ip, dns, gateway, subnet);

     

    subnet: the subnet mask of the network (array of 4 bytes). optional: defaults to 255.255.255.0

     

    Please make these changes and transfer both projects to the devices:

    P1AM-100:

    Change Line#29 back to: "IPAddress ip(192,168,1,177); //IP Address of the P1AM-ETH module."

     

    C-more:

    Setup>Panel Network>Ethernet Port, Enable "Save setting to Project"

    Ethernet Port 1 > "Use the following IP Address" > "192.168.1.178" "255.255.255.0"

     

    Additional Questions:

    Q1) How are you connecting to the C-more? USB/Ethernet?

    Q2) Is your PC on the 192.168.x.x subnet?

    Q3) Can you ping the P1AM-ETH at 192.168.1.177

    Q4) Can you ping the C-more at 192.168.1.178

    Q5) What are the results from the C-more System Screen "PLC Enquiry Test"? https://cdn.automationdirect.com/static/manuals/cm5userm/ch5.pdf

    Page 5-31

    Expand Post
    Selected as Best
  • FACTS_AdamC (AutomationDirect)

    On the C-more side change the Slave number to 255

    or

    On the Arduino side, change to "modbusTCPServer.begin(1)" to set the ID

  • gleasontech (Customer)

    hi Adam,

    I tried your suggestion, neither works for me?

    /*

      Modbus TCP Server for P1AM-ETH with

      access to P1 Input/Output Modules

      This sketch creates a Modbus TCP Server for up to 8 connections.

      Slot1 Inputs are mapped to Modbus Input Bits 100001 to 100008.

      Slot2 Outputs are controlled by Modbus Coil Bits 000001 to 000008.

      Modbus Holding Register 400001 is always incrementing.

      The P1AM-100 cpu will require external 24vdc power

      for the IO modules to function.  This example uses

      Serial.print() to display status information.  The

      Serial Monitor must be running for the sketch to start.

      Required Libraries which need to be installed.

      https://github.com/arduino-libraries/ArduinoModbus

      https://github.com/arduino-libraries/ArduinoRS485

      use left side serial port

      01/06/2025 5:09PM

    */

     

    #include <SPI.h>

    #include <Ethernet.h>

    #include <P1AM.h>

     

    #include <ArduinoRS485.h> // ArduinoModbus depends on the ArduinoRS485 library

    #include <ArduinoModbus.h>

     

    byte mac[] = { //Use the �Reserved MAC� printed on the right-side label of your P1AM-ETH.

      0x60, 0x52, 0xD0, 0x08, 0x17, 0x47

    };

    IPAddress ip(192,168,1,177); //IP Address of the P1AM-ETH module.

    boolean MB_C[16]; //Modbus Coil Bits

    boolean MB_I[16]; //Modbus Input Bits

    int MB_HR[16];    //Modbus Holding Registers

    int MB_IR[16];    //Modbus Input Registers

     

    EthernetServer server(502);

    EthernetClient clients[8];

    ModbusTCPServer modbusTCPServer;

    int client_cnt;

     

    void setup() {

      Serial.begin(115200);

      while (!Serial){}// wait for serial port to connect.

      Serial.println("Modbus TCP Server and Module I/O Example");

      while (!P1.init()){} ; //Wait for P1 Modules to Sign on  

      Ethernet.begin(mac, ip);

      server.begin(); // start the server to begin listening

     

      if (!modbusTCPServer.begin(1)) { // start the Modbus TCP server

        Serial.println("Failed to start Modbus TCP Server!");

        while (1); //If it can't be started no need to contine, stay here forever.

      }

     

      modbusTCPServer.configureCoils(0x00, 16);             //Coils

      modbusTCPServer.configureDiscreteInputs(0x00, 16);    //Discrete Inputs

      modbusTCPServer.configureHoldingRegisters(0x00, 16); //Holding Register Words

      modbusTCPServer.configureInputRegisters(0x00, 16);   //Input Register Words

     

      Serial.println("Done with setup()");

    }

     

    void loop() {

        EthernetClient newClient = server.accept(); //listen for incoming clients

        if (newClient) { //process new connection if possible

        for (byte i = 0; i < 8; i++) { //Eight connections possible, find first available.

          if (!clients[i]) {

            clients[i] = newClient;

            client_cnt++;

            Serial.print("Client Accept:"); //a new client connected

            Serial.print(newClient.remoteIP());

            Serial.print(" , Total:");

            Serial.println(client_cnt);

            break;

            }

          }

        }

     

        //If there are packets available, receive them and process them.

        for (byte i = 0; i < 8; i++) {

          if (clients[i].available()) { //if data is available

            modbusTCPServer.accept(clients[i]); //accept that data

            modbusTCPServer.poll();// service any Modbus TCP requests, while client connected

            }

        }

        for (byte i = 0; i < 8; i++) { // Stop any clients which are disconnected

          if (clients[i] && !clients[i].connected()) {

            clients[i].stop();

            client_cnt--;

            Serial.print("Client Stopped, Total: ");

            Serial.println(client_cnt);

          }

        }

     

      //Read from P1-08SIM Input Module and then write into Modbus memory

      int Slot1_Inputs = P1.readDiscrete(1,0);  //Read from P1-08SIM Input Simulator Module

      for (int i=0;i<8;i++){

        MB_I[i]=Slot1_Inputs&(1<<i);

      }

      updateInputs(); //Write current state of the Modbus Inputs into MB_I[]

     

      //Read from Analog Input Modules and then write into Modbus memory

      updateInputRegisters(); //Write current state of the Modbus Inputs into MB_IR[]

     

      updateCoils(); //Read current state of the Modbus Coils into MB_C[]

      for (int i=0;i<8;i++){

        P1.writeDiscrete(MB_C[i],2,i+1);//Data,Slot,Channel ... Channel is one-based.

      }

     

      updateHoldingRegisters(); //Read current state of the Modbus Registers into MB_HR[]

      MB_HR[0]++; //TestApp, increment the Modbus Register 400000 just to have data changing.

      modbusTCPServer.holdingRegisterWrite(0,MB_HR[0]);

    }

     

    void updateCoils() {//Read the Coil bits from the Modbus Library

      for (int i=0;i<16;i++){

        MB_C[i] = modbusTCPServer.coilRead(i);

      }

    }

     

    void updateInputs() { //Write the Input bits to the Modbus Library

      for (int i=0;i<16;i++){

        modbusTCPServer.discreteInputWrite(i,MB_I[i]);

      }

    }

     

    void updateHoldingRegisters() {//Read the Holding Register words from the Modbus Library

      for (int i=0;i<16;i++){

        MB_HR[i] = modbusTCPServer.holdingRegisterRead(i);

      }

    }

     

    void updateInputRegisters() { //Write the Input Registers to the Modbus Library

      for (int i=0;i<16;i++){

        modbusTCPServer.inputRegisterWrite(i,MB_IR[i]);

      }

    }

     

     

    Expand Post
  • ADC TechnologyGroup_01 (AutomationDirect)

    What is the IP Address of C-more?

    After loading the sketch you are opening the Arduino Serial Monitor?

    "This example uses Serial.print() to display status information. The Serial Monitor must be running for the sketch to start."

    If you are opening the Serial Monitor, what is it displaying?

    • FACTS_AdamC (AutomationDirect)

      Could you provide the IP settings of the C-more panel?

       

    • FACTS_AdamC (AutomationDirect)

      The C-more and P1AM should not have the same IP address. You should change either one of them to a free address and see if that corrects the issue.

  • gleasontech (Customer)

    1. /*
    2. Modbus TCP Server for P1AM-ETH with
    3. access to P1 Input/Output Modules
    4. This sketch creates a Modbus TCP Server for up to 8 connections.
    5. Slot1 Inputs are mapped to Modbus Input Bits 100001 to 100008.
    6. Slot2 Outputs are controlled by Modbus Coil Bits 000001 to 000008.
    7. Modbus Holding Register 400001 is always incrementing.
    8. The P1AM-100 cpu will require external 24vdc power
    9. for the IO modules to function. This example uses
    10. Serial.print() to display status information. The
    11. Serial Monitor must be running for the sketch to start.
    12. Required Libraries which need to be installed.
    13. https://github.com/arduino-libraries/ArduinoModbus
    14. https://github.com/arduino-libraries/ArduinoRS485
    15. use left side serial port
    16. 01/17/2025 9:29am
    17. */
    18.  
    19. #include <SPI.h>
    20. #include <Ethernet.h>
    21. #include <P1AM.h>
    22.  
    23. #include <ArduinoRS485.h> // ArduinoModbus depends on the ArduinoRS485 library
    24. #include <ArduinoModbus.h>
    25.  
    26. byte mac[] = { //Use the �Reserved MAC� printed on the right-side label of your P1AM-ETH.
    27. 0x60, 0x52, 0xD0, 0x08, 0x17, 0x47
    28. };
    29. IPAddress ip(192,168,2,177); //IP Address of the P1AM-ETH module.
    30. boolean MB_C[16]; //Modbus Coil Bits
    31. boolean MB_I[16]; //Modbus Input Bits
    32. int MB_HR[16]; //Modbus Holding Registers
    33. int MB_IR[16]; //Modbus Input Registers
    34.  
    35. EthernetServer server(502);
    36. EthernetClient clients[8];
    37. ModbusTCPServer modbusTCPServer;
    38. int client_cnt;
    39.  
    40. void setup() {
    41. Serial.begin(115200);
    42. while (!Serial){}// wait for serial port to connect.
    43. Serial.println("Modbus TCP Server and Module I/O Example");
    44. while (!P1.init()){} ; //Wait for P1 Modules to Sign on
    45. Ethernet.begin(mac, ip);
    46. server.begin(); // start the server to begin listening
    47.  
    48. if (!modbusTCPServer.begin()) { // start the Modbus TCP server
    49. Serial.println("Failed to start Modbus TCP Server!");
    50. while (1); //If it can't be started no need to contine, stay here forever.
    51. }
    52.  
    53. modbusTCPServer.configureCoils(0x00, 16); //Coils
    54. modbusTCPServer.configureDiscreteInputs(0x00, 16); //Discrete Inputs
    55. modbusTCPServer.configureHoldingRegisters(0x00, 16); //Holding Register Words
    56. modbusTCPServer.configureInputRegisters(0x00, 16); //Input Register Words
    57.  
    58. Serial.println("Done with setup()");
    59. }
    60.  
    61. void loop() {
    62. EthernetClient newClient = server.accept(); //listen for incoming clients
    63. if (newClient) { //process new connection if possible
    64. for (byte i = 0; i < 8; i++) { //Eight connections possible, find first available.
    65. if (!clients[i]) {
    66. clients[i] = newClient;
    67. client_cnt++;
    68. Serial.print("Client Accept:"); //a new client connected
    69. Serial.print(newClient.remoteIP());
    70. Serial.print(" , Total:");
    71. Serial.println(client_cnt);
    72. break;
    73. }
    74. }
    75. }
    76.  
    77. //If there are packets available, receive them and process them.
    78. for (byte i = 0; i < 8; i++) {
    79. if (clients[i].available()) { //if data is available
    80. modbusTCPServer.accept(clients[i]); //accept that data
    81. modbusTCPServer.poll();// service any Modbus TCP requests, while client connected
    82. }
    83. }
    84. for (byte i = 0; i < 8; i++) { // Stop any clients which are disconnected
    85. if (clients[i] && !clients[i].connected()) {
    86. clients[i].stop();
    87. client_cnt--;
    88. Serial.print("Client Stopped, Total: ");
    89. Serial.println(client_cnt);
    90. }
    91. }
    92.  
    93. //Read from P1-08SIM Input Module and then write into Modbus memory
    94. int Slot1_Inputs = P1.readDiscrete(1,0); //Read from P1-08SIM Input Simulator Module
    95. for (int i=0;i<8;i++){
    96. MB_I[i]=Slot1_Inputs&(1<<i);
    97. }
    98. updateInputs(); //Write current state of the Modbus Inputs into MB_I[]
    99.  
    100. //Read from Analog Input Modules and then write into Modbus memory
    101. updateInputRegisters(); //Write current state of the Modbus Inputs into MB_IR[]
    102.  
    103. updateCoils(); //Read current state of the Modbus Coils into MB_C[]
    104. for (int i=0;i<8;i++){
    105. P1.writeDiscrete(MB_C[i],2,i+1);//Data,Slot,Channel ... Channel is one-based.
    106. }
    107. updateHoldingRegisters(); //Read current state of the Modbus Registers into MB_HR[]
    108. MB_HR[0]++; //TestApp, increment the Modbus Register 400000 just to have data changing.
    109. modbusTCPServer.holdingRegisterWrite(0,MB_HR[0]);
    110. }
    111.  
    112. void updateCoils() {//Read the Coil bits from the Modbus Library
    113. for (int i=0;i<16;i++){
    114. MB_C[i] = modbusTCPServer.coilRead(i);
    115. }
    116. }
    117.  
    118. void updateInputs() { //Write the Input bits to the Modbus Library
    119. for (int i=0;i<16;i++){
    120. modbusTCPServer.discreteInputWrite(i,MB_I[i]);
    121. }
    122. }
    123.  
    124. void updateHoldingRegisters() {//Read the Holding Register words from the Modbus Library
    125. for (int i=0;i<16;i++){
    126. MB_HR[i] = modbusTCPServer.holdingRegisterRead(i);
    127. }
    128. }
    129.  
    130. void updateInputRegisters() { //Write the Input Registers to the Modbus Library
    131. for (int i=0;i<16;i++){
    132. modbusTCPServer.inputRegisterWrite(i,MB_IR[i]);
    133. }
    134. }

    Hi... I'm still having trouble connecting P1AM-100 TO CM5-T7W, I have included latest C code, along with c-more coms protocol, screen shot, along with P!AM-100 serial monitor display after booting up, the ether-net cable is Automation Direct #C5E-STPGY-S3, all component are brand new , thanks... Mick

    Screenshot 2025-01-17 serial monitor display Screenshot 2025-01-17 c-more coms protocol

    Expand Post
    • ADC TechnologyGroup_01 (AutomationDirect)

      You have changed the P1AM-ETH from 192.168.1.177 to now 192.168.2.177

      But the C-more is trying to connect to 192.168.1.177

       

      So you have caused yourself further problems now because the devices are on different subnets.

       

      https://reference.arduino.cc/reference/en/libraries/ethernet/ethernet.begin/

      Ethernet.begin(mac);

      Ethernet.begin(mac, ip);

      Ethernet.begin(mac, ip, dns);

      Ethernet.begin(mac, ip, dns, gateway);

      Ethernet.begin(mac, ip, dns, gateway, subnet);

       

      subnet: the subnet mask of the network (array of 4 bytes). optional: defaults to 255.255.255.0

       

      Please make these changes and transfer both projects to the devices:

      P1AM-100:

      Change Line#29 back to: "IPAddress ip(192,168,1,177); //IP Address of the P1AM-ETH module."

       

      C-more:

      Setup>Panel Network>Ethernet Port, Enable "Save setting to Project"

      Ethernet Port 1 > "Use the following IP Address" > "192.168.1.178" "255.255.255.0"

       

      Additional Questions:

      Q1) How are you connecting to the C-more? USB/Ethernet?

      Q2) Is your PC on the 192.168.x.x subnet?

      Q3) Can you ping the P1AM-ETH at 192.168.1.177

      Q4) Can you ping the C-more at 192.168.1.178

      Q5) What are the results from the C-more System Screen "PLC Enquiry Test"? https://cdn.automationdirect.com/static/manuals/cm5userm/ch5.pdf

      Page 5-31

      Expand Post
      Selected as Best