-
Notifications
You must be signed in to change notification settings - Fork 132
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
Write to Mifare Classic 1K card in Electron App #7
Comments
So I experimented a bit more and just cloned the complete repository, ran the install command and uncommented the authentication code but still no luck. Any tips for looking in the right direction? |
@PimButton 0x6300 is status code from the NFC card, that means, that the operation failed – the cause could be, that you are using bad key (or key type). Don't you need to authenticate also with another key (maybe key B) for writing data to your card? |
Ok so another update: However, still no luck in Electron. Reading / Writing seems to depend on Async / Await and that does not work in Electron by default. I tried using Babel but gives a lot of headache... Did you ever get this working? |
Can't you get async/await through externals? |
@indiecore-fm would love to, but can't seem to find how to do that exactly. Any hints in the right direction? |
@PimButton Instead of async/await you can you Promises (which should work without transpiler because they are already supported in Chrome). So with Promises the code could look like: reader.on('card', card => {
const key = 'FFFFFFFFFFFF';
const keyType = KEY_TYPE_A; // KEY_TYPE_B
// EXAMPLE reading and writing data to Mifare 1K with Promises
// 16 bytes data assuming containing 16bit integer
Promise.all([
reader.authenticate(4, keyType, key),
// you add more authenticate call if you want auth more blocks
])
// READ data
.then(() => reader.read(4, 16, 16))
.then(data => {
console.log(`data read`, data);
const number1 = data.readInt16BE();
console.log(`data converted`, number1);
// WRITE data
const number2 = Buffer.allocUnsafe(16);
number2.writeInt16BE(Math.random() * 100);
return reader.write(4, number2, 16);
})
.then(() => {
console.log(`data written`);
})
.catch(err => {
console.log(`error`, err);
});
}); But I recommend you to use Babel transpiler (with Webpack) in your Electron app. You can take a look at https://github.com/chentsulin/electron-react-boilerplate, where both Babel and Webpack are set up. If you have difficulties, I can help you set it up in your app if you want. Hope, it helps. |
Of course! Promises! Great idea @pokusew I'll have to give that a try when I build my desktop app. |
Hi @pokusew,
Thanks for the great library, it has saved me a lot of time! I am currently working on a app that should write some data to a Mifare 1Kb card from within an Electron app.
Because Electron does not support
async
andawait
I'm having some trouble integrating the example as shown in the readme.This is my current code:
This however does not work, I alway get the
blocks successfully authenticated
message, but I think that this since i removedawait
the catch function never gets called. The error message that I receive isUncaught (in promise) WriteError: Write operation failed: Status code: 0x6300
. Please see the screenshot below for the full output (the Data and Object array that are logged are other functions from the program, separate from this issue):If you require any more information I would be happy to provide it!
Thanks in advance,
The text was updated successfully, but these errors were encountered: