Closed ChiKaLiO closed 3 years ago
The original lib not working, i can't figure out how to add a user, here is what i did:
constants.js added
CMD_SET_USER:8,
zklibtcp:
async createUser(user) {
console.log(user);
return await this.executeCmd(COMMANDS.CMD_USER_WRQ, [user])
}
index:
const user = {
uid: '90909',
password:'',
name: 'testing',
user_id: '123',
cb :''
}
await zkInstance.createUser(user);
i can't figure it out..
Yeah, I really tried to figure it out , but it just worked with some devices :)) so I haven't push it here
so my code is correct but it doesn't work with all devices ?
I tried every library in github 😆 i added cardno in one of the php libs and it worked but still can't figure out how to send the data i node..
i got it to work like this:
async setUser(uid, userid, name, password, role = 0, cardno = 0) {
try{
if (
parseInt(uid) === 0 ||
parseInt(uid) > 3000 ||
userid.length > 9 ||
name.length > 24 ||
password.length > 8 ||
cardno.length > 10
) {
return false;
}
const command_string = Buffer.alloc(72);
command_string.writeUInt16LE(uid, 0);
command_string.write('2', 2, 1);
command_string.write(password, 3, 8);
command_string.write(name, 11, 24);
command_string.writeUInt32LE(cardno, 35);
command_string.writeUInt16LE(role, 39);
command_string.writeUInt32LE(0, 40);
command_string.write(userid ? userid.toString(9) : '', 48);
console.log(command_string);
return await this.executeCmd(COMMANDS.CMD_SET_USER, command_string);
}catch(e){
console.log(e);
console.log('duh');
}
}
but the role is unkown, i dunno why .. my device is MB2000
i got it to work like this:
async setUser(uid, userid, name, password, role = 0, cardno = 0) { try{ if ( parseInt(uid) === 0 || parseInt(uid) > 3000 || userid.length > 9 || name.length > 24 || password.length > 8 || cardno.length > 10 ) { return false; } const command_string = Buffer.alloc(72); command_string.writeUInt16LE(uid, 0); command_string.write('2', 2, 1); command_string.write(password, 3, 8); command_string.write(name, 11, 24); command_string.writeUInt32LE(cardno, 35); command_string.writeUInt16LE(role, 39); command_string.writeUInt32LE(0, 40); command_string.write(userid ? userid.toString(9) : '', 48); console.log(command_string); return await this.executeCmd(COMMANDS.CMD_SET_USER, command_string); }catch(e){ console.log(e); console.log('duh'); } }
but the role is unkown, i dunno why .. my device is
MB2000
in this format everything is working:
const command_string = Buffer.alloc(72);
command_string.writeUInt16LE(uid, 0);
command_string.writeUInt16LE(role, 2);
command_string.write(password, 3, 8);
command_string.write(name, 11, 24);
command_string.writeUInt16LE(cardno, 35);
command_string.writeUInt32LE(0, 40);
command_string.write(userid ? userid.toString(9) : '', 48);
Hello, i'm new to zk this library is worth gold to me but still can't figure alot of things.. i will be needing to add users from computer with fingerprints, bulk delete expired users