Comments (10)
@AhmedBHameed added this line. could you tell if and why this is needed?
from mfrc522-rpi.
@trankin if you find out this is not needed from your point of view. please share your thoughts. we are happy about any clarification.
i have no idea why this was added.
need to wait for feedback from @AhmedBHameed
from mfrc522-rpi.
I've got a fork that I refactored to 25ms instead of 250ms to match what was documented in the comments of the file. It doesn't appear to have any negative side effects, but I don't know what was intended, or what edge case this may have been handling...
from mfrc522-rpi.
Hello @trankin,
I can't see any point to run the program without functional connected RFID card! note that I might be wrong here.
The app will hung till the loop ends but this is because of trying to find any signal from the device and expend time delay more for each loop for a another chance.
Let me explain more about the delay process.
The maximum time for delay is around 30 seconds in case of no signal received. BUT the delay start with 0 ms and start expanding for each cycle. The reason behind this is that most of IoT is working as synchronous to match the configuration of the manufacture and for that i used Atomics.wait
since it will block the code till the respond come.
You can run the following code to see how Atomic.wait
works here.
let int32 = new Int32Array(new SharedArrayBuffer(4));
// Start calculate the time required to finish the proccess.
const startTime = process.hrtime();
// Check the memory index 0;
console.log(int32[0]);
for (let i = 250; i > 0; i--) {
const r = Atomics.wait(int32, 0, 0, 250 - i);
console.log(`${i} =>> ${int32[0]}`);
if (i === 200) {
Atomics.store(int32, 0, 123);
Atomics.notify(int32, 0, 1);
}
}
// The time required til the end.
const finishTime = process.hrtime(startTime);
const nanoseconds = finishTime[0] * 1e9 + finishTime[1];
const seconds = nanoseconds / 1e9;
console.log(`CHECK=>>: finishTime at ${seconds} s`);
My knowledge was/is not enough to control the frequency clock using javascript to determine the exact time required. so i went with a exponential delay
and leave the application take the time required for configuration.
I didn't care about the time value since the exponential delay
was solving my issue at any time the configuration complete. I'm happy to hear that you tried to reduce it without any issues.
Good luck.
from mfrc522-rpi.
Will close this issue. Feel free to reopen it.
from mfrc522-rpi.
I can't see any point to run the program without functional connected RFID card! note that I might be wrong here.
I think he has build an application with this package and its running in the same node process. is my assumption correct @trankin ?
I mean whatever you would probably do with this package, you would probably add some code to the node process where the mfrc522-rpi is running.
and a delay that randomly blocks the node process for several seconds could create strange side-effects.
i found that we did not had any delay at this part of the application and it was added by you @AhmedBHameed in this commit
ea37c17#diff-168726dbe96b3ce427e7fedce31bb0bcR202
could you elaborate more why you added this delay? i mean it was not there before, and i was not aware of any communication issues reported.
my understanding is you wanted to give the MFRC522 more time to get the respond from the RFID chip? but how do we know when this exact time is? i mean couldn't it be that the node process is still blocked and the respond is already rdy..?
would there not be another way without blocking the node process?
from mfrc522-rpi.
Hello @firsttris,
TBH, I'm sure that I added this line for a reason but can't remember it unfortunately!!!
I did test the code without this line and do work perfectly so i follback to the priginal code and opened PR.
I Also did a test with the same module running while plugging out and plugging in all wires and still work perfectly [Note that i made RJ-45 for the connect for ease of use].
It is also important to mention that the module is Synchronous
which means that has to be wrapped with asynchronous function like setTimeout
or cron job
for example.
Hope that also solve the issue for @trankin.
from mfrc522-rpi.
hey @AhmedBHameed i really appreciate that you say it this honestly. not everyone is so honest. thx for your help.
@trankin might be already working on a new project 👍
ill close this one
from mfrc522-rpi.
Yes, I've got this code integrated into another working application where the blocking causes unacceptable side effects where other asynchronous code and event loops stop operating until this method returns.
There are a number of reasons that would cause the device to be non functioning, one of the cases in my scenario is that I'm debugging and testing my code in a windows environment where the raspberry pi pins are mocked instead of real.
.. I can certainly code around this, and / or move this code into another process. I will likely refactor this library if possible to make the calls asynchronous instead of synchronous. <== I feel like asynchronous execution is more in the nature of the language in general.
I may be wrong in my ability to refactor this code, but .. any pitfalls I may encounter or insight would be appreciated.
Note, that I just read that you have a PR in to adjust this code back to the original scenario. I will say that I have a fork of this already that I have removed the offending line and it appears to also be working as expected in both the windows and linux (pi) environment.
Thanks,
Thomas
from mfrc522-rpi.
@trankin
the code was originally migrated from an arduino project.
keep in mind we probably do not have more knowledge than you do!
if you have success in your async refactoring i would really appreciate a pull-request.
you have to give something back 😏 🙌
best regards
Tristan
from mfrc522-rpi.
Related Issues (17)
- Unable to determine hardware version. I see: Hardware : BCM2835 HOT 9
- MFRC522 not working on RPi 4 HOT 5
- Increasing range of MFRC522 HOT 2
- MFRC522-python not working after running mfrc522-rpi HOT 1
- 7 byte uid HOT 1
- Cannot get continuous read HOT 5
- Atomics.wait cannot be called in this context HOT 12
- Pin in use
- Request for publishing the package in npm
- Race condition(?) on a mifare ISO/IEC 14443-4 card
- Request for publishing the repo in npm
- Error while reading! Status: false Data: 55 BitSize: 0
- Use SPI1 HOT 8
- Error: Cannot find module '../build/Release/WiringPi HOT 6
- Example of how to write on NTAG213, if possible HOT 3
- LEDs on module HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mfrc522-rpi.