iPhone code sample, PhidgetManager and PhidgetRFID

Supporting 10.7 and up
intomo
Phidgetly
Posts: 24
Joined: Tue May 13, 2008 11:00 pm

iPhone code sample, PhidgetManager and PhidgetRFID

Postby intomo » Thu May 05, 2011 4:25 pm

Hi.
I'm having some trouble getting a PhidgetRFID to work with iPhone.
I bought a PhidgetSBC and am extending the PhidgetManager code sample. The code sample works as expected, it recognizes when both the Phidget I/F Kit and PhidgetRFID are added. However, I need some help receiving the tags.

I've added this to the phidgetAdded method in the implementation file.
Of note: the switch statement never seems to trip so I had to put in an if statement. 32761 is the serial number of my PhidgetRFID.

Code: Select all

- (void)phidgetAdded:(Phidget *)phidget
{
   
      //NSLog(@"PHIDGET FOUND NAME: %@",phidget.name);
   
   int serial, version;
   int numOutputs;
   const char *name;
   CPhidget_DeviceID devid;
   

   
   CPhidget_getSerialNumber((CPhidgetHandle)rfid, &serial);
   CPhidget_getDeviceVersion((CPhidgetHandle)rfid, &version);
   CPhidget_getDeviceName((CPhidgetHandle)rfid, &name);
   CPhidget_getDeviceID((CPhidgetHandle)rfid, &devid);
   
   NSLog(@"PHIDGET FOUND SERIAL: %d",phidget.serialNumber);

   
   switch(devid)
   {
      case PHIDID_RFID_2OUTPUT:         
            //Turn on antenna and LED
         CPhidgetRFID_setLEDOn(rfid,1);
         CPhidgetRFID_setAntennaOn(rfid,1);
         break;
      case PHIDID_RFID:
         break;
      default:
         break;
   }
   
   if (phidget.serialNumber == 32761) {
      NSLog(@"PHIDGET RFID");
      
      
      CPhidgetRFID_create(&rfid);
      
      CPhidgetRFID_set_OnTag_Handler(rfid, gotTag, self);
      CPhidgetRFID_set_OnTagLost_Handler(rfid, lostTag, self);
      CPhidgetRFID_getOutputCount(rfid, &numOutputs);
      
      NSLog(@"PHIDGET RFID FOUND numOutputs: %d",numOutputs);
      CPhidget_DeviceID devid;
      CPhidget_getDeviceID((CPhidgetHandle)rfid, &devid);
      CPhidgetRFID_setLEDOn(rfid,1);
      CPhidgetRFID_setAntennaOn(rfid,1);
   }
}


And I've added these methods per the CocoaRFID sample.
This is what I added to the implementation file:

Code: Select all

CPhidgetRFIDHandle rfid=0;

int gotTag(CPhidgetRFIDHandle phid, void *context, unsigned char *tag) {
   [(id)context RFIDTag:tag];
   return 0;
}

int lostTag(CPhidgetRFIDHandle phid, void *context, unsigned char *tag) {
   NSLog(@"PHIDGET LOST TAG");
   
   [(id)context RFIDTagLost];
   return 0;
}



- (void)RFIDTag:(unsigned char *)tag
{
   NSLog(@"TAG: %@",[NSString stringWithFormat:@"%02x%02x%02x%02x%02x\n",tag[0],tag[1],tag[2],tag[3],tag[4]]);
}

- (void)RFIDTagLost
{
   NSLog(@"LOST TAG");
}


What am I missing?

Thanks very much.
It all compiles fine with no error for iOS 4.3.
I just don't get any tags read.
Been using Phidgets for years. Great products.

User avatar
Patrick
Lead Developer
Posts: 3078
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: iPhone code sample, PhidgetManager and PhidgetRFID

Postby Patrick » Fri May 06, 2011 9:31 am

You need to open the rfid after creating it, and then wait for it to be attached before calling any functions on it.

You can't use waitForAttachement inside the manager attach handler, so I'd suggest you set up an rfid attach handler.

Really, if you already know the serial number, I'm not sure why you need to use the manager.

-Patrick

intomo
Phidgetly
Posts: 24
Joined: Tue May 13, 2008 11:00 pm

Re: iPhone code sample, PhidgetManager and PhidgetRFID

Postby intomo » Tue May 10, 2011 3:23 pm

OIC, thanks. I will look at the RFID code sample again.

I thought if you were using a PhidgetsSBC and multiple sensors that you had to use the PhidgetsManager.


Return to “macOS”

Who is online

Users browsing this forum: No registered users and 1 guest