0

In a project im using a TcAdsWebService.js provided by Beckhoff. Using this file im trying to create a class with a couple of functions.

Click, The click function can be implemented and used by a button.

click() {
        this.tcClient.write(
            this.NETID,
            this.PORT,
            0x0000F005, // IndexGroup = Write variable by handle;
            this.handlerVar,
            this.TrueBase64,
            this.writeCallback,
            null,
            this.general_timeout,
            this.writeTimeoutCallback,
            true // True for AJAX
        );
    }

writeCallback

writeCallback(e, s) {
          if (e && e.isBusy) {
            // HANDLE PROGRESS TASKS HERE;
            // Exit callback function because request is still busy;
            return;
        }

        if (e && !e.hasError) {
            // Success
        } else {

            if (e.error.getTypeString() == "TcAdsWebService.ResquestError") {
                // HANDLE TcAdsWebService.RequestError HERE;
                console.log(this.plcVar + " Write - Request Error");
            }
            else if (e.error.getTypeString() == "TcAdsWebService.Error") {
                // HANDLE TcAdsWebService.Error HERE;
                console.log(this.plcVar + " - Other Error");
            }
        }
    }

WriteTimeoutCallback

writeTimeoutCallback() {
        return '${this.name} - Writing to var timeout';
    }

All the needed variables are passed trough the constructor.

constructor(name, location, plcVar, tcClient) {
        super();
        this.name = name;
        this.location = location;
        this.plcVar = plcVar;
        this.tcClient = tcClient;
        this.handlerVar = "h" + name;
    }

This is how i implement the class where all the functions are created:

 var SERVICE_URL = "http://localhost/tcadswebservice/tcadswebservice.dll";
 var client = new TcAdsWebService.Client(SERVICE_URL, null, null);
 var start = new Button('Start', 'MAIN.'+fbName+'.bStart', 'bStart', client);

When creating a instance of the class i provide all the variables trough the constructor and i can access them all. After that i tried to use the click function with a button.onclick but everytime i try this i get the following prompt:

Uncaught TypeError: Cannot read property 'write' of undefined at HTMLButtonElement.click

The error points to the first line in the click function:

this.tcClient.write(

How can i implement the class and use the click function without getting the error?

Collin
  • 1,064
  • 1
  • 9
  • 30
  • It's unclear if the code you show is really enough to reproduce the problem, but it's *probably* [this](https://stackoverflow.com/q/20279484/476). – deceze Aug 30 '21 at 07:22

0 Answers0