RFD2000 trigger event blocked by TCP connection?

Good morning,

I'm currently developing a relatively simple RFID reader app for the TC20/RFD2000 using the RFID API3.

Its point is to scan RFIDs and send the tag data to a server application in JSON format via a simple TCP socket.

Now, for some reason I can't figure out, once I run the connection task that creates my TCP client instance and listens for server response, the trigger of the RFD2000 stops working. Checking Logcat I see that instead of the usual

05-25 09:06:58.444 13429-13447/com.saco.mrott.rfidapp I/Android SDK API: Notification_TriggerEvent TRIGGER_PRESS

    Notification_TriggerEvent TRIGGER_RELEASE

I get a lot of

05-25 09:06:54.663 13429-13429/com.saco.mrott.rfidapp D/RFIDAPI3: broadcast: TRIGGERScom.symbol.button.R1

05-25 09:06:54.900 13429-13429/com.saco.mrott.rfidapp D/RFIDAPI3: broadcast: TRIGGERScom.symbol.button.R1

05-25 09:06:55.155 13429-13429/com.saco.mrott.rfidapp D/RFIDAPI3: broadcast: TRIGGERScom.symbol.button.R1

05-25 09:06:56.152 13429-13429/com.saco.mrott.rfidapp D/RFIDAPI3: broadcast: TRIGGERScom.symbol.button.R1

05-25 09:06:56.349 13429-13429/com.saco.mrott.rfidapp D/RFIDAPI3: broadcast: TRIGGERScom.symbol.button.R1

instead.

I'm relatively new to android development, but from what I gather it would appear that the notification event doesn't fire as it's supposed to.

I have no idea why this is, the TCPclient class I wrote has literally nothing to do with the API. What am I doing wrong?

Here's the class:

package com.saco.mrott.rfidapp.home.classes;

import com.saco.mrott.rfidapp.home.application.Interfaces;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.util.List;

/**
* Very basic TCP client class that connects to a server on a specified port (port=6666 for testing,
* we will see what port we later need to use) and is able to send and receive messages.

*/

public class TCPclient {

   public static final String SERVER_IP = "192.168.199.103";
  public static final int SERVER_PORT = 6666;

  private String mServerMessage;
  private Interfaces.OnMessageReceived mMessageListener = null;

  private Boolean mRun = false;

  private PrintWriter mBufferOut;
  private BufferedReader mBufferIn;

  public TCPclient (Interfaces.OnMessageReceived listener){

   mMessageListener = listener;
   }

   public void sendMessage (final String message){

  Runnable runnable = new Runnable() {

   @Override
   public void run() {

   if (mBufferOut != null) {

   mBufferOut.println(message + "\r\n");
   mBufferOut.flush();
   }

  }

  };
   Thread thread = new Thread(runnable);
   thread.start();
   }

   public void stopClient() {

   mRun = false;

  if (mBufferOut != null) {

   mBufferOut.flush();
   mBufferOut.close();
   }

   mMessageListener = null;
   mBufferIn = null;
   mBufferOut = null;
   mServerMessage = null;

   }

   public void run() {

   mRun = true;

  try {

  InetAddress serverAddress = InetAddress.getByName(SERVER_IP);
   Socket socket = new Socket(serverAddress, SERVER_PORT);

  try {

   mBufferOut = new PrintWriter(socket.getOutputStream());
   mBufferIn = new BufferedReader(new InputStreamReader(socket.getInputStream()));
  int charsRead = 0;
  char[] buffer = new char[1024];

  while (mRun) {

  charsRead = mBufferIn.read(buffer);
   mServerMessage = new String(buffer).substring(0, charsRead);
  if (mServerMessage != null && mMessageListener != null) {

   mMessageListener.messageReceived(mServerMessage);
   }

   mServerMessage = null;
   }

  } catch (Exception e) {

   // handle this somehow
   } finally {

  socket.close();
   }

  } catch (Exception e) {

   // handle this somehow
   }

  }

}

and the AsyncTask that handles the connection:

public class ConnectTask extends AsyncTask<String, String, TCPclient> {

   @Override
   protected TCPclient doInBackground (String... message) {

   mClient = new TCPclient(new Interfaces.OnMessageReceived() {

   @Override
   public void messageReceived(String message) {

  publishProgress(message);
   }

  });

   mClient.run();

  return null;
   }

   @Override
   protected void onProgressUpdate (String... values) {

   super.onProgressUpdate(values);

   // handle server response here


   }

   @Override
   protected void onCancelled() {

   super.onCancelled();

   mClient.stopClient();
   }

}

Marwin Rott
If I run the ConnectTask on a

If I run the ConnectTask on a button press and cancel it afterwards (still within the OnClickListener), I get some weird behavior:

Clicking the button once will successfully send whatever message I want to the server, but the trigger will still be blocked.

Clicking it again will seemingly free up the trigger again.

Generally, the trigger will only work again if I set the instance of the TCPclient class that the task creates to null, calling the stopClient() function is not enough.

I deduce from this that the problem seems to be the instance of that class existing, but why this would block trigger event notifications I have absolutely no idea.

Anyone able to help? This is a blocker for me, I don't know what to do.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Marwin Rott
Further testing seems to

Further testing seems to confirm this.

I created a barebones project with just the absolutely necessary bits of code in it:

The API itself as well as connection to the reader, basic setup to allow listening for trigger presses and basic textViews as status output,

added to this only the TCPclient class shown above and the connection task used to run the client.

As soon as the client is instantiated, trigger events do not register any more. So it's definitely the client and I can rule out any other interactions within my main app. I still do not understand why this happens, however.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Marwin Rott
Nevermind, I found the issue

Nevermind, I found the issue myself ...

Executing the ConnectTask on THREAD_POOL_EXECUTOR fixes it. The more you know ...

Vote: 
Vote up!
Vote down!

Points: 1

You voted ‘up’


Jacob Haaf-Murphy
Did you ever find a solution

Did you ever find a solution to this? I believe I am having a similar problem with the RFID event triggers not firing.
Edit: Was able to see the comments after posting and executing a thread I am using on THREAD_POOL_EXECUTOR resolved the issue.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments