So I'm using some APDUs to get information from a smart card with Node.js and pcsclite.
The problem is that the pcsclite function transmit is asynchronous and I need to send the APDU's in order and get their result in order.
For example, I read some sequential data in chunks of 258bytes and I increase by 1 one of the transmit parameters by 6 times, but since the function is asynchronous it does not always work as intended.
Also sometimes the data isn't even stored/available yet and it's already calling the next function.
I've tried to use Promises but I couldn't make it work(not sure if my fault) because it resolves the Promise before getting the info from the smart card(I think it's because it calls the transmit function, which has a callback where I'm doing the data storing. And since the transmit function was already called and there's nothing else to do on the promise it resolves it?)
I've also tried to use timeouts which kinda works but is not consistent.
This is what I need to do: Send apduA, get result1. Result1 is good, send apduB, get result 2.. send apduX, get resultX, increment apduX, get resultX2..
And the main problem is that I need to wait for the smart card reader to get the data before progressing in the code.
How should I resolve this?
Thanks in advance.
via jm8FE
No comments:
Post a Comment