[Question!] Show 16 bits integer in an array (micrologix 1400)
Closed this issue · 5 comments
Hello, first, thanks for this, I'm working on a HMI with NodeJS and this is perfect, my question is when i'm showing the data of the PLC, in the taglookup function I have this:
switch (tag) { case 'TEST': return 'N3:0/0,8'; }
this show the right values, but, when i change the function:
switch (tag) { case 'TEST': return 'N3:0/0,16'; }
this show bad and undefined values, also i tried with this:
switch (tag) { case 'TEST': return 'N3:0/8,8'; }
but the same result bad and undefined values. is there a way to call the 16 bits of an integer ?
Thank You
I solved already... Thanks
How did you solved, @Jotan?
Hi @joaomello, in the module of nodepccc (nodepccc.js) I modified some lines of codes...here are (with the number of every line):
Real
1559. if ((((arrayIndex + theItem.bitOffset + 1) % 8) == 0) || (arrayIndex == theItem.arrayLength - 1)){
Modified to:
1559. if ((((arrayIndex + theItem.bitOffset + 1) % 16) == 0) || (arrayIndex == theItem.arrayLength - 1)){
As you can see I change the 8 value to 16 thats take 16 bits instead of 8, then you must change all the case X value format, I'll show you on the next lines:
Real
1614.theItem.value.push(((theItem.byteBuffer.readUInt8(thePointer) >> (bitShiftAmount)) & 1) ? true : false);
Modified to:
1614.theItem.value.push(((theItem.byteBuffer.readUInt16LE(thePointer) >> (bitShiftAmount)) & 1) ? true : false);
Real
1650. if ((((arrayIndex + theItem.bitOffset + 1) % 8) == 0) || (arrayIndex == theItem.arrayLength - 1)){
Modified to:
1650. if ((((arrayIndex + theItem.bitOffset + 1) % 16) == 0) || (arrayIndex == theItem.arrayLength - 1)){
Real
1782. theItem.writeBuffer.writeUInt8(theByte, thePointer);
Modified to:
1782. theItem.writeBuffer.writeUInt16LE(theByte, thePointer);
Real
1818. if ((((arrayIndex + theItem.bitOffset + 1) % 8) == 0) || (arrayIndex == theItem.arrayLength - 1)){
Modified to:
1818.if ((((arrayIndex + theItem.bitOffset + 1) % 16) == 0) || (arrayIndex == theItem.arrayLength - 1)){
Real
1847. theItem.writeBuffer.writeUInt8(((theItem.writeValue) ? 1 : 0), thePointer); // checked ===true but this caused problems if you write 1
Modified to:
1847. theItem.writeBuffer.writeUInt16LE(((theItem.writeValue) ? 1 : 0), thePointer); // checked ===true but this caused problems if you write 1
With that changes you can get and write data like "N16:0/0,32"
I hope it helps you.
Thank you for this I have integrated it into the package now. Finally. PR's are always welcome.
Note there was a bug affecting writing non-zero values to bit arrays > length 16 that is fixed in 0.1.5 as well.
Thanks to you for this Library :)