roccomuso / node-ads

NodeJS Twincat ADS protocol implementation
58 stars 21 forks source link

Fixed getSymbols function, there was a bug according to the length of… #23

Closed Suizi11 closed 6 years ago

Suizi11 commented 6 years ago

… one symbol (reading next symbol started at wrong position)

I tried it with the official C++ library of Beckhoff and it seems to work (got all my 18 symbols back). This JS library crashed while copying something into the new buffer. The problem was that the length of the symbol was ignored.

If somebody needs my TwinCat project please let me know.

PLCHome commented 6 years ago

I had no problem reading the symbols. But that does not mean that everything is correct.

The solution is good. But I would be interested to know where the difference is coming from. Was initialPos les than pos or higher? Can you post the buffer? console.log(result); on line 571 I would like to take a closer look. So I can rule, we read the Buffer, we make no mistake.

This post is definitely OK.

Can you also test the reading of the types?

PLCHome commented 6 years ago

When I look at the "TcAdsDll.h" I wonder why the length is wrong?

////////////////////////////////////////////////////////////////////////////////
// ADS symbol information
typedef struct
{
        unsigned        long            entryLength;    // length of complete symbol entry
        unsigned        long            iGroup;                 // indexGroup of symbol: input, output etc.
        unsigned        long            iOffs;                  // indexOffset of symbol
        unsigned        long            size;                   // size of symbol ( in bytes, 0 = bit )
        unsigned        long            dataType;               // adsDataType of symbol
        unsigned        long            flags;                  // see above
        unsigned        short           nameLength;             // length of symbol name (excl. \0)
        unsigned        short           typeLength;             // length of type name (excl. \0)
        unsigned        short           commentLength;  // length of comment (excl. \0)
} AdsSymbolEntry, *PAdsSymbolEntry, **PPAdsSymbolEntry;

Maybe it's the Twincat version?

Suizi11 commented 6 years ago

Thanks - but feel free to change my solution, it's only a quick solution, but in my opinion less error prone, because only one symbol can fail if the length is correct. :)

Twincat version is: 3.1.4022.4

I was also very confused about the comparison with the header file of C++.

