AddClient

TwinCAT
Network REST Client

ns=2;s=DEPRAG Smart/Network/HTTP/REST/AddClient

Creates a new, fully parameterized REST client. The REST client can be retrieved from the "ActiveClients" list via the returned index.

Parameters:

    ConnectionTimeoutInMilliseconds
    Maximum time in milliseconds for establishing a connection to the REST API. If a connection cannot be established within the time interval, an error is issued.
    TlsVersion
    TLS version used for encryption:
    SSL2, SSL3, TLS, Default, TLS11, TLS12, TLS13
    UserName
    Username used to authenticate to the specified REST server.
    Password
    Password used to authenticate to the specified REST server.
    ApiToken
    API token used to authenticate to the specified REST server.
    AcceptSelfSignedCertificates
    Specifies whether unsigned certificates are accepted. If this value is set to yes, the application can connect to REST servers with self-signed certificates.
    Compression
    Sets the compression algorithm:
    All
    None
    Gzip
    Deflate
    Brotli

Returns:

    AddClient
    A variable of type OpcMethodReturnValueInt32. The Result property contains the command-specific return values.
      Result
      Unique index that can be used to retrieve the REST client from the "ActiveClients" list.

Examples:

In addition to the parameters already explained, the following variables must be created / transferred for the implementation in TwinCAT 3:

Beckhoff parameter:

    bHttpAddClient
    A boolean variable that can be used to trigger the execution of the AddClient command.
    OutputDataHttpAddClient
    An instance of the ST_Int32OutputData structure into which the return value of the AddClient method is written.
    hrHttpAddClient
    This can be used to monitor the execution of the command. Error codes have the type HRESULT.
    fbHttpRest
    An instance of the "FB_HttpRest" function block supplied with the DEPRAG Smart library.
    HostAddress
    A String(255) variable representing the address of the REST API.
    HostPort
    A DINT variable that specifies the port of the REST API.
    ConnectionTimeOutInMilliseconds
    A DINT variable representing the maximum time in milliseconds for establishing a connection to the REST API. If a connection cannot be established within the time interval, an error is issued.
    TlsVersion
    An enum of type "SslProtocols" which specifies the TLS version used for encryption: SSL2, SSL3, TLS, Default, TLS11, TLS12, TLS13
    UserName
    A String(255) variable representing the username used to authenticate to the specified REST server.
    Password
    A String(255) variable representing the password used to authenticate to the specified REST server.
    ApiToken
    A String(255) variable representing the API token used to authenticate to the specified REST server.
    AcceptSelfSingedCertificates
    A boolean variable that determines whether unsigned certificates are accepted. If this value is set to yes, the application can connect to REST servers with self-signed certificates.
    Compression
    An enum of type "DecompressionMethods" which specifies the compression algorithm: All, None, Gzip, Deflate, Brotli
    ContentType
    A string(255) variable which adds the content type in the HTTP header.
    ConnectionHandle
    "ConnectionHandle" received when establishing a connection between DEPRAG Smart Server and your OPC UA client.


VAR
    bHttpAddClient : BOOL;
    OutputDataHttpAddClient : ST_Int32OutputData;
    hrHttpAddClient   : HRESULT;

    fbHttpRest   : FB_HttpRest;
END_VAR

hrHttpAddClient := fbHttpRest.AddClient( 
        bExecute      := bHttpAddClient, 
        ConnectionHandle    := depragSmartConnection.ConnectionHandle,
        HostAddress      := 'https://OpcUa.deprag.com/',  
        HostPort      := 443,
        ConnectionTimeOutInMilliseconds := 5000,
        TlsVersion      := SslProtocols.Tls12,
        UserName      := 'User1',
        Password      := 'Password1',
        ApiToken      := 'ApiToken1',
        AcceptSelfSingedCertificates := TRUE,
        Compression      := DecompressionMethods.All,
        ContentType      := '', 
        OutputData      => OutputDataHttpAddClient);
IF hrHttpAddClient <> S_FALSE THEN 
    bHttpAddClient := FALSE;
END_IF
                                                    

For examples and explanations regarding the calls of nodes via Siemens TIA Portal please refer to the sub-menu "Siemens TIA Portal" in section "Getting Started".