Modbus wont compile for Teknic Clearcore

I have been trying to get modbus TCP to work on a teknic clearcore to control a VSD on a CNC.
I uploaded the example modbus tcp sketch from the arduino Modbus library and if I set the board to any standard arduino board it compiles fine but if I set it to the teknic board it wont compile. with the below error
I am trying to use the ethernet port to run tcp/ip because I need the other com ports for other coms. I Have managed to open a connection with the drive over ethernet but I get problems when I try to introduce the ArduinoModbus library.
Can anyone point me in the right direction?

Heres the example code


/*
  Ethernet Modbus TCP Client Toggle

  This sketch toggles the coil of a Modbus TCP server connected
  on and off every second.

  Circuit:
   - Any Arduino MKR Board
   - MKR ETH Shield

  created 16 July 2018
  by Sandeep Mistry
*/

#include <SPI.h>
#include <Ethernet.h>

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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);

EthernetClient ethClient;
ModbusTCPClient modbusTCPClient(ethClient);

IPAddress server(192, 168, 1, 10); // update with the IP Address of your Modbus server

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);

  // Check for Ethernet hardware present
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    while (true) {
      delay(1); // do nothing, no point running without Ethernet hardware
    }
  }
  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");
  }
}

void loop() {
  if (!modbusTCPClient.connected()) {
    // client not connected, start the Modbus TCP client
    Serial.println("Attempting to connect to Modbus TCP server");
    
    if (!modbusTCPClient.begin(server, 502)) {
      Serial.println("Modbus TCP Client failed to connect!");
    } else {
      Serial.println("Modbus TCP Client connected");
    }
  } else {
    // client connected

    // write the value of 0x01, to the coil at address 0x00
    if (!modbusTCPClient.coilWrite(0x00, 0x01)) {
      Serial.print("Failed to write coil! ");
      Serial.println(modbusTCPClient.lastError());
    }

    // wait for 1 second
    delay(1000);

    // write the value of 0x00, to the coil at address 0x00
    if (!modbusTCPClient.coilWrite(0x00, 0x00)) {
      Serial.print("Failed to write coil! ");
      Serial.println(modbusTCPClient.lastError());
    }

    // wait for 1 second
    delay(1000);
  }
}

and this is the error I get

Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "Teknic ClearCore"

Arduino Sketches\libraries\ArduinoRS485\src\RS485.cpp:189:18: error: 'SERIAL_PORT_HARDWARE' was not declared in this scope
 RS485Class RS485(SERIAL_PORT_HARDWARE, RS485_DEFAULT_TX_PIN, RS485_DEFAULT_DE_PIN, RS485_DEFAULT_RE_PIN);
                  ^~~~~~~~~~~~~~~~~~~~
Arduino Sketches\libraries\ArduinoRS485\src\RS485.cpp:189:18: note: suggested alternative: 'SERIAL_PARITY_MARK'
 RS485Class RS485(SERIAL_PORT_HARDWARE, RS485_DEFAULT_TX_PIN, RS485_DEFAULT_DE_PIN, RS485_DEFAULT_RE_PIN);
                  ^~~~~~~~~~~~~~~~~~~~
                  SERIAL_PARITY_MARK
In file included from:  Arduino Sketches\libraries\ArduinoRS485\src\RS485.cpp:20:0:
Arduino Sketches\libraries\ArduinoRS485\src\RS485.h:35:30: error: 'A6' was not declared in this scope
 #define RS485_DEFAULT_DE_PIN A6
                              ^
Arduino Sketches\libraries\ArduinoRS485\src\RS485.cpp:189:62: note: in expansion of macro 'RS485_DEFAULT_DE_PIN'
 RS485Class RS485(SERIAL_PORT_HARDWARE, RS485_DEFAULT_TX_PIN, RS485_DEFAULT_DE_PIN, RS485_DEFAULT_RE_PIN);
                                                              ^~~~~~~~~~~~~~~~~~~~
Arduino Sketches\libraries\ArduinoRS485\src\RS485.h:35:30: note: suggested alternative: 'Ac'
 #define RS485_DEFAULT_DE_PIN A6
                              ^
Arduino Sketches\libraries\ArduinoRS485\src\RS485.cpp:189:62: note: in expansion of macro 'RS485_DEFAULT_DE_PIN'
 RS485Class RS485(SERIAL_PORT_HARDWARE, RS485_DEFAULT_TX_PIN, RS485_DEFAULT_DE_PIN, RS485_DEFAULT_RE_PIN);
                                                              ^~~~~~~~~~~~~~~~~~~~
Arduino Sketches\libraries\ArduinoRS485\src\RS485.h:36:30: error: 'A5' was not declared in this scope
 #define RS485_DEFAULT_RE_PIN A5
                              ^
Arduino Sketches\libraries\ArduinoRS485\src\RS485.cpp:189:84: note: in expansion of macro 'RS485_DEFAULT_RE_PIN'
 RS485Class RS485(SERIAL_PORT_HARDWARE, RS485_DEFAULT_TX_PIN, RS485_DEFAULT_DE_PIN, RS485_DEFAULT_RE_PIN);
                                                                                    ^~~~~~~~~~~~~~~~~~~~
Arduino Sketches\libraries\ArduinoRS485\src\RS485.h:36:30: note: suggested alternative: 'Ac'
 #define RS485_DEFAULT_RE_PIN A5
                              ^
Arduino Sketches\libraries\ArduinoRS485\src\RS485.cpp:189:84: note: in expansion of macro 'RS485_DEFAULT_RE_PIN'
 RS485Class RS485(SERIAL_PORT_HARDWARE, RS485_DEFAULT_TX_PIN, RS485_DEFAULT_DE_PIN, RS485_DEFAULT_RE_PIN);
                                                                                    ^~~~~~~~~~~~~~~~~~~~

