adsplctwincattwincat-adstwincat-ads-.net

Beckhoff ADS decoding


I'm trying to decode the ADS data for a small project I'm doing in my free time. I want to retrieve as much information as possible. So far, I have successfully decoded most of the Symbol information.

I'm trying to decode this:

[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 112, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 129, 24, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 4, 0, 70, 66, 95, 68, 101, 114, 0, 0, 0, 87, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 8, 0, 0, 0, 33, 0, 0, 0, 130, 0, 0, 0, 5, 0, 21, 0, 0, 0, 0, 0, 0, 0, 97, 84, 101, 115, 116, 0, 65, 82, 82, 65, 89, 32, 91, 48, 46, 46, 49, 53, 93, 32, 79, 70, 32, 66, 79, 79, 76, 0, 0, 167, 31, 223, 55, 169, 37, 128, 33, 86, 37, 201, 179, 183, 194, 6, 67, 83, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 40, 0, 0, 0, 33, 0, 0, 0, 130, 16, 0, 0, 9, 0, 4, 0, 0, 0, 0, 0, 0, 0, 98, 83, 112, 101, 99, 105, 102, 105, 99, 0, 66, 79, 79, 76, 0, 0, 149, 25, 7, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 1, 0, 3, 0, 70, 111, 111, 0, 0, 96, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 42, 0, 0, 0, 2, 0, 0, 0, 130, 16, 0, 0, 6, 0, 19, 0, 0, 0, 0, 0, 0, 0, 97, 65, 114, 114, 97, 121, 0, 65, 82, 82, 65, 89, 32, 91, 49, 46, 46, 52, 93, 32, 79, 70, 32, 73, 78, 84, 0, 0, 165, 96, 169, 71, 39, 250, 206, 0, 194, 86, 209, 251, 162, 169, 100, 90, 1, 0, 4, 0, 87, 111, 111, 100, 0, 0, 76, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 56, 0, 0, 0, 56, 0, 0, 0, 65, 0, 0, 0, 130, 0, 0, 0, 7, 0, 8, 0, 0, 0, 0, 0, 0, 0, 102, 98, 68, 101, 114, 95, 49, 0, 70, 66, 95, 68, 101, 114, 95, 49, 0, 0, 99, 0, 3, 238, 29, 32, 193, 228, 75, 222, 172, 84, 117, 36, 185, 44, 46, 246, 109, 72, 201, 122, 121, 97, 174, 100, 244, 43, 146, 84, 29, 58, 2, 0, 129, 0, 0, 0, 1, 0, 0, 0, 6, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 149, 25, 7, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 33, 0, 0, 0, 1, 0, 0, 0, 5, 0, 4, 0, 0, 0, 1, 0, 109, 101, 116, 104, 50, 0, 66, 79, 79, 76, 0, 0, 61, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 33, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 149, 25, 7, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 0, 0, 6, 0, 4, 0, 0, 0, 98, 73, 110, 112, 117, 116, 0, 66, 79, 79, 76, 0, 0, 195, 1, 0, 0, 1, 0, 0, 0, 10, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 149, 25, 7, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 18, 0, 0, 0, 1, 0, 0, 0, 4, 0, 4, 0, 0, 0, 6, 0, 77, 69, 84, 72, 0, 85, 73, 78, 84, 0, 0, 61, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 33, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 149, 25, 7, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 0, 0, 6, 0, 4, 0, 0, 0, 98, 73, 110, 112, 117, 116, 0, 66, 79, 79, 76, 0, 0, 62, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 33, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 149, 25, 7, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 0, 0, 7, 0, 4, 0, 0, 0, 98, 73, 110, 112, 117, 116, 50, 0, 66, 79, 79, 76, 0, 0, 62, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 33, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 149, 25, 7, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 0, 0, 7, 0, 4, 0, 0, 0, 98, 73, 110, 112, 117, 116, 51, 0, 66, 79, 79, 76, 0, 0, 62, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 33, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 149, 25, 7, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 0, 0, 7, 0, 4, 0, 0, 0, 98, 79, 117, 116, 112, 117, 116, 0, 66, 79, 79, 76, 0, 0, 63, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 33, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 149, 25, 7, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 0, 0, 8, 0, 4, 0, 0, 0, 98, 79, 117, 116, 112, 117, 116, 50, 0, 66, 79, 79, 76, 0, 0, 74, 0, 0, 0, 1, 0, 0, 0, 8, 0, 0, 0, 33, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 24, 32, 218, 102, 239, 17, 94, 166, 151, 84, 70, 239, 64, 130, 149, 47, 0, 0, 6, 0, 17, 0, 0, 0, 98, 73, 110, 79, 117, 116, 0, 82, 69, 70, 69, 82, 69, 78, 67, 69, 32, 84, 79, 32, 66, 79, 79, 76, 0, 0, 3, 0, 4, 0, 87, 111, 111, 100, 0, 0, 3, 0, 70, 111, 111, 0, 0, 12, 9, 84, 99, 73, 109, 112, 108, 101, 109, 101, 110, 116, 115, 0, 73, 84, 70, 59, 73, 84, 70, 95, 49, 0, 0, 0, 0, 0, 0, 0, 0]

Into that(these are different symbols, but this is what I had at hand. Just to show the input data and results):

// Structure of ADS Symbol:
// Metadata size: 4 bytes,
// Group: 4 bytes,
// Offset: 4 bytes,
// Size of the variable: 4 bytes,
// Base type: 4 bytes,
// Flags: 2 bytes,
// Legacy array dim: 2 bytes,
// Name len.: 2 bytes,
// Type name len.: 2 bytes,
// Comment len.: 2 bytes
// Name: Name len. bytes + termination byte(0),
// Type name: Type name len. bytes + termination byte(0),
// Comment: Comment len. bytes + termination byte(0),
// GUID: 4 bytes, 2 bytes, 2 bytes, 2 bytes, 6 bytes,
// Number of attributes: 2 bytes,
// Repeat for each attribute:
// Attribute len.: 1 byte(..=44, after that null termination needs to be found manually),
// Attribute argument len.: 1 byte (assumed as above),
// Attribute: Attribute len. + leftover bytes + termination byte,
// Attribute argument: Attribute argument len. + leftover bytes + termination byte,
// A few unknown bytes! To be investigated.

And most of the Type information. I say most because I haven't covered edge cases. I could eventually brute force through it, but that seems like a hassle, which I'd rather avoid. I went through many existing ADS libraries across different languages and couldn't find one that fully decodes Symbol and Type.

So my question is. Is there any documentation describing the ADS Symbols and Type data structure?


Solution

  • The ads-client for Node.js parses symbols and data types quite deeply.

    Symbol: https://github.com/jisotalo/ads-client/blob/d5a0fe33359974d3aee1d5634093d6a86d2de693/src/ads-client.js#L5042

    Data type: https://github.com/jisotalo/ads-client/blob/d5a0fe33359974d3aee1d5634093d6a86d2de693/src/ads-client.js#L4701

    It's my project and the way I found these was by looking through TwinCAT.Ads.dll and other libraries. Not all bytes are known however.