Teensy4.1 Native ethernet to Delta HMI Communication?

nick703

Member
hello friends i have a teensy 4.1 with use of native ethernet over TCP IP protocol to communicate with DELTA HMI 100 series DOP-107WV . so when i try with teensy4.1 etherent to PC ethernet communication working . When i try DOP-107WV HMI ethernet to PC ethernet is working but when i DIrect connect Teensy4.1 Ethernet to HMI ethernet than communoication is not established . please help me if any solution .
Code:
#include <NativeEthernet.h>
byte mac[] = { 0x04, 0xE9, 0xE5, 0x12, 0x34, 0x56 };
IPAddress ip(192, 168, 1, 20);
IPAddress subnet(255, 255, 255, 0);
EthernetServer server(502);   // Modbus TCP standard port
bool coil0 = false;           // LED coil
void setup() {
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  Serial.begin(115200);
  while (!Serial && millis() < 3000);
  Ethernet.begin(mac, ip, subnet);
  Serial.print("Teensy IP: ");
  Serial.println(Ethernet.localIP());
  server.begin();
  Serial.println("Modbus TCP Server READY");
}
void loop() {
  EthernetClient client = server.available();
  if (!client) return;
  uint8_t req[260];
  uint8_t res[260];
  while (client.connected()) {
    if (!client.available()) continue;
    int len = client.read(req, sizeof(req));
    if (len < 8) continue;
    uint16_t transId = (req[0] << 8) | req[1];
    uint8_t unitId   = req[6];
    uint8_t fc       = req[7];
    // ---------------- FC05 : Write Single Coil ----------------
   if (fc == 0x05) {
      uint16_t coilAddr = (req[8] << 8) | req[9];
      uint16_t value    = (req[10] << 8) | req[11];
      Serial.print("FC05 received, coil=");
      Serial.print(coilAddr);
      Serial.print(" value=");
      Serial.println(value == 0xFF00 ? "ON" : "OFF");
      if (coilAddr == 0) {
        coil0 = (value == 0xFF00);
        digitalWrite(LED_BUILTIN, coil0);
      }
      memcpy(res, req, 12);
      client.write(res, 12);
    }

    // ---------------- FC03 : Read Holding Register ----------------
    else if (fc == 0x03) {
      uint16_t regAddr = (req[8] << 8) | req[9];
      uint16_t qty     = (req[10] << 8) | req[11];
      uint16_t adc = analogRead(A0);
      res[0] = req[0];  // Transaction ID
      res[1] = req[1];
      res[2] = 0x00;    // Protocol ID
      res[3] = 0x00;
      res[4] = 0x00;
      res[5] = 0x05 + qty * 2;   // Length
      res[6] = unitId;
      res[7] = 0x03;
      res[8] = qty * 2;
      for (int i = 0; i < qty; i++) {
        uint16_t val = (regAddr + i == 0) ? adc : 0;
        res[9 + i * 2]     = val >> 8;
        res[10 + i * 2]    = val & 0xFF;
      }
      client.write(res, 9 + qty * 2);
    }
  }
  client.stop();
}
above is code and below is the HMI setiing image
 

Attachments

  • configtcp.png
    configtcp.png
    67.8 KB · Views: 24
  • Miantain.png
    Miantain.png
    36.5 KB · Views: 29
I suggest you try using QNEthernet.
NativeEthernet is NOT actively SUPPORTED by it's author and hasn't been for quite some time, whereas QNEthernet is VERY ACTIVELY SUPPORTED.
The Author is often on this forum helping users with their Ethernet code.
 
ok evreything is working now simple setting i have a miss in DOP HMI setting page i have to set controller ip same as teensy ip and local ip set to different in HMI. now both library work and i have receive and send data. Thnaks for help.
 
Back
Top