cmseaton42 / node-ethernet-ip

A Lightweight Ethernet/IP API written to interface with Rockwell ControlLogix/CompactLogix Controllers.
MIT License
265 stars 106 forks source link

bool read bug #19

Closed nuannuande closed 6 years ago

nuannuande commented 6 years ago

bool var not right

Current Behavior

in tag/index.js this.controller_value = data.readUInt8(2) === 0x01 ? true : false;

i test while the bool is true ,the return data is <buff 00 ff> so this.controller_value = data.readUInt8(2) === 0xff ? true : false;

Expected Behavior

Possible Solution (Optional)

Context

Steps to Reproduce (for bugs only)

1. 2. 3. 4.

Your Environment

cmseaton42 commented 6 years ago

@nuannuande We are aware of this issue. I am pretty busy at the moment so it may be a bit before I can get to it. As a work around, you could read the entire word and then look at individual bits of the read data via the native javascript bitwise operators. Something like the following could work for now.

let bit;

// Let's say we are concerned with the 3rd bit of readTag (readTag.2)
//     then the following should work
bit = readTag & 0b00000100 !== 0 ? true : false;

That said, we would love some help continuing to develop library, thus pull requests are welcome 😄.

We really appreciate you using the project and helping us uncover some of these bugs!