Search code examples
javaandroidbarcode-scanner

Android: Unable to connect to integrated barcode scanner via API


This is a bit obscure ;) I'm attempting to interface with a Atid AT 911 (it has a built in 1D/2D barcode scanner) using the API provided by the company (http://sdgsystems.com/support/developers/). However, I've run into a series of snags (one of which being a lack of documentation with the majority of it being in Korean). Attempting to use the provided JARs failed, so I imported the source code into my project.

In the one file (the main scanner API file ATScanLib), this line

static{System.load(ATLib.INTERNAL_PATH + "/libat_scanner_jni.so");}

was failing to load the provided library, so based on this answer (https://stackoverflow.com/a/20818603/1275278) I changed it to

static{System.load("/data/data/ca.ticketscene.app/lib/libat_scanner_jni.so");}

and that succeeded in loading in the file. However, now when I attempt to scan it fails in the library file. I call into the API from my BarcodeScanner class:

public class BarcodeScanner implements IScanner {

private ATScanLib scanner;

@Override
public void initiateScan(Activity activity) {

    this.scanner = new ATScanLib();
    this.scanner.power(true);
    this.scanner.init();
    this.scanner.setEncoding("UTF-8");
    this.scanner.setType("2D");

    this.scanner.setOnResponseListener(new ATScanLib.OnResponseListener() {

        public void onResponse(int arg0) {

            if(arg0 == ATScanLib.READ_OK) {
                String readData = scanner.getReadResults();
            } else if(arg0 == ATScanLib.READ_ENCODING_ERROR) {
                scanner.stop();
            }
        }
    });
    this.scanner.start();
}
}

The issue happens in the call to scanner.start(). That calls into this function in the ATScanLib (provided with the API):

public class ATScanLib  {

static{System.load("/data/data/ca.ticketscene.app/lib/libat_scanner_jni.so");}

private native boolean Init(String dev, int baud);
private native void DeInit();
public native int Read(byte [] b);
private native void Power(boolean on);

public void start() {
    if ( mTask == null ) {

        mResult = new String ();

        mByteIndex = 0;
        Arrays.fill(mBytes, (byte)0);

        mSem = new Semaphore(1, true);
        try {

            mSem.acquire();

            Init(mDev, mBaud);

            mTask = new TagSequenceTask();
            mTask.execute();
        } catch (InterruptedException e1) {
            e1.printStackTrace();
        }
    } else
        Log.e("atid","::skip start");
}
}

In here, the issue is the call to Init which calls into the libat_scanner_jni.so library here:

jboolean Java_com_atid_lib_ATScanLib_Init(JNIEnv* env, jobject thiz, jstring devName, jint baud) {
int cmd;
int w;
int ret;
jboolean iscopy;

const char *dev = (*env)->GetStringUTFChars(
            env, devName, &iscopy);

ret = init_serial(&gfd_serial, dev, baud);
if(ret < 0){
    LOGE("can't open DEV_SCAN\n");
    (*env)->ReleaseStringUTFChars(env, devName, dev);
    return JNI_FALSE;
}

gObj = (jobject)(*env)->NewGlobalRef(env, thiz);      
gClassGPS = (*env)->GetObjectClass(env, gObj);  

gCallback = (*env)->GetMethodID( env, gClassGPS, "notifyRead", "()V");
if ( gCallback == NULL ) {
    LOGE("can't find method NotifyRead\n");
    (*env)->ReleaseStringUTFChars(env, devName, dev);
    return JNI_FALSE;
}

read(gfd_serial,gTempBuf, BUF_SIZE);
while(!is_empty())
    pull_char();

gfd_dev = open(NODE_FILE, O_RDWR);

ioctl(gfd_dev, IOCTL_GPJ3_OUT_CLR, 2);
close(gfd_dev);

gTerminated = JNI_FALSE;
pthread_mutex_init(&gLock, NULL);
gThr_id=pthread_create(&gTid, NULL, native_thread, NULL);

(*env)->ReleaseStringUTFChars(env, devName, dev);

return JNI_TRUE;
}

The log messages coming out of that file are:

ERROR/libnav(3302): serial dev open error(/dev/s3c2410_serial1)
ERROR/libnav(3302): can't open DEV_SCAN

I'm at a loss. All I can figure is some sort of permissions issue in that where the library file is located. I'm new to Android so this is definitely over my head and any help would be much appreciated.


Solution

  • Turns out that the supplied SDK was the wrong version for the phone I was provided with. A lengthy conversation with their tech support managed to track that down.

    If it helps anyone else, the version of the SDK that worked for me is available here: http://developer.sdgsystems.com/sdk/atid/AT911_ICS_SDK.zip