Sign in to follow this  
Followers 0
PartieHonteuse

phidgets RFID help.

10 posts in this topic

Hello everyone,

A couple of days ago my boss asked if I could do something for him using the phidgets (phidgetsusa.com) interface kit and make some generic "command line" program that would turn off the relays. Well, with browsing the web and all that stuff I made it work. It was rather exciting and now he's letting me play with the RFID reader but am completely stuck.

All I really want to do is understand in Autoit how to convert

Private Sub rfid_OnTag(ByVal TagNumber As String)

Into something that autoit can use/read. I've done this so far..

Global $TagNumber
;create the phidget rfid object
$oPhidget = ObjCreate("phidget.phidgetrfid")
;open the rfid
$oPhidget.Open(True)
;check to make sure the rfid kit is attached to the system.
If NOT $oPhidget.IsAttached Then
    ;if the interface kit is not attached then display a message box and exit
    MsgBOx(0, "Error", "The Phidget Interface Kit is not Attached!  Please attach it and try again!")
    Exit
EndIf
$oPhidget.OutputState(3) = True ;this turns on the reader

$tagnum = $oPhidget.OnTag($TagNumber)
MsgBox(0, "On Tag", $tagnum)oÝ÷ Ø'£­ßÛ&x¬ré^nëZR0j{m¡Ú"²Ú.׫²Ö§t.zË*ºUjV¬²Úâ
®¢Ö§v0¶®¢Ûkj{%jתºm«bÚºÚ"´â·lç²Æ«Ê«{l¶8À Ƨ¹©_¢»azbv­²êå

Thanks in advance for reading and hopefully a helpful hand!

Partie

Share this post


Link to post
Share on other sites



I don't have the means to test this, but I'd think your script ought to look something like this:

Global $TagNumber
;create the phidget rfid object
$oPhidget = ObjCreate("phidget.phidgetrfid")
;open the rfid
$oPhidget.Open(True)
;check to make sure the rfid kit is attached to the system.
If NOT $oPhidget.IsAttached Then
    ;if the interface kit is not attached then display a message box and exit
    MsgBOx(0, "Error", "The Phidget Interface Kit is not Attached!  Please attach it and try again!")
    Exit
EndIf
$oPhidget.OutputState(3) = True ;this turns on the reader

$SinkObject=ObjEvent($oPhidget,"RFIDEvent_")

func RFIDEvent_OnTag($tagnum)
MsgBox(0, "On Tag", $tagnum)
endfunc


while 1
  sleep(1000)
wend


[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites

Thank you for the very quick response and sorry it took me a minute to get back to you.

How do I know what an "event" is to use ObjEvent?

And now that you gave me "ObjEvent($oPhidget,"RFIDEvent_")" any new "event" i want to use I create a new function for it and make sure to use the "RFIDEvent_" prefix for that event and it should work?

$SinkObject=ObjEvent($oPhidget,"RFIDEvent_")

func RFIDEvent_OnTag($TagNumber)
MsgBox(0, "On Tag", $TagNumber)
endfunc


while 1
  sleep(1000)
wend

Share this post


Link to post
Share on other sites

Yes, I think you've got it. You can do this to detect unhandled events. Then, once you know what they are, you can create a new function to handle them, just put the event name after the _ , similar to the OnTag handler.

func RFIDEvent_OnTag($TagNumber)
MsgBox(0, "On Tag", $TagNumber)
endfunc

func RFIDEvent_($UnhandledEvent)
MsgBox(0, "Unhandled Event:", $UnhandledEvent)
endfunc


while 1
  sleep(1000)
wend

BTW, did my code work?


[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

BTW, did my code work?

Err, sorry, didn't realize I forgot to mention that yes, your code worked a treat. Thank you very much for your help and explanations!

Posted Image

Partie

Edited by PartieHonteuse

Share this post


Link to post
Share on other sites

Hi Guys-

I am a TOTAL noob at programming in general, and I have been working to create a show control system using autoIT. It's working great so far, but a key feature is having an RFID reader start playback.

I can't for the life of me figure out how to get my phidgetRFID reader to work with autoIT. All I want it to do is poll every second or so, and write the ID of any tags found to a file.

I have tried the code you posted here, but I keep getting an error that my variable type must be an object with regards to the $oPhidget.Open($TRUE) line.

Please help!

Share this post


Link to post
Share on other sites

Hi Guys-

I am a TOTAL noob at programming in general, and I have been working to create a show control system using autoIT. It's working great so far, but a key feature is having an RFID reader start playback.

I can't for the life of me figure out how to get my phidgetRFID reader to work with autoIT. All I want it to do is poll every second or so, and write the ID of any tags found to a file.

I have tried the code you posted here, but I keep getting an error that my variable type must be an object with regards to the $oPhidget.Open($TRUE) line.

Please help!

Actually, it turns out that the regKey object from Phidgets is now phidget21com.phidgetinterfacekit.1 from phidget.phidgetinterfacekit.1 and phidget21com.phidgetrfid from phidget.phidgetrfid.

I now get "device not attaced' errors (from your mesage reporting), but phidget manager, it tells me that yes, I do have an RFID device attached.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I know this post is 3+ months old but I never got a message saying there was a new reply so to GordoMandoza I do apologize.

I'm a beginner just as you are (or were from 3 months ago, yet I still am a beginner :whistle: ). Either way, give this a shot..

Global $TagNumber
;create the phidget rfid object
$oPhidget = ObjCreate("phidget.phidgetrfid")
;open the rfid
$oPhidget.Open(True)
;check to make sure the rfid kit is attached to the system.
If NOT $oPhidget.IsAttached Then
   ;if the interface kit is not attached then display a message box and exit
    MsgBOx(0, "Error", "The Phidget Interface Kit is not Attached!  Please attach it and try again!")
    Exit
EndIf
$oPhidget.OutputState(3) = True;this turns on the reader
$oPhidget.OutputState(2) = False; this turns OFF the onboard LED
$oPhidget.OutputState(1) = False; turns OFF the post LED
$oPhidget.OutputState(0) = False; turns OFF the 5V lead
$SinkObject=ObjEvent($oPhidget,"RFIDEvent_")
    
func RFIDEvent_OnTag($tagnum)
    FileWrite(@ScriptDIr & "\output.txt", $tagnum & @LF)
;MsgBox(0, "On Tag", $tagnum)
endfunc


while 1
sleep(10000)
wend

This is initialize and turn on the rfid reader. Then, when you put a rfid tag over it, it should output the rfid tag number into a file where the script is saved named output.txt.

I've just come back to this after a while so there is 1 problem that I haven't worked out yet. The rfid tag reader reads it so fast that you'll see multiple lines of the same tag number depending on how long you hold the rfid tag over the reader.

I also have the phidget manager 2.1 installed from Feb 5 of 2007 and have no problems with the code above.

Partie

Edited by PartieHonteuse

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Ok, so after I went home and didn't have the Phidgets21.msi package installed I went and installed the newest version dated June 21st. I then ran my code as above and guess what, it didn't work! I was getting the same error as GordoMandoza. The com object was initialized but my MsgBox kept saying it's not attached. After posting to the phidgets website and not getting a response for a couple of days I did some more research. Apparently the open command is now asynchronous so I added a "sleep()" command after the $oPhidget.Open() so it gave it time to open the phidget rfid. The below code works. You can take out the 1st msgbox() and also the serial number in the $oPhidget.Open().

Posted Image

Global $TagNum
;create the phidget rfid object
$oPhidget = ObjCreate("phidget21COM.phidgetrfid")
;open the rfid
$oPhidget.Open(18477)
sleep(6000)
;check to make sure the rfid kit is attached to the system.
MsgBox(0, "Test", $oPhidget.DeviceType())

If NOT $oPhidget.IsAttached Then
   ;if the interface kit is not attached then display a message box and exit
    MsgBOx(0, "Error", "The Phidget Interface Kit is not Attached!  Please attach it and try again!")
    Exit
EndIf
$oPhidget.OutputState(3) = True;this turns ON the reader
$oPhidget.OutputState(2) = False; this turns OFF the onboard LED
$oPhidget.OutputState(1) = False; turns OFF the post LED
$oPhidget.OutputState(0) = False; turns OFF the 5V lead
$SinkObject=ObjEvent($oPhidget,"RFIDEvent_")
    
func RFIDEvent_OnTag($tagnum)
    FileWrite(@ScriptDIr & "\output.txt", $tagnum & @CRLF)
    $oPhidget.OutputState(3) = FALSE
    If $tagnum = "08003332f7" Then
        With $oPhidget
            .OutPutState(2) = True
            .OutPutState(1) = True
            .Outputstate(0) = True
        EndWith
    Else
        With $oPhidget
            .OutputState(2) = False
            .OutputState(1) = False
            .OutputState(0) = False
        EndWith
        
    EndIf
;MsgBox(0, "On Tag", $tagnum)

endfunc


while 1
    Sleep(5000)
    If not $oPhidget.Outputstate(3) = True Then
        $oPhidget.OutputState(3) = True
    EndIf
WEnd
Edited by PartieHonteuse

Share this post


Link to post
Share on other sites

i tested the script using my serial number and tag but i get this error

$oPhidget.OutputState(3) = True

$oPhidget.OutputState(3) = True^ ERROR

do you can explain me why?

By

franco

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0