Android - Barcode Control Specification

tibburfrogtownMobile - Wireless

Dec 14, 2013 (3 years and 9 months ago)

132 views

Winmate® Software Application
Note
Project Name:
Android - Barcode Control
Specification
Revision: 1.1
June 18, 2012
Winmate
1
Contents
1.Spec. Description........................................................................................................................3
1.1 Introduction........................................................................................................................3
1.2 System Overview..............................................................................................................3
1.3 Software Design - Barcode control process.......................................................4
1.3.1 Enable/ disable barcode service in WDC (Winmate Data Capture).......4
1.3.2 Enable/ disable the power of barcode..................................................................4
1.3.3 Receive the barcode broadcast message from android...............................4
1.3.4 Access com port in JNI layer......................................................................................4
1.4 Optional function:............................................................................................................5
1.4.1 Virtual keys (Home, Menu, Back, Search) enable/disable.........................5
Appendix.................................................................................................................................................6
A.Enable/Disable barcode service in WDC..............................................................6
B.Enable/Disable power of barcode...........................................................................7
C.Receive barcode broadcast.........................................................................................9
D.Access comport in JNI layer.....................................................................................10
E.Enable/Disable virtual keys (Home, Menu, Back and Search)...............12
Winmate
2
Revision History
Revision
Author
Date
Description
1.0
Perry
2012/06/08
1. Initial draft
1.1
Perry
2012/06/19
1.Add virtual key enable/disable
Winmate
3
1.Spec.Description
1.1 Introduction
This specification describes how to control the barcode scanner on the android phone.
The developer must implement the application to meet this specification.
1.2 System Overview
Application: Winmate Data Capture (WDC)
Service: To receive the barcode broadcast message.
Library: Access com port to controlling the barcode scanner.
Hardware: E430T (E430M, C350T)
Barcode Module: Opticon Barcode 2D (MDI-3100-Serial-SR) or Barcode 1D (M3 CCD)
Android OS
Application (WDC)
Barcode
Module
Library
(JNI)
Barcode
Service
Hardware
Winmate
4
1.3 Software Design - Barcode control process
1.3.1 Enable/ disable barcode service in WDC (Winmate Data Capture)
When the mobile is booted, the barcode service will automatically run in the
background.
See Appendix A.- Enable/Disable barcode service.
1.3.2 Enable/ disable the power of barcode.
When the mobile is turn on, the barcode power is disabling. You need to turn on the
barcode power then you can control it.
See Appendix B.- Enable/Disable power of barcode.
1.3.3 Receive the barcode broadcast message from android.
When you pressed function button, it will send a broadcast message, so you need to
register a broadcast receiver in your project.
See Appendix C.- Receive barcode broadcast.
1.3.4 Access com port in JNI layer
1) Open com port
2) Write trigger command to barcode
3) Read message from barcode
See Appendix D.- Access com port in JNI layer.
Winmate
5
1.4 Optional function:
1.4.1 Virtual keys (Home, Menu, Back, Search) enable/disable
You can disable the virtual keys when you using barcode function.
See Appendix E.– Enable/Disable virtual keys (Home, Menu, Back and Search)
Winmate
6
Appendix
A.Enable/Disable barcode service in WDC
Send broadcast message to enable/disable barcode service in WDC:
Broadcast Message:
Enable : android.intent.action.BARCODE_ENABLE_NOTIFY
Disable : android.intent.action.BARCODE_DISABLE_NOTIFY
Sample code:
//Enable Barcode Service
Intent intent = new Intent("android.intent.action.BARCODE_ENABLE_NOTIFY");
sendOrderedBroadcast(intent, null);
//Disable Barcode Service
Intent intent = new Intent("android.intent.action.BARCODE_DISABLE_NOTIFY");
sendOrderedBroadcast(intent, null);
Winmate
7
B.Enable/Disable power of barcode.
Access the node “/dev/barcode_enable” via JNI layer, then write data “0” to disable
barcode power or write “1” to enable barcode power.
Sample code for Java layer:
// ****************************************************************************
// Declare Native Function
// ****************************************************************************
public native int BarcodePower (String path, String data);
// ****************************************************************************
// Implement function
//
//path = /dev/barcode_enable
//Enable Barcode Power => data = “1”;
//Disable Barcode Power => data = “0”;
//
// ****************************************************************************
public void BarcodePowerEnable(Boolean isEnable){
String path = "/dev/barcode_enable"; //Barcode_enable node path
if(isEnable)
BarcodePower(path, “1”); //Enable Barcode Power => data = “1”;
else
BarcodePower(path, “0”); //Disable Barcode Power => data = “0”;
}
Winmate
8
Sample code for JNI layer:
// ****************************************************************************
// Implement native function
//
//path = /dev/barcode_enable
//
// ****************************************************************************
JNIEXPORT jint JNICALL Java_com_winmate_demo_main_BarcodePower
(JNIEnv * env, jobject thiz, jstring path, jstring data) {
int fd = 0;
const char *cPath, *cData;
if (path == NULL) return false;
// Convert jstring to char pointer
cPath = (*env)->GetStringUTFChars(env, path, NULL);
cData = (*env)->GetStringUTFChars(env, data, NULL);
// Open node “/dev/barcode_enable”
fd = open(cPath, O_WRONLY | O_NOCTTY | O_NDELAY | O_NONBLOCK);
if (fd < 0) {
// Release char pointer
(*env)->ReleaseStringUTFChars(env, path, cPath);
(*env)->ReleaseStringUTFChars(env, data, cData);
return -1;
}
// Write data to the node “/dev/barcode_enable”,
// Enable Barcode Power => write data = “1”;
// Disable Barcode Power => write data = “0”;
write(fd, cData, strlen(cData));
// Release char pointer
(*env)->ReleaseStringUTFChars(env, path, cPath);
(*env)->ReleaseStringUTFChars(env, data, cData);
close(fd);
return 0;
}
Winmate
9
C.Receive barcode broadcast.
Barcode broadcast message: android.intent.action.BARCODE_NOTIFY
1) Register a broadcast receiver in the AndroidManifest.xml
2) Implement a broadcast receiver
Sample code:
// **************************************************************************
// Register a broadcast receiver in the AndroidManifest.xml
// **************************************************************************
<receiver android:name=".BarcodeDemoReceiver">
<intent-filter>
<action android:name="android.intent.action.BARCODE_NOTIFY"/>
<category android:name="android.intent.category.HOME"/>
</intent-filter>
</receiver>
// **************************************************************************
// Implement a broadcast receiver
// **************************************************************************
public class BarcodeDemoReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(“android.intent.action.BARCODE_NOTIFY”)) {
// Do something….
}
}
}
Winmate
10
D.Access comport in JNI layer
// ***************************************************************************
// Comport configuration
//
//Comport:/dev/ttyO0
//Baud rate: 9600
//bits per second: 8
//parity: none
//stop bits: 1
//
// ***************************************************************************
int configure_port(int fd) // comport configuration
{
struct termios port_settings; // structure to store the port settings
tcflush(fd, TCIOFLUSH);
cfsetispeed(&port_settings, B9600); // set baud rates, default : 9600
cfsetospeed(&port_settings, B9600);
port_settings.c_cflag &= ~CRTSCTS;
port_settings.c_cflag &= ~PARENB; // set no parity, stop bits, data bits
port_settings.c_cflag &= ~CSTOPB;
port_settings.c_cflag &= ~CSIZE;
port_settings.c_cflag = CS8 | CLOCAL | CREAD;
port_settings.c_oflag = 0;// RAW Mode
tcflush(fd, TCIOFLUSH);
tcsetattr(fd, TCSANOW, &port_settings); // apply the settings to the port
return (fd);
}
Winmate
11
//******************************************************************
// Access comport
//
//1) Open comport “/dev/ttyO0”
//2) Write trigger command : {0x1B, 0x5A, 0x0D} (See menu_book command list)
//3) Read message
//
//******************************************************************
JNIEXPORT jstring JNICALL Java_com_winmate_demo_test_ ComportAccessDemo
(JNIEnv * env, jobject thiz) {
char TriggerCommand[3] = {0x1B, 0x5A, 0x0D}; // for 2D Barcode(Opticon)
char Result[1024];
jstring jResult = NULL;
int size = 0, fd = 0;
// Open comport “/dev/ttyO0”
fd = open(“/dev/ttyO0”, O_WRONLY | O_NOCTTY | O_NDELAY | O_NONBLOCK);
if (fd < 0) return (*env)->NewStringUTF(env, "OPEN_ERROR");
//Comport configuration
configure_port(fd);
// Write trigger command to the comport
write(fd, TriggerCommand, strlen(TriggerCommand));
// Read string from comport
Int size = read(fd, Result, sizeof(Result));
// Convert char to jstring
jResult = (*env)->NewStringUTF(env, Result);
// Close com port
close(fd);
return jResult;
}
Winmate
12
E.Enable/Disable virtual keys (Home, Menu, Back and
Search)
Access the node “/sys/board_properties/touch_disable” via JNI layer.
Write data “0” to enable touch panel.
Write data “1” to disable touch panel.
Write data “2” to disable virtual keys.
Note: if you write data “1” then you cannot access any function on the touch screen,
so you must be careful to use this function.
Sample code for Java layer:
// ****************************************************************************
// Declare Native Function
// ****************************************************************************
public native int TouchStatus (String path, String data);
// ****************************************************************************
// Implement function
//
//path = /sys/board_properties/touch_disable
//Enable touch panel => data = “0”
//Disable touch panel => data = “1”
//Disable virtual key => data = “2”
// ****************************************************************************
public void VirtualKeyStatus (int iState){
//touch_disable node path
String path = "/sys/board_properties/touch_disable";
//set touch state
TouchStatus(path, iState);
}
Winmate
13
Sample code for JNI layer:
// ****************************************************************************
// Implement native function
//
//path = /sys/board_properties/touch_disable
//
// ****************************************************************************
JNIEXPORT jint JNICALL Java_com_winmate_demo_main_ TouchStatus (JNIEnv
* env, jobject thiz, jstring path, jstring data) {
int fd = 0;
const char *cPath, *cData;
if (path == NULL) return false;
// Convert jstring to char pointer
cPath = (*env)->GetStringUTFChars(env, path, NULL);
cData = (*env)->GetStringUTFChars(env, data, NULL);
// Open node “/sys/board_properties/touch_disable”
fd = open(cPath, O_WRONLY | O_NOCTTY | O_NDELAY | O_NONBLOCK);
if (fd < 0) {
// Release char pointer
(*env)->ReleaseStringUTFChars(env, path, cPath);
(*env)->ReleaseStringUTFChars(env, data, cData);
return -1;
}
// Write data to the node “/sys/board_properties/touch_disable”,
//Enable touch panel => data = “0”
//Disable touch panel => data = “1”
//Disable virtual key => data = “2”
write(fd, cData, strlen(cData));
// Release char pointer
(*env)->ReleaseStringUTFChars(env, path, cPath);
(*env)->ReleaseStringUTFChars(env, data, cData);
close(fd);
return 0;
}