Comments (3)
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
TYPE ST_Bits:
STRUCT
Bit_0 : BIT;
Bit_1 : BIT;
Bit_2 : BIT;
Bit_3 : BIT;
Bit_4 : BIT;
Bit_5 : BIT;
Bit_6 : BIT;
Bit_7 : BIT;
END_STRUCT
END_TYPE
//GVL_BitTest
{attribute 'qualified_only'}
VAR_GLOBAL
Bits : ST_Bits;
END_VAR
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!
from ads-client.
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.
from ads-client.
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!
Isaac
from ads-client.
Related Issues (20)
- ads-client error npm test... HOT 1
- We have discovered a crash in the unsubscribe all method. HOT 6
- Proposal ReadSymbolInfo SumCommand HOT 4
- Can't subscribe to POINTER or REFERENCE variables (solved) HOT 11
- Creating base project structure
- exported code of matlab has type MatSim.DINT HOT 5
- Version 2 - Optional Ams_NetId HOT 3
- _parseDataType: Incorrect parsing of flags HOT 3
- Is it possible to access the library created with TwinCAT? HOT 3
- Why is there such an error HOT 2
- Read symbol value on BC9050 HOT 2
- MBUS card through ADS HOT 1
- BK9050 HOT 11
- idea: ads-client with Blockly, organization: VisualPLC, problem port 301 without address, HOT 11
- CX9020 HOT 1
- Get events/alarms/messages from TcEventLogger HOT 3
- write variable type BOOL HOT 1
- ads-client+vite+vanillajs it's possible? HOT 5
- Subcribe to variable without PLC port 301 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ads-client.