And this is this is the sketch that successfully opened a connection with the drive (well the serial monitor said it was successful anyway)

#include <Ethernet.h>


byte mac[] = { 0x24, 0x15, 0x10, 0xb0, 0x0a, 0xd9 };
byte ip[] = { 192, 168, 33, 110 };
byte server[] = { 192, 168, 33, 10 }; 
int tcp_port = 80;

EthernetClient client;

void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);

  delay(1000);

  Serial.println("Connecting...");

  if (client.connect(server, tcp_port)) { // Connection to VSD
    Serial.println("Connected to VSD");
    client.println();
  } else {
    Serial.println("connection failed");
  }
}

void loop()
{
  if (client.available()) {
    if(Serial.available()){
      char s = Serial.read();
      client.write(s); // Send what is reed on serial monitor
      char c = client.read();
      Serial.print(c); // Print on serial monitor the data from server 
    }
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}

That library isn't designed for your rather exotic hardware, so you have to adapt it a little. Just define the few things that are missing (SERIAL_PORT_HARDWARE, A6, A5) and the library should compile. These serial things aren't used anyway for a Modbus TCP setup.

Thanks for your response, I have tried to do as you've suggested but I get the same error.
code I used below.

/*
  Ethernet Modbus TCP Client Toggle

  This sketch toggles the coil of a Modbus TCP server connected
  on and off every second.

  Circuit:
   - Any Arduino MKR Board
   - MKR ETH Shield

  created 16 July 2018
  by Sandeep Mistry
*/

#include <SPI.h>
#include <Ethernet.h>

#include <ArduinoRS485.h> // ArduinoModbus depends on the ArduinoRS485 library
#include <ArduinoModbus.h>
//#define SERIAL_PORT_HARDWARE Serial1 have tried with and without this, Serial and Serial1
#define RS485_DEFAULT_TX_PIN  18
#define RS485_DEFAULT_DE_PIN  22
#define RS485_DEFAULT_RE_PIN  23

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);

EthernetClient ethClient;
ModbusTCPClient modbusTCPClient(ethClient);

IPAddress server(192, 168, 1, 10); // update with the IP Address of your Modbus server

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);

  // Check for Ethernet hardware present
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    while (true) {
      delay(1); // do nothing, no point running without Ethernet hardware
    }
  }
  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");
  }
}

void loop() {
  if (!modbusTCPClient.connected()) {
    // client not connected, start the Modbus TCP client
    Serial.println("Attempting to connect to Modbus TCP server");
    
    if (!modbusTCPClient.begin(server, 502)) {
      Serial.println("Modbus TCP Client failed to connect!");
    } else {
      Serial.println("Modbus TCP Client connected");
    }
  } else {
    // client connected

    // write the value of 0x01, to the coil at address 0x00
    if (!modbusTCPClient.coilWrite(0x00, 0x01)) {
      Serial.print("Failed to write coil! ");
      Serial.println(modbusTCPClient.lastError());
    }

    // wait for 1 second
    delay(1000);

    // write the value of 0x00, to the coil at address 0x00
    if (!modbusTCPClient.coilWrite(0x00, 0x00)) {
      Serial.print("Failed to write coil! ");
      Serial.println(modbusTCPClient.lastError());
    }

    // wait for 1 second
    delay(1000);
  }
}

I have also seen this ArduinoModbus for other shields and with different Serial port - MKR Family / MKR SHIELDS - Arduino Forum
I have tried modifying the library as described here with no luck either

Solved, use this library instead

GitHub - emelianov/modbus-esp8266: Most complete Modbus library for Arduino. A library that allows your Arduino board to communicate via Modbus protocol, acting as a master, slave or both. Supports network transport (Modbus TCP) and Serial line/RS-485 (Modbus RTU). Supports Modbus TCP Security for ESP8266/ESP32.

I get the following error when using this library and trying to upload to Teknic Clearcore. Were you able to get this working and if so, can you post project or share what you did?

Arduino: 1.8.14 (Windows 10), Board: "Teknic ClearCore"

In file included from C:\Users\jbenn\Documents\Arduino\sketch_oct06c\sketch_oct06c.ino:10:0:

C:\Users\jbenn\Documents\Arduino\libraries\modbus-esp8266-master\src/ModbusTLS.h:8:2: error: #error Unsupported architecture

#error Unsupported architecture

^~~~~

C:\Users\jbenn\Documents\Arduino\libraries\modbus-esp8266-master\src/ModbusTLS.h:10:10: fatal error: WiFiClientSecure.h: No such file or directory

#include <WiFiClientSecure.h>

      ^~~~~~~~~~~~~~~~~~~~

compilation terminated.

exit status 1

Error compiling for board Teknic ClearCore.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

The library explicitly tells you why it fails. This library doesn't support your processor architecture.

I understand that but fulstop said the library he linked solves his original question. We are using the same architecture so he must have been able to get it to work. Just wondering how he did it.

@jbenni6
You are trying to build ModbusTLS while ClearCore was tested with ModbusTCP only. You need these examples.

I will give it a try today, thank you!

It uploads and connects but I am getting a "no response" error from my HMI. In the loop, doesn't there need to be some function to send back data? What is mb.task? I can't find info on it. Thanks in advance.

void loop() {
  mb.task();                      // Common local Modbus task
  delay(10);
}

Typically 'no response' stands for wide set of network connectivity problems.
As for .task() -- its core function containing all the server functionality.

I got it to work since my last post, thank you very much!