Compiling under TwinCAT/BSD

This step shows how to generate executable code directly under TwinCAT/BSD with the LLVM compiler. For this purpose, a sample C/C++ project is created, which will use the ADS interface. To use the functions of TcAdsDll in your C/C++ project, you have to integrate the header file TcAdsAPI.h in your project.

The ADS header file is located in the following directory:
usr/local/include/TcAdsAPI.h

Sample C/C++ project adstest.c

#include <stdio.h>
#include <stdint.h>
#include "TcAdsAPI.h"

int main(){
    printf("ADS Test Sample\n");

    long nTemp;
    AdsVersion* pDLLVersion;
    nTemp = AdsGetDllVersion();
    pDLLVersion = (AdsVersion *)&nTemp;
    printf("Version: %d\n", (int)pDLLVersion->version);
    printf("Revision: %d\n", (int)pDLLVersion->revision);
    printf("Build: %d\n", (int)pDLLVersion->build);
    //printf("Ads DLL Version: %d\n", version);
    
    long l_port;
    l_port = AdsPortOpen();
    printf("Port opened: %ld\n", l_port);
    AdsPortClose();
    printf("Port closed\n");
    return 0;
}

Requirements:

Generate executable code under TwinCAT/BSD as follows:

1. Copy the file adstest.c to any TwinCAT/BSD directory. Example: /usr/local/ADSinterface
2. Navigate to the directory with the example file adstest.c
3. Use the command doas cc -c -I /usr/local/include/ -D POSIX adstest.c -o adstest.o to compile the file adstest.c.
4. Link the compiled file with the ADS library with the command cc -lpthread adstest.o /usr/local/lib/libTcAdsDll.so -o adstest
5. Execute the file with ./adstest.