New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue reading structs containing BIT datatype #100
Comments
Hi! Actually the BIT data type is not available/working at the moment. I thought that I had it in README but I didn't.. Basically it is in the code however handled like a BOOL and it would require some extra effort to be handled correctly. So I would suggest to use BOOL instead if possible, or just a single WORD and then get the bits yourself. Personally I never use BITs with TwinCAT as the support is not that good. Edit: I will keep this issue open as this certainly should work some day if it's technically doable. |
Hi jisotalo, Thanks very much for the quick reply. Good to know I wasn't going crazy! We initially were using BITs instead of BOOLs to reduce the size of the overall packets over the network, but it's not a big deal for us to change over to using BOOLs instead. I'll keep it in mind for future development not to use BITs. Once again, I very much appreciate the time and effort you've put into this library. Thanks! |
If you really need to read struct with BITs it's possible but needs a little work. I tested the following and it works fine! PLC side
Node.js side const ads = require('ads-client');
const client = new ads.Client({
targetAmsNetId: 'localhost',
targetAdsPort: 851
});
client.connect()
.then(async res => {
console.log(`Connected to the ${res.targetAmsNetId}`);
console.log(`Router assigned us AmsNetId ${res.localAmsNetId} and port ${res.localAdsPort}`);
//First getting the symbol info for this variable
const info = await client.getSymbolInfo('GVL_BitTest.Bits');
//Using symbol info to subscribe to raw data
const sub = await client.subscribeRaw(info.indexGroup, info.indexOffset, info.size, (data, sub) => {
//Converting Buffer to byte
const value = data.value.readUint8();
const converted = {
bit_0: !!(value & (0x01 << 0)),
bit_1: !!(value & (0x01 << 1)),
bit_2: !!(value & (0x01 << 2)),
bit_3: !!(value & (0x01 << 3)),
bit_4: !!(value & (0x01 << 4)),
bit_5: !!(value & (0x01 << 5)),
bit_6: !!(value & (0x01 << 6)),
bit_7: !!(value & (0x01 << 7)),
}
console.log(converted);
/* Should print something like:
{
bit_0: true,
bit_1: false,
bit_2: true,
bit_3: false,
bit_4: true,
bit_5: false,
bit_6: true,
bit_7: false
}
*/
});
})
.catch(err => {
console.log('Something failed:', err);
}) Thanks again and have a nice christmas! |
Hi,
I'm having an issue where I cannot subscribe to structures containing BITs. I can subscribe to everything else just fine.
For example, I cannot subscribe to the struct below:
Turning on debugging in ads-client, I receive the following message:
Any help would be greatly appreciated.
Thanks!
Isaac
The text was updated successfully, but these errors were encountered: