OpticonRL

Summary

OpticonRL is an application developed separately for multiple platforms that converts barcode data coming over a serial port into key presses. Since the majority of our products support serial communication in one way or another this can be especially useful. In effect, the barcode data is wedged into whatever application is at the forefront and has text focus, as if it were typed.

OpticonRL for Windows

This section has moved to the Windows platform page.

OpticonRL for Mac OS X

To get setup with OpticonRL for Mac

This section has moved to the Mac OS X platform page.

OpticonRL for Android

This section has moved to the Android platform page. For general information about using Opticon Products with Android devices please see the wiki page dedicated to the Android platform.

OpticonRL for Windows Mobile 6.0, 6.1, and 6.5

Use this version of OpticonRL on our H16, H19, H21 and H22 devices. This file includes installation instructions.

Download

Usage

  1. To connect to a device using OpticonRL, tap on its listing on the Windows Mobile Today Screen, which is the first screen you see when you start up your device.
  2. Tap "Discover." Wait for the operation to be completed. Your device will appear in the list if it is discoverable.
  3. Select your device from the list.
  4. Tap "Connect" to begin connecting to your device. Follow the prompts, and make sure that you enter the correct PIN code. When you are finished your device should be connected to OpticonRL.

OpticonRL for Pocket PC

All versions of Windows Mobile prior to Windows Mobile 6.0 use M2694. Current version is 2694.0A or version 1.10.

OpticonRL for Palm

OpticonRL for BlackBerry

This section has moved to the Blackberry platform page. For general information about using Opticon Products with BlackBerry please see the wiki page dedicated to the BlackBerry platform.

Software Development

Since Bluetooth Serial Port data requires an application present on the host device to receive the incoming data Opticon developed it's OpticonRL application. OpticonRL intercepts the serial data and injects it at the cursor. In some cases an application developer may wish to have direct control of the serial data and replace OpticonRL. This section contains a few hints and tips for duplicating the functionality of OpticonRL within your own application.

Android

  • The Android UI is not thread safe, so all connection handles have to be under the thread and the Handler needs to be used to talk to the UI.
  • OpticonRL is similar to Google's example. As a starting point we recommend using this example to see if the device can be connected.
<Android-sdk>/samples/android-7/BluetoothChat
  • If you have a resource busy problem it might be caused by an incorrect UUID. UUIDs do change with different Android devices. Please try several different UUIDs such as:
    • "00001101-0000-1000-8000-00805F9B34FB"
    • "fa87c0d0-afac-11de-8a39-0800200c9a66"

Code Examples

  • The Google example above does not address reconnections. An example of this is below.
Disconnections

Once the device is connected, start the ConnectedThread to begin managing a Bluetooth connection.

public synchronized void connected(BluetoothSocket socket, BluetoothDevice device) {

        // Cancel the thread that completed the connection
        if (mConnectThread != null) {
            mConnectThread.cancel(); 
            mConnectThread = null;
        }

        // Cancel any thread currently running a connection
        if (mConnectedThread != null) {
            mConnectedThread.cancel(); 
            mConnectedThread = null;
        }

        // Cancel the accept thread because we only want to connect to one device
        if (mAcceptThread != null) {
            mAcceptThread.cancel(); 
            mAcceptThread = null;
        }

        // Start the thread to manage the connection and perform transmissions
        mConnectedThread = new ConnectedThread(socket);
        mConnectedThread.start();

        // Send the name of the connected device back to the UI Activity
        Message msg = mHandler.obtainMessage(OpticonRL.MESSAGE_DEVICE_NAME);
        Bundle bundle = new Bundle();
        bundle.putString(OpticonRL.DEVICE_NAME, device.getName());
        msg.setData(bundle);
        mHandler.sendMessage(msg);

        setState(STATE_CONNECTED);

Implement ConnectedThread - When the device is disconnected, IOExceptin is thrown in while roop in run function. Notify to the UI Activity.

/*
 *
 * This thread runs during a connection with a remote device.
 * It handles all incoming and outgoing transmissions.
 *
 */
    public class ConnectedThread extends Thread {
        private final BluetoothSocket mmSocket;
        private final InputStream mmInStream;

        public ConnectedThread(BluetoothSocket socket) {
            Log.d(TAG, "create ConnectedThread");
            mmSocket = socket;
            InputStream tmpIn = null;

            // Get the BluetoothSocket input and output streams
            try {
                tmpIn = socket.getInputStream();
            } catch (IOException e) {
                Log.e(TAG, "temp sockets not created", e);
            }
            mmInStream = tmpIn;
        }
        public void run() {
            Log.i(TAG, "BEGIN mConnectedThread");
            byte[] buffer = new byte[1024];
            int bytes;

            // Keep listening to the InputStream while connected
            while (true) {
                try {

                    // Read from the InputStream
                    bytes = mmInStream.read(buffer);
                 
                    // Send the obtained bytes to the UI Activity
                    mHandler.obtainMessage(OpticonRL.MESSAGE_READ, bytes, -1,    buffer).sendToTarget();
                    
                } catch (IOException e) {
                    Log.e(TAG, "disconnected", e);
                    // Connection is LOST (disconnected from device)
                    break;
                }
            }
        }
        public void cancel() {
            try {
                mmSocket.close();
            } catch (IOException e) {
            	Log.e(TAG, "ConnectedThread close()", e);
            }
        }
    }

Reconnections

Override AsyncTask and make an application run background.

private class Reconnect extends AsyncTask<BluetoothDevice, Void, Boolean > {
    	BluetoothService mService = null;
    	boolean stopReconnect = false;
    	
    	public Reconnect(BluetoothService mService){
    		this.mService = mService;
    	}
    	
    	@Override
    	protected void onCancelled() {

    	}
    
	@Override
	protected Boolean doInBackground(BluetoothDevice... arg0) {

    	// if device is not connected, create timer and keep connecting for certain time.

	}

}

Excecute AsyncTask when device was disconnected.

	private Reconnect task = new Reconnect(mService);
	task.execute(device);



Useful links