简体   繁体   中英

How can I read data from CT10 bluetooth barcode scanner in Phonegap?

I have a requirement that, there is a Barcode scanner. I have to implement that, the data read by barcode scanner have to display my phonegap application. I use the Bluetoothserial plugin in my project. But when I want to read or readUntil what the barcode scanner scan then the readUntil method shows no buffer. I used the function like

private String readUntil(String c) {
    LOG.d(TAG, "parameter = " + c);
    String data = "";
    int index = buffer.indexOf(c, 0);
    LOG.d(TAG, "index position = " + String.valueOf(buffer));
    if (index > -1) {
        data = buffer.substring(0, index + c.length());
        buffer.delete(0, index + c.length());
    }
    LOG.d(TAG, "action = " + data);
    return data;
}

Thanks in advance. Please help with code or any tutorial where may I get some help in code.

This is possible with a short trick. You don't need to require make connection from your app. You just connect your bluetooth device from your phone manually. Then take a text box in you application and make this text box with height to one and place it at the top left corner with z index negative value such that no end use can see this text box. Now write a recursive program which always make focus on the text box. Since if the scanner connect with your phone then if the barcode scanner reads anything then it will print in your text box and recursive or timeout function works if any thing write on the text box. I give you setTimeout function code given below:

function focusOnScanner()
{
    if($("#scannerTxt").length == 1)
    {
        document.getElementById('scannerTxt').focus();
        var scannedData = $("#scannerTxt").val();
        if(scannedData.length > 0)
        {
            $("#scannerTxt").val('');
            //Here do your work
        }
     }
     setTimeout(focusOnScanner, 5000);
}
setTimeout(focusOnScanner, 5000);

I think this will help you to solve your problem without taking any plugin or making any connection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM