-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transmit example #57
Comments
Hi @JohnMcLear, thank you for posting your issue here. 🙂 Firstly, I am sorry that the API is not documented better. Will improve, I promise. 😉 The
So your usage of the method is correct. But you are passing the bad data. The correct way of constructing the data with your APDU is following: So you create the Buffer from that like this: // creating a Buffer instance from a hex string
// letters can be lowercase or uppercase – it doesn't matter
const data = Buffer.from('80CA9F7F2C', 'hex'); // <- note the 'hex' encoding or like this: // creating a Buffer instance from an array of bytes
// Note about the number literals:
// 0x prefix says the number is in hexadecimal representation
// 0b prefix says the number is in binary representation (0 and 1 for each bit)
// 0x80 = 128 = 0b10000000
const data = Buffer.from([
0x80,
0xca, // letters can be lowercase or uppercase – it doesn't matter
0x9f,
0x7f,
0x2c,
]); So your code after the updates could look like: nfc.on('reader', reader => {
reader.autoProcessing = false;
// this turns off auto processing
// by default (when autoProcessing is set to true) when a card is detected
// an APDU command is automatically transmitted to obtain the card's UID
// then in card event, card.uid is available
// it works well ONLY for standard ISO 14443-3 tags like NTAG or Mifare Ultralight
reader.on('card', async card => {
// APDU Transmit logic
console.log('card detected');
const apdu = '80ca9f7f2c';
const data = Buffer.from(apdu, 'hex');
try {
const uid = await reader.transmit(data, 12); // 12 bytes = 24 hex digits (update according to your needs)
console.log(`UID`, uid.toString('hex'));
} catch (err) {
console.log(err);
}
});
}); Hope I clarified a few things a bit. Please let me know if you are able to make it work. 🙂 PS Don't forget to star ⭐️my library, if you find it useful. 😃Thanks. |
Excellent thanks for this :) I tried the above logic (copy/pasted) and I get thsi output:
To fix I bumped the buffer length value up to Entire code is now this:
Any idea why 47 is the magic number here? Does that come from the response and is it something I should know the length based on a response? |
Hi @JohnMcLear, sorry for the late reply. It's great you made it work. 🙂 Unfortunately, it seems my previous statement about the responseMaxLength was incorrect. 😄 The reader (reps. the card) is returning 47 bytes as the response to the You should know the expected response length of any command you use. You should find that value in the appropriate documentation. Could you please add a link to the documentation of the command you used? Or link to the docs of the card you use? Anyway, does it work for you? Did you manage to get response you wanted? If so, feel free to close the issue. Hope it helps. 🙂 |
Ack, yeah all working fine :) Thanks! :) |
Hey man, thanks for all the hard work on this project :)
I'm working on some logic which can get the SEID from an IC using an APDU. Pretty simple stuff I have working on other platforms (Cordova etc.) but I seem to struggling with this project. It's likely I'm a bit rusty as I haven't worked on it for a few years so apology if this is user error however I have read through the docs and do feel like the transmit method docs could do with some additional input (of which I will be happy to do once I am comfortable with the method).
The following:
Returns:
The UID value should be much longer.
I'm 99% correct the APDU is correct.
I'm only making assumptions I'm doing transmit correctly.
I think the error lies in the format I'm encoding the APDU (from string to Buffer?)
The text was updated successfully, but these errors were encountered: