Multiple RFID Readers

Legacy support with Phidget21
davidwsshaw

Multiple RFID Readers

Postby davidwsshaw » Thu Jul 28, 2011 12:04 pm

Hi all,

I've read on these boards and in the manual that in order to use two readers you should disable/enable them in sequence with a delay in there.

Unfortunately I can't get this to work, my code sees them both at the same time and won't differentiate between the two readers.

They are initialised like this

Code: Select all

rfid.open("localhost", 5001, 35846);
rfid2.open("localhost", 5001, 11506);


I've got a function for each RFID change

Code: Select all

function RFID1on():void{
   rfid.Antenna = true;
   trace("rfid one is on");
}

function RFID1off():void{
   rfid.Antenna = false;
   trace("rfid one is off");
}

function RFID2on():void{
   rfid2.Antenna = true;
   trace("rfid two is on");
}

function RFID2off():void{
   rfid2.Antenna = false;
   trace("rfid two is off");

}


A timer that calls them in sequence

Code: Select all

var myTimer:Timer = new Timer(1000);
myTimer.addEventListener(TimerEvent.TIMER,timerListener);


function timerListener (e:TimerEvent):void{
   RFID1on();
   trace(rfid.Antenna, rfid2.Antenna);
   RFID1off();
   trace(rfid.Antenna, rfid2.Antenna);
   RFID2on();
   trace(rfid.Antenna, rfid2.Antenna);
   RFID2off();
   trace(rfid.Antenna, rfid2.Antenna);


And I get results in the output like this

Code: Select all

rfid one is on
true true
rfid one is off
true true
rfid two is on
true true
rfid two is off
true true
rfid one is on
false false
rfid one is off
false false
rfid two is on
false false
rfid two is off
false false


See how the are both doubled up?

Any help would be much appreciated!

Thanks.

mphi
Phidgetly
Posts: 39
Joined: Tue Nov 16, 2010 4:27 pm
Contact:

Re: Multiple RFID Readers

Postby mphi » Thu Jul 28, 2011 2:23 pm

After you have set Phidget information, you should wait a little while before displaying its value. You will have to give the Phidget enough time to properly set the value. This is especially important in Flash where the WebService is used.

Here is sample code:

Code: Select all

import com.phidgets.*;
import com.phidgets.events.*;

var rfid:PhidgetRFID = new PhidgetRFID();
var rfid2:PhidgetRFID = new PhidgetRFID();

var rfid1interval;
var rfid12nterval;

rfid.addEventListener(PhidgetEvent.ATTACH,   onAttach);
rfid.open("localhost", 5001, "1234", 32450);

rfid2.addEventListener(PhidgetEvent.ATTACH,   onAttach2);
rfid2.open("localhost", 5001, "1234",  33502);

function onAttach(evt:PhidgetEvent):void{
   trace ("RFID 1 Attached");
}

function onAttach2(evt:PhidgetEvent):void{
   trace ("RFID 2 Attached");

}

function RFID1on():void{
   rfid.LED = true;
   trace("rfid one is on");

  // trace(rfid.LED, rfid2.LED);  //it is too soon to display information
   rfid1interval = setInterval(RFID1off,500);   //so we will display it later
}

function RFID1off():void{
   trace(rfid.LED, rfid2.LED); //shows the result of RFID1on
   rfid.LED = false;
   trace("rfid one is off");

   clearInterval(rfid1interval);
   
   RFID2on();
}

function RFID2on():void{
   rfid2.LED = true;
   trace("rfid two is on");
   
   // trace(rfid.LED, rfid2.LED);  //it is too soon to display information
   rfid12nterval = setInterval(RFID2off,500); //so we will display it later
}

function RFID2off():void{
   trace(rfid.LED, rfid2.LED); //shows the result of RFID2on
   rfid2.LED = false;
   trace("rfid two is off");

    clearInterval(rfid12nterval);
}

var myTimer:Timer = new Timer(2000);
myTimer.addEventListener(TimerEvent.TIMER,timerListener);
myTimer.start()

function timerListener (e:TimerEvent):void{
   trace("\n")
    trace(rfid.LED, rfid2.LED); //initial state
   
    RFID1on();
}

davidwsshaw

Re: Multiple RFID Readers

Postby davidwsshaw » Fri Jul 29, 2011 8:24 am

That worked perfectly :!:

Thank you so much :D


Return to “ActionScript 3.0 - Flash CS3 / Flex / AIR”

Who is online

Users browsing this forum: No registered users and 1 guest