otti / EspAdsLib

Simple Beckhoff ADS communication for ESP
6 stars 2 forks source link

No data exchange #1

Open evisvasiu opened 1 year ago

evisvasiu commented 1 year ago

For some reason, I'm not able to exchange data between my esp32 and Twincat. I've tried some modifications. I have used the same SrcAmsAddr port as in the example. Should we use another one? I also created a firewall rule on PLC client to allow communication through this port. Here's my final version:

#include <EspAdsLib.h>
#include <WiFi.h>
#define ADS_DEBUG_PRINT_ENABLE = 1

ADS::AmsAddr SrcAmsAddr((char*)"192.168.100.57.1.1", 43609);
ADS::AmsAddr DestAmsAddr((char*)"192.168.134.132.1.1", AMSPORT_R0_PLC_TC3);
char DestIpAddr[] = "192.168.134.132"; // IP of the TwinCAT target machine

ADS::Ads Ads(&SrcAmsAddr, &DestAmsAddr, DestIpAddr);

char ssid[] = "Infinity Evis";
char password[] = "Vasiu2023";

int16_t u16PlcWrData = 1234;
int16_t u16PlcRdData;

void setup(){

uint8_t au8Data[32];
Serial.begin(115200);
delay(1000);
SrcAmsAddr.PrintInfo();
WifiConnect();
Ads.Connect();}

bool WifiConnect(void){

int i = 0;
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED)
{
    if (++i > 40) // cancel after 40 * 250 ms
    {
      Serial.print("WiFi connection failed ...");
      Serial.print("Restsrting ESP ...");
      ESP.restart();
    }

    delay(250);
    Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());

return 1;
}

void loop(){
  // Write the PLC variable 'Main.u16MyVar' to u16PlcWrData (1234)
Ads.WritePlcVarByName("MAIN.numberToWrite", &u16PlcWrData, sizeof(int16_t));

// Read back the PLC variable 'Main.u16MyVar' to u16PlcRdData
Ads.ReadPlcVarByName((char*)"MAIN.numberToRead", &u16PlcRdData, sizeof(int16_t));
Serial.println("PlcRdData: " + String(u16PlcRdData));}

On PLC I have just created this two variables: numberToWrite : INT; numberToRead : INT := 0;

otti commented 1 year ago

Hi evisvasiu,

I can't find any obvious fault in your code.

here are some points to check:

I have used the same SrcAmsAddr port as in the example. Should we use another one?

No, the SrcAmsAddr is ok

KaBee69 commented 5 months ago

Hi Otti,

Can you give an example to use the Ads.read function please?

I can use all other calls, but only with the Ads.read i get the error: "no matching function for call to 'ADS::Ads::Read(uint32_t&, uint32_t&, int, bool*)'"

I can't figure it out what is wrong.

Kind regards, Kevin