twincat

Is there a way to check the TwinCAT XAR version of the runtime?


I didn't find anything on InfoSys on how to check this. You can pin/fix the project version, but this only changes things on the XAE side, not on the runtime.

I want to check the XAR version, because of a feature that was introduced in 4024.40. I want to make sure that this feature is available.

But now I'm wondering if it is necessary to have the runtime at a newer version as well. According to this question, a later XAE version compared to the XAR is ok. So in that case I can just upgrade the XAE version.


Solution

  • There are multiple ways. The first two need a local access to the Windows. The last one uses ADS and can be used remotely.

    Registry

    TwinCAT 4024 and newer has TcVersion registry entry that contains the version. 4022 seems not to have it.

    Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Beckhoff\TwinCAT3\System

    enter image description here

    TwinCAT System UI

    The version is displayed in about dialog. So right click TwinCAT tray icon (in the PLC - not on your PC!) and select About TwinCAT... enter image description here

    Using ADS communication

    You can remotely read the full version number using ADS:

    Response data example: 01 00 03 00 1b 00 b6 0f

    Version number: 3.1.4022.27

    Example with PLC code:

    Create a struct ST_TwincatVersion:

    {attribute 'pack_mode' := '1'} 
    TYPE ST_TwincatVersion :
    STRUCT
        num1 : UINT;
        num2 : UINT;
        num3 : UINT;
        num4 : UINT;
    END_STRUCT
    END_TYPE
    

    Code:

    VAR
        ReadVersionReq  : BOOL;
        AdsReader       : ADSREADEX;
        Version         : ST_TwincatVersion;
    END_VAR
    
    //Set ReadVersionReq to TRUE to read version
    AdsReader(
        NETID   := '192.168.1.50.1.1', //Change to correct address
        PORT    := 10000, 
        IDXGRP  := 160, 
        IDXOFFS := 0, 
        LEN     := SIZEOF(version), 
        DESTADDR:= ADR(Version), 
        READ    := ReadVersionReq
    );
    
    //Note: No error handling
    IF ReadVersionReq AND NOT AdsReader.BUSY THEN
        ReadVersionReq := FALSE;
    END_IF
    

    Result:

    enter image description here

    Example with Javascript and ads-client library:

    const ads = require('ads-client');
    
    const client = new ads.Client({
      targetAmsNetId: '192.168.1.50.1.1', //Change to correct address
      targetAdsPort: 10000,
      bareClient: true
    });
    
    client.connect()
      .then(async res => {   
        const data = await client.readRaw(160, 0, 8);
        
        const versionNumbers = [
          data.readInt16LE(2),
          data.readInt16LE(0),
          data.readInt16LE(6),
          data.readInt16LE(4)
        ];
    
        const versionStr = versionNumbers.join(".");
        
        console.log(data); //<Buffer 01 00 03 00 1b 00 b6 0f>
        console.log(versionNumbers); //[ 3, 1, 4022, 27 ]
        console.log(versionStr); //3.1.4022.27
    
        await client.disconnect();
      })
      .then(() => {
        console.log('Disconnected');
      })
      .catch(err => {
        console.log('Something failed:', err);
      })