Version Differences for OpticonRL

(Development FAQ)
Line 16:
  Content coming soon!    Content coming soon! 
  *Download the zipped file from Opticon's FTP - [http://ftp.opticonusa.com/Downloads/OpticonRL%20for%20Android%20EGFS055x.zip Download]    *Download the zipped file from Opticon's FTP - [http://ftp.opticonusa.com/Downloads/OpticonRL%20for%20Android%20EGFS055x.zip Download] 
- ===Development FAQ===      
- The 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 the Google example. As a starting point I would recommend using this example to see if the device can be connected. Android-sdk/samples/android-7/BluetoothChat      
       
- The document about "Disconnecting and Reconnecting" is linked [https://wiki.opticonusa.com/techsupport/upload/2011/8/Android_Example-05143653.doc here].      
       
- If you have a resource busy problem 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"      
       
       
- Useful links      
       
- *http://developer.android.com/guide/topics/wireless/bluetooth.html      
- *http://developer.android.com/reference/android/os/AsyncTask.html      
  ==OpticonRL for Pocket PC==    ==OpticonRL for Pocket PC== 
  All versions of Windows Mobile PPC use M2694. Current version is 2694.0A or version 1.10.    All versions of Windows Mobile PPC use M2694. Current version is 2694.0A or version 1.10. 
Line 160:
  ::*The Auto Reconnect option causes the BlackBerry to automatically reconnect to the barcode scanner when the connection is broken. The default setting for first time use is for this option to be enabled.     ::*The Auto Reconnect option causes the BlackBerry to automatically reconnect to the barcode scanner when the connection is broken. The default setting for first time use is for this option to be enabled.  
  ::*Not all barcode devices support Auto reconnection. Currently only the OPN2002 supports the auto reconnection option.    ::*Not all barcode devices support Auto reconnection. Currently only the OPN2002 supports the auto reconnection option. 
       
    + ==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.''  
    + <pre>  
    + 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);  
    + </pre>  
    + ''Implement ConnectedThread - When the device is disconnected, IOExceptin is thrown in while roop in run function. Notify to the UI Activity.''  
    + <pre>  
    + /*  
    + *  
    + * 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);  
    + }  
    + }  
    + }  
       
    + </pre>  
    + =====Reconnections=====  
    + ''Override AsyncTask and make an application run background.''  
    + <pre>  
    + 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.  
       
    + }  
       
    + }  
    + </pre>  
    + ''Excecute AsyncTask when device was disconnected.''  
    + <pre>  
    + private Reconnect task = new Reconnect(mService);  
    + task.execute(device);  
       
    + </pre>  
       
       
       
       
    + ====Useful links====  
       
    + *http://developer.android.com/guide/topics/wireless/bluetooth.html  
    + *http://developer.android.com/reference/android/os/AsyncTask.html