caobo171 / node-zklib

This is a lightweight of node.js module to connect to biometrix attendance device for examples ZKTeco
70 stars 59 forks source link

RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 4. Received 24 #41

Closed Shameel123 closed 2 years ago

Shameel123 commented 2 years ago

I am getting the following error and unable to understand the reason for its occurrence. I tried to find solutions on Google but different people are facing this issue for entirely different applications.

Node Version: 17.0.0

The code execute perfectly till ok tcp

Error:

ZKError {
  err: RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 4. Received 24
      at new NodeError (node:internal/errors:371:5)
      at boundsError (node:internal/buffer:86:9)
      at Buffer.readUInt32LE (node:internal/buffer:220:5)
      at Buffer.readUIntLE (node:internal/buffer:178:17)
      at ZKLibTCP.getInfo (C:\Users\shame\OneDrive\Desktop\AMS\zklibtcp.js:459:26)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at async ZKLib.functionWrapper (C:\Users\shame\OneDrive\Desktop\AMS\zklib.js:23:38)
      at async ZKLib.getInfo (C:\Users\shame\OneDrive\Desktop\AMS\zklib.js:182:16)
      at async test (C:\Users\shame\OneDrive\Desktop\AMS\index.js:10:17) {
    code: 'ERR_OUT_OF_RANGE'
  },
  ip: '192.168.18.2',
  command: '[TCP] undefined'
}
Shameel123 commented 2 years ago

The error persists on following node.js versions:

Shameel123 commented 2 years ago

I have traced the error to zklibtco.js The error occurs in following function when returning the data.

async getInfo() {
    try {
      const data = await this.executeCmd(COMMANDS.CMD_GET_FREE_SIZES, "");

      return {
        userCounts: data.readUIntLE(24, 4),
        logCounts: data.readUIntLE(40, 4),
        logCapacity: data.readUIntLE(72, 4),
      };
    } catch (err) {
      console.log("noway");
      return Promise.reject(err);
    }
  }
Shameel123 commented 2 years ago

I have changed it to this and it is now working fine:

async getInfo() {
    try {
      const data = await this.executeCmd(COMMANDS.CMD_GET_FREE_SIZES, "");

      return {
        userCounts: data.readUIntLE(0, 4),
        logCounts: data.readUIntLE(0, 4),
        logCapacity: data.readUIntLE(0, 4),
      };
    } catch (err) {
      console.log("noway");
      return Promise.reject(err);
    }
  }