With the bug, the second round has the initial position 58, but it should be 80 (= readLength). Nevertheless, my buffer: 50000000404000009dd30700010000002100000008000000150004000000436f6e7374616e74732e62465055537570706f727400424f4f4c00009519071800000000000000000000003000000000000070000000404000008bd30700010000002100000008000000170004001f00436f6e7374616e74732e624c6974746c65456e6469616e00424f4f4c0020446f6573207468652074617267657420737570706f727420616e204650550095190718000000000000000000000030000000000070000000404000009cd30700010000002100000008000000190004001f00436f6e7374616e74732e6253696d756c6174696f6e4d6f646500424f4f4c0020446f6573207468652074617267657420737570706f727420616e204650550095190718000000000000000000000030000000700000004040000094d30700080000004100000008000000190007001f00436f6e7374616e74732e436f6d70696c657256657273696f6e0056455253494f4e0020446f6573207468652074617267657420737570706f727420616e2046505500eae4f0b796a13e46a8d22f9453e4c1e85800000040400000a8d30700040000001300000008000000200005000000436f6e7374616e74732e436f6d70696c657256657273696f6e4e756d657269630044574f524400009519071800000000000000000000000700006800000040400000a0d30700020000001200000008000000130004001f00436f6e7374616e74732e6e5061636b4d6f64650055494e540020446f6573207468652074617267657420737570706f727420616e2046505500951907180000000000000000000000050070000000404000009ed30700020000001200000008000000170004001f00436f6e7374616e74732e6e526567697374657253697a6500574f52440020446f6573207468652074617267657420737570706f727420616e204650550095190718000000000000000000000004000000000070000000404000008cd30700080000004100000008000000180007001f00436f6e7374616e74732e52756e74696d6556657273696f6e0056455253494f4e0020446f6573207468652074617267657420737570706f727420616e2046505500eae4f0b796a13e46a8d22f9453e4c1e8005800000040400000a4d307000400000013000000080000001f0005000000436f6e7374616e74732e52756e74696d6556657273696f6e4e756d657269630044574f5244000095190718000000000000000000000007000000480000004040000088d3070002000000020000000800000012000300000047564c5f484d492e69476c6f62616c496e7400494e54000095190718000000000000000000000006000048000000404000001cd007000100000011000000080000000e00040000004d41494e2e6279746556616c756500425954450000951907180000000000000000000000010000000000480000004040000070d307000400000003000000080000000e00040000004d41494e2e64696e7456616c75650044494e540000951907180000000000000000000000090000000000480000004040000068d307000400000013000000080000000f00050000004d41494e2e64776f726456616c75650044574f524400009519071800000000000000000000000700000040000000404000006ed307000200000002000000080000000900030000004d41494e2e68496e7400494e540000951907180000000000000000000000060000004000000020400000020000000200000002000000080000000900030000004d41494e2e69496e7400494e5400009519071800000000000000000000000600000048000000404000006cd307000200000002000000080000000d00030000004d41494e2e696e7456616c756500494e5400009519071800000000000000000000000600000000000000480000004040000078d307000800000005000000080000000f00050000004d41494e2e6c7265616c56616c7565004c5245414c00009519071800000000000000000000000e00000040000000214000000000000001000000210000000a0000000a00040000004d41494e2e6d426f6f6c00424f4f4c00009519071800000000000000000000001000500000004040000080d307000800000041000000080000000d000e0000004d41494e2e7041647269496e7400504f494e54455220544f20494e540000c0bc4710ad1ba589aa210d2629c1df4700000000480000004040000074d307000400000004000000080000000e00040000004d41494e2e7265616c56616c7565005245414c00009519071800000000000000000000000d000000000048000000404000001dd007000100000010000000080000000e00040000004d41494e2e73696e7456616c75650053494e54000095190718000000000000000000000003000000000068000000204000000c000000510000001e000000080000000c000a001c004d41494e2e73537472696e6700535452494e47283830290069496e743209415420254d5731203a494e5409093a3d20313233343b0095190718000000000000000100000050000000000048000000404000001ed007000200000012000000080000000e00040000004d41494e2e776f726456616c756500574f52440000951907180000000000000000000000040000000000880000004040000038d507007000000041000000081000002300130000005477696e4341545f53797374656d496e666f5661724c6973742e5f5f506c635461736b005f496d706c696369745f5461736b5f496e666f000080619eb0794c6d47aaea6bb26f48ffad01000d075463436f6e746578744e616d6500506c635461736b00000000000000006800000040400000b0d307000001000041000000080000002200140000005477696e4341545f53797374656d496e666f5661724c6973742e5f417070496e666f00504c432e506c6341707053797374656d496e666f00007ff48f5c837f93448d21f1ff8a08f75a008000000040400000b0d407008000000041000000080000002300250000005477696e4341545f53797374656d496e666f5661724c6973742e5f5461736b496e666f004152524159205b312e2e315d204f4620504c432e506c635461736b53797374656d496e666f0000f5d3c5454aa5c8278af03abce4a1006d00000000000000600000004040000030d507000400000013000000080000002a00050000005477696e4341545f53797374656d496e666f5661724c6973742e5f5461736b4f69645f506c635461736b004f5443494400009519071800000000000000000000000f6800000040400000acd307000400000013000000080000002d00050000005477696e4341545f53797374656d496e666f5661724c6973742e5f5461736b506f754f69645f506c635461736b004f5443494400009519071800000000000000000000000f0000000000

PLCHome commented 6 years ago

Thanx... There are some 95190718...nnnn...00 Is there another structure in the TcAdsDll.h ? But the rest is fine :-) It can also be some internal data.

getDatatyps looks good: return readLength+p

readLength | 0 | 80 |  
indexGroup | 4 | 16448 |  
indexOffset | 8 | 512925 |  
size | 12 | 1 |  
type | 16 | 33 |  
something | 20 | 8 |  
nameLength | 24 | 21 |  
typeLength | 26 | 4 |  
commentLength | 28 | 0 |  
name | 30 | 44 | 436f6e7374616e74732e62465055537570706f727400
type | 52 | 10 | 424f4f4c00
comment | 57 | 2 | 00
??? | 58 | 44 | 95190718000000000000000000000030000000000000

readLength | 80 | 112 |  
indexGroup | 84 | 16448 |  
indexOffset | 88 | 512907 |  
size | 92 | 1 |  
type | 96 | 33 |  
something | 100 | 8 |  
nameLength | 104 | 23 |  
typeLength | 106 | 4 |  
commentLength | 108 | 31 |  
name | 110 | 48 | 436f6e7374616e74732e624c6974746c65456e6469616e00
type | 134 | 10 | 424f4f4c00
comment | 139 | 64 | 20446f6573207468652074617267657420737570706f727420616e2046505500
??? | 171 | 42 | 951907180000000000000000000000300000000000

readLength | 192 | 112 |  
indexGroup | 196 | 16448 |  
indexOffset | 200 | 512924 |  
size | 204 | 1 |  
type | 208 | 33 |  
something | 212 | 8 |  
nameLength | 216 | 25 |  
typeLength | 218 | 4 |  
commentLength | 220 | 31 |  
name | 222 | 52 | 436f6e7374616e74732e6253696d756c6174696f6e4d6f646500
type | 248 | 10 | 424f4f4c00
comment | 253 | 64 | 20446f6573207468652074617267657420737570706f727420616e2046505500
??? | 285 | 38 | 95190718000000000000000000000030000000