firsttris / mfrc522-rpi

:key: Control your MFRC522 RFID Module with your Raspberry-pi and JavaScript
MIT License
118 stars 35 forks source link

Atomics.wait cannot be called in this context #20

Closed devrim-oguz closed 3 years ago

devrim-oguz commented 4 years ago

My electron build on Raspberry Pi 4 B gives this error:

Uncaught TypeError: Atomics.wait cannot be called in this context
    at Atomics.wait (<anonymous>)
    at MFRC522.setResetPin (/home/alba/Interface_Automat_ArGe/node_modules/mfrc522-rpi/index.js:32)
    at rfid_controller.js:19

It is shown to be caused by the line 32 of index.js -> Atomics.wait( new Int32Array(new SharedArrayBuffer(4)), 0, 0, 50);

can't we replace these Atomics.wait with something else for electron compatibility?

devrim-oguz commented 4 years ago

Edit: I have just seen the commit to resolve the issue, I guess it is caused by the npm package coming from behind. Can you update the npm repo?

firsttris commented 4 years ago

hey @devrim-oguz can you check 2.1.3. an report back?

thx for reporting

Tristan

devrim-oguz commented 4 years ago

I cleared the node modules, removed the libray from the package.json file and installed the v2.1.3, issue seems to be still there, code doesn't seem to be changed.

Thanks for the quick response.

devrim-oguz commented 4 years ago

Ok, my bad I'm so sorry. The commited code of "AhmedBHameed" #17 is on the line 202, whereas the electron gives the error on "line 32" of the index.js file. Can this issue be fixed by replacing it with something else?

// Hold RESET pin low for 50ms to hard reset the reader
    rpio.open(this.reset_pin, rpio.OUTPUT, rpio.LOW);
    Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 50);   //<- This line gives the error (Line 32 of index.js)
    rpio.write(this.reset_pin, rpio.HIGH);
    return this;
firsttris commented 4 years ago

can you report back if this works?

  setResetPin(pin = 22) {
    if (!pin) {
      throw new Error(
        "Invalid parameter! reset pin parameter is invalid or not provided!"
      );
    }
    this.reset_pin = pin;
    // Hold RESET pin low for 50ms to hard reset the reader
    rpio.open(this.reset_pin, rpio.OUTPUT, rpio.LOW);
    setTimeout(function() {
          rpio.write(this.reset_pin, rpio.HIGH);
    }, 50);
    return this;
  }

or if you know a better way.

firsttris commented 4 years ago

feel free to create a pull-request to fix this issue! i will release a new version.

devrim-oguz commented 4 years ago

Thanks for quick response again, I've tried the code

setResetPin(pin = 22) {
    if (!pin) {
      throw new Error(
        "Invalid parameter! reset pin parameter is invalid or not provided!"
      );
    }
    this.reset_pin = pin;
    // Hold RESET pin low for 50ms to hard reset the reader
    rpio.open(this.reset_pin, rpio.OUTPUT, rpio.LOW);
    setTimeout(function() {
          rpio.write(this.reset_pin, rpio.HIGH);
    }, 50);
    return this;
  }

and it gives an error of the pin not being defined, but I figured that it is caused by this.reset_pin since the reset pin belongs to the parent function, so changed the code like this:

setResetPin(pin = 22) {
    if (!pin) {
      throw new Error(
        "Invalid parameter! reset pin parameter is invalid or not provided!"
      );
    }
    this.reset_pin = pin;
    // Hold RESET pin low for 50ms to hard reset the reader
    rpio.open(this.reset_pin, rpio.OUTPUT, rpio.LOW);
    setTimeout(function() {
          rpio.write(this.reset_pin, rpio.HIGH);
    }.bind(this), 50);
    return this;
  }

and this time it worked. Thanks for the help, I will create a pull request in a few minutes after testing it again.

devrim-oguz commented 4 years ago

I created a pull request in #21 but only changed the package.json file to update the version number. Is this enough or more changes neededed for a version update? Can you update the required parts before updating the npm package please?

devrim-oguz commented 4 years ago

Created a new pull-request by changing both the package.json file and the package-lock.json file. Can you please review the changes before merging it?

devrim-oguz commented 4 years ago

Also, what does the new Int32Array(new SharedArrayBuffer(4)) do in the Atomics.wait function?

devrim-oguz commented 4 years ago

Hey, did you forgot about the pull request? 😊

devrim-oguz commented 3 years ago

Issue resolved in #22. Closing the issue.