evantahler / nodePhidgets

Node.js JavaScript library to interface with the Phidgets line of hardware boards.
Other
30 stars 8 forks source link

Can't use multiple RFID readers nor interface kits #19

Closed Imadeanaccountforthis closed 8 years ago

Imadeanaccountforthis commented 8 years ago

all works perfectlly when using a single RFID reader but as soon as I try to use several, they're kind of considered as the same.

I wrote very simple code to display the tag IDs that are read by RFID readers, but whenever one reads a tag, the other "reads" it too. You'll have two "detected" calls with each emitter having the serial of a rfid reader whenever you present a tag to one of the two readers. This doesn't appear in the phidgets control board nor on the webservice itself, but when I check the webservice output I can see a "[32] - ERR: Error in set function: 5 (key:"/PCK/PhidgetRFID/386375/AntennaOn", Val:"1")" My code is pretty straightforward but I'll post it anyway

var phidgets = require("Phidgets");

var rfid2=new phidgets.PhidgetRFID();
var rfid1=new phidgets.PhidgetRFID();

rfid1.open({"serial" : 387935});
console.log(rfid1.serial);

rfid2.open({"serial" : 386375});
console.log(rfid2.serial);

rfid1.on('opened', function (emitter){
    emitter.antenna= true;
    console.log("35 "+emitter.antenna+emitter.serial);
});

rfid2.on('opened', function (emitter){
    emitter.antenna= true;
    console.log("75 "+emitter.antenna+emitter.serial);
});
rfid1.on('detected',function (emitter,tag){
    console.log(emitter.serial + " "+ tag.value)
});
rfid2.on('detected',function (emitter,tag){
    console.log(emitter.serial + " "+ tag.value)
});

EDIT: I checked it a bit more, maybe I'm doing something wrong, or maybe the problem comes from the phidgets web service, but if there's only one RFID reader connected and I open 4 in js with 4 different S/N, they'll all get connected to whichever reader is plugged in. It seems specifying the RFID serial number in open(); only writes a serial number in the javascript rfid reader object but the webservice will just assign any RFID reader to it. When I look at the webservice logs, it seems it receives perfectly well the demand for a specific SN but decides to not care? I've put the logs on pastebin as it's a bit long: http://pastebin.com/raw/WV6KLvRw I'm using the latest phidgets drivers (direct from their website), and tried this on both nw.js and node.js (on both latest and LTS). I also tried older phidgets drivers , going back to Mar 23 2015, same result

EDIT: tried the same thing with two 8/8/8 interface kits, same result, when one reads something, the other is detected as reading it too. I plugged a sensor on the port 0 of one and another on the port 1 of the other kit, both kits detect the two sensors in my javascript tests. Am I doing something wrong? it feels like the communication with the web service isn't set up correctly somehow

EDIT: also tried on a mac mini with phidget21 v2.1.8, exact same result, but trying to connect to the webservice in C++ works. I have zero experience with JS so I tried looking around in phidgets.js without much success

Imadeanaccountforthis commented 8 years ago

could anyone else confirm they can replicate this issue?

djipco commented 8 years ago

I'll check it out and get back to you.

djipco commented 8 years ago

I can confirm the issue. A fix will have to be written. As a workaround, you can filter in only the desired data by using the emitter.serial property:

pik.on('sensor', function(emitter, data) {
  if (emitter.serial === "1234567") {
    // do stuff
  }
});
Imadeanaccountforthis commented 8 years ago

Sadly I tried this and it doesn't work either, you will get an event for each "sensor" with the serial you registered as emitter.serial let's say you open two readers with SN 123456 and 654321, when one detects a tag, on the javascript side you'll really have the two readers detecting it, with two seperate "detect" events, one with emitter.serial as 123456 and another with 654321 but both reading the same tag at roughly the same time (there is an order though, the first one opened seems to be the first one to go). The first one to be opened is also the only one whose state you can change (led on/off, antenna on/off etc...).

djipco commented 8 years ago

The issue should have been fixed in version 0.5.4 (PR 20). I don't have time to run extensive tests for now but it seems to be working. Let me know if it solves the problem on your end.

Thanks for reporting it. Cheers!

Imadeanaccountforthis commented 8 years ago

I'll be trying this right away, thanks for all your work!

Imadeanaccountforthis commented 8 years ago

I currently have two rfid readers connected and can properly read tags and change antenna/led status on both, so all looks good! thanks!