CAEN RFID Reader on WAP (Windows CE)

This question is answered

Hello!

I'm looking for some code in VB.NET on how to read the EPC, TID and User memory of a RFID tag using the WAP running on Windows CE and returning the values in a textbox.

Any help would be useful as I'm new to RFID, handheld computers and VB.NET.

Verified Answer
  • Found the problem this morning: the 250ms delay (using system.threading.thread.sleep(250)) is not long enough! Since my reader was not connected, all commands sent to the reader were making the app crash.

    I used 500ms instead and everything works perfectly!

    Yes, it was that simple! But quite stupid that CAEN are not talking about this delay anywhere, and that in many demo applications 250ms is fine...

All Replies
  • Good morning,

    As a start, here is the link to our RFID SDK Download section.
    Our RFID SDKs usually come with comprehensive demo solutions.

    Kind regards,
    Jacques

  • There is a small demo, but coded in C#... Nothing in VB!

    I will try to understand, but it is a bit hard since I'm new to all this.

    Any other place I could find some code?

  • Hi Dcantin.

    Some of the demo in C# is translatable for VB.NET and others not so much.

    If you are starting out, I suggest using the RFID keyboard wedge to get started with just reading tags.

    Then move onto the harder aspects like Writing data to RFID tags.

    If you have any further issues, contact either of the Regional Help Desks, and we can assist you.

    -sean

    Sean M. Kennedy  {Americas Help Desk Application Support}

  • My application is used to record tire transactions (receiving tire, inflating tire, ...). One of the field to fill up is the tire serial number. Right now, we have to enter the serial number on the keyboard of the WAP. New tires will have RFID tags in them, so instead of entering the info manually, I need to use a button on the form to read the RFID tag and place the information in a textbox.

    So what I need is this:

    - Click on a button on a form;

    - This will call a function that will return the TID portion of the tag, and call another function that will return the User memory of the tag;

    - Use the TID portion of the tag to know which type of tire has been scanned and set a variable with that information;

    - Place the User memory of the tag in a textbox (this is the serial number).

    For now, we don't have to write anything in the tags. Just need the simplest way to read TID and user memory of a RFID tag.

  • When you download the latest CAEN SDK for WAP:  http://community.psion.com/downloads/developer_sdkhdk/m/rfid_sdk/543.aspx

    In the Samples directory, you'll find the DEMO_CAEN_READ project (as well as its counterpart, DEMO_CAEN_WRITE). 

    You'll also need to install the RfidDriverManager:  http://community.psion.com/downloads/developer_sdkhdk/m/rfid_sdk/7283.aspx, as the project uses API's that require it being installed (such as controlling power to the device).

    That project also relies on the Trigger API from our MDSDK.

    Run the DEMO_CAEN_READ sample on your device to see how it works.

    You'll notice that we use our triggers to constantly read/inventory until we get data (pressing and holding the trigger button will cause a contant inventory+bank read).  Keep that in mind when your desiging your application with the CAEN module.  Generally, the first call to read sometimes returns no tags at all (unless you're really close to the tag).

    Try to digest this sample, and then ask questions on this thread based off of it.  The APIs from CAENRFIDLibraryPocketPC have documentation in both C# and VB (see the .chm files that come with the download).  You can see the flow of the APIs from DEMO_CAEN_READ, then extrapolate for your VB project.  And again, if you run into something that doesn't make sense, post your question here about it.

  • Thanks Steven, I will have a look at this today.

    Just our of curiosity: is the source code of CAEN WEDGE available? Because that would also be nice: could place the cursor in a text box, then push a trigger, then read the tag, then place the info in the textbox...

    That would almost do what I need right away, with just a little modifications...

    EDIT: Just found source code for CAEN Wedge. Will try to understand...

  • I was able to download, build and install the CAEN Read demo.

    As soon as I open it on the WAP, I have at the top: "FAIL: CAEN Init"

    Help please! I'm really unable to do anything related to RFID on the WAP (except CAEN Demo and CAEN Wedge are working OK)!!!

  • Did you install the RFID Driver Manager?  Without this, it won't work...

  • Yep, RFID Driver manager is installed.

    When I click on "TEST", I get the error "Error while opening RS232..."

    CAEN Demo and CAEN Wedge are working OK...

    Any idea? This might also be my problem that I'm not able to read RFID in my application...

    EDIT: Just went in RFID Device 2 in the drop-down list, then clicked on "Detect". It found the same RFID Device as RFID Device 1 and (re?) installed it. Now both RFID  Device 1 and 2 seems to work when I hit the Test button. CAEN Demo and Wedge still working. My application still not working. It crashes when I try to set the power on the reader...(and if I remove that line in the code, my application crashes on the next line where I set the protocol and so on... Next lines are Getsource, then SetQ_EPC_C1_G2, then Setsession_EPC_C1G2.....Of course, impossible to read tags in the end since application crashes!)

  • Hi, 

    The first point is to check, you use the latest CAEN SDK 4.2.0 and associated RFIDLibrary (refer download section->RFID SDK)

    When you launch your appplication all the RFID demos have to be closed before.

    The steps are Enable rfid driver then use Connect to the CAEN reader. (refer developer's guide from SDK and DEMO_CAEN_READ sample)

    Reader = new CAENRFIDReader();
    try
    {
    rfidDriver.Enable();

    Reader.Connect(CAENRFIDPort.CAENRFID_RS232, "COM" + rfidDriver.ComPort.ToString() + ":115200");
    }
    catch
    {
    CAEN_Close();
    return false;
    }
    //
    // You MUST sleep this amount of time before executing other commands
    //
    System.Threading.Thread.Sleep(250);

    CAENRFIDLogicalSource[] logical_sources = Reader.GetSources();
    if (logical_sources.Length == 0)
    {
    CAEN_Close();
    return false;
    }
    m_Source0 = logical_sources[0];

    Regards,

    Jan-Manuel

  • I've been able to do the following with success:

    Public Class RFID

      Public Shared ReadOnly RfidDriver As New PsionTeklogix.RFID.RFIDDriver()
      Dim RfidReader As New com.caen.RFIDLibrary.CAENRFIDReader()
      Dim logicalSources As com.caen.RFIDLibrary.CAENRFIDLogicalSource()
      Dim source0 As com.caen.RFIDLibrary.CAENRFIDLogicalSource
      Dim tags As com.caen.RFIDLibrary.CAENRFIDTag()

      Public Shared Sub main()
        Application.Run(RFID)
      End Sub

      Public Sub Connect()

        'Check if RFID driver is installed
        If RfidDriver.IsInstalled = True Then
          lblDriverinstalled.Text = "Driver is installed"
          lblDriverinstalled.ForeColor = Color.Green
        Else
          lblDriverinstalled.Text = "Driver is not installed"
          lblDriverinstalled.ForeColor = Color.Red
        End If

        'Enable RFID Driver
        RfidDriver.Enable()

        'Get COM port number where RFIDDriver is installed
        Dim comPort As Integer = RfidDriver.ComPort
        lblcomPort.Text = String.Concat("COM", CType(comPort, String))
        lblcomPort.ForeColor = Color.Green

        'Open the connection to the reader
        RfidReader.Connect(com.caen.RFIDLibrary.CAENRFIDPort.CAENRFID_RS232, "COM1:115200")
        System.Threading.Thread.Sleep(250)
        lblReaderconnected.Text = "Connected to reader"
        lblReaderconnected.ForeColor = Color.Green

        'Find logical source
        logicalSources = RfidReader.GetSources()
        If logicalSources.Length < 0 Then
          Throw New Exception("No logical sources")
        End If
        source0 = logicalSources(0)
        lblLogicalSource.Text = "Logical Source OK"
        lblLogicalSource.ForeColor = Color.Green

    ----------------------------------------------------------------

    I'm not able to use methods like Get Power(), SetPower(), GetProtocol(), etc....(Not that much important as long as I'm able to read tags - which I'm still unable)

    What should I add to my code so that I can read one tag and place the different values in different textboxes (TagID, TagTID, TagUserMemory)? Best way to do it would also be to set the trigger for reading a tag on the "Scan button" of the WAP...

    With that last portion of code I'm still missing, I will be good to go!

    By the way, thanks Jan Manuel!

  • For application compatibility, please take care to use the following parameter:

                    Reader.Connect(CAENRFIDPort.CAENRFID_RS232, "COM" + rfidDriver.ComPort.ToString() + ":115200");

    In your code, after

        source0 = logicalSources(0)

    To perform an UHF RFID inventory

    CAENRFIDTag[] tags = source0.InventoryTag();

    You get a list of tags, with the methods getID, you will be able to display the EPC ID.

    foreach (CAENRFIDTag tag in tags)

    string IDTag = System.BitConverter.ToString(tag.GetId()).Replace("-", "");

    With this tag reference, you will be able to read TID and User memory

     // TID

    read = m_Source0.ReadTagData_EPC_C1G2(tag, 2, 0, 4); // to read 4 bytes of TID

    // User
    read = m_Source0.ReadTagData_EPC_C1G2(tag, 3, 0, 0x0c); // to read 96bits= 12bytes from address 0

    For Trigger request, please refer to DEMO_CAEN_READ



  • Jan-Manuel,

    I added this part of code:

    'Read tags
        Dim tag As com.caen.RFIDLibrary.CAENRFIDTag
        tags = source0.InventoryTag()
        For Each tag In tags
          IDtag = System.BitConverter.ToString(tag.GetId()).Replace("-", "")
          lblTag.Text = IDtag
        Next

    My application crashes on InventoryTag()...

    The RFID tag is right on the reader, could not miss it! (Actually, it finds it right away using CAEN Wedge or CAEN Demo)

    Don't understand why it doesn't work...

  • Found the problem this morning: the 250ms delay (using system.threading.thread.sleep(250)) is not long enough! Since my reader was not connected, all commands sent to the reader were making the app crash.

    I used 500ms instead and everything works perfectly!

    Yes, it was that simple! But quite stupid that CAEN are not talking about this delay anywhere, and that in many demo applications 250ms is fine...

  • Thanks for the help!