如何从蓝牙条码扫描器读取数据符号CS3070到Android设备

如何从蓝牙条码扫描器读取数据符号CS3070到Android设备,第1张

概述在我的项目中,我必须使用条形码扫描器Symbol CS3070通过蓝牙阅读条形码.即;我必须通过蓝牙建立 Android设备和条码扫描器之间的连接.任何人都可以告诉我如何从条形码阅读器读取值,以及如何设置通信?我已经阅读了 Bluetooth Developer Guide,我不想在蓝牙键盘仿真(HID)模式下使用条码阅读器(我有一些可以使用软键盘和条形码读取器填充的文本视图,我无法控制焦点) 我 在我的项目中,我必须使用条形码扫描器Symbol CS3070通过蓝牙阅读条形码.即;我必须通过蓝牙建立 Android设备和条码扫描器之间的连接.任何人都可以告诉我如何从条形码阅读器读取值,以及如何设置通信?我已经阅读了 Bluetooth Developer Guide,我不想在蓝牙键盘仿真(HID)模式下使用条码阅读器(我有一些可以使用软键盘和条形码读取器填充的文本视图,我无法控制焦点)

我会使用这样的线程与读者通信

private class barcodeReaderThread extends Thread {    private final BluetoothServerSocket mmServerSocket;    public barcodeReaderThread(UUID UUID_BLUetoOTH) {        // Use a temporary object that is later assigned to mmServerSocket,// because mmServerSocket is final        BluetoothServerSocket tmp = null;        try {            // MY_UUID is the app's UUID string,also used by the clIEnt code            tmp = mBluetoothAdapter.ListenUsingRfcommWithServiceRecord("barcodeScannerForSGST",UUID_BLUetoOTH);            /*             * The UUID is also included in the SDP entry and will be the basis for the connection             * agreement with the clIEnt device. That is,when the clIEnt attempts to connect with this device,* it will carry a UUID that uniquely IDentifIEs the service with which it wants to connect.             * These UUIDs must match in order for the connection to be accepted (in the next step)             */        } catch (IOException e) { }        mmServerSocket = tmp;    }    public voID run() {        BluetoothSocket socket = null;        // Keep Listening until exception occurs or a socket is returned        while (true) {            try {                socket = mmServerSocket.accept();                try {                    // If a connection was accepted                    if (socket != null) {                        // Do work to manage the connection (in a separate thread)                        inputStream mmInStream = null;                        // Get the input and output streams,using temp objects because                        // member streams are final                        mmInStream = socket.getinputStream();                        byte[] buffer = new byte[1024];  // buffer store for the stream                        int bytes; // bytes returned from read()                        // Keep Listening to the inputStream until an exception occurs                        // Read from the inputStream                        bytes = mmInStream.read(buffer);                        if (bytes > 0) {                            // Send the obtained bytes to the UI activity                            String readMessage = new String(buffer,bytes);                            //doMainUIOp(barCODE_READ,readMessage);                            if (readMessage.length() > 0 && !etMlfb.isEnabled()) //Se sono nella parte di picking                                new ServerWorker().execute(new Object[] {LEGGI_SPED,readMessage});                        }                        socket.close();                    }                }                catch (Exception ex) { }             } catch (IOException e) {                break;            }        }    }    /**      * Will cancel the Listening socket,and cause the thread to finish     */    public voID cancel() {        try {            mmServerSocket.close();        } catch (IOException e) { }    }}

谢谢

解决方法 我刚刚收到我的设备,当我配对并连接设备时,会自动将数据发送到当前关注的EditText.您使用的是什么版本的AndroID,因为我在ICS和JB上尝试使用它,并且这样做.
我没有在任何早期的版本中测试它.

编辑:

我把手机降级到了姜饼,发现它不行,但是我有一个解决方案:

这个很重要! >>首先,您必须扫描手册中的“串行端口配置文件(SPP)”中的条形码.

btAdapter = BluetoothAdapter.getDefaultAdapter();if (btAdapter.isEnabled()){    new BluetoothConnect().execute("");}public class BluetoothConnect extends AsyncTask<String,String,VoID>{    public static String MY_UUID = "00001101-0000-1000-8000-00805F9B34FB";    @OverrIDe    protected VoID doInBackground(String... params)    {        String address = DB.Getoption("bluetoothAddress");        BluetoothDevice device = btAdapter.getRemoteDevice(address);        try        {            socket = device.createRfcommSocketToServiceRecord(UUID.fromString(MY_UUID));            btAdapter.canceldiscovery();            socket.connect();            inputStream stream = socket.getinputStream();            int read = 0;            byte[] buffer = new byte[128];            do            {                try                {                    read = stream.read(buffer);                    String data = new String(buffer,read);                    publishProgress(data);                }                catch(Exception ex)                {                    read = -1;                }            }            while (read > 0);        }        catch (IOException e)        {            e.printstacktrace();        }        return null;    }    @OverrIDe    protected voID onProgressUpdate(String... values)    {        if (values[0].equals("\r"))        {            addToList(input.getText().toString());            pickupinput.setText("");        }        else input.setText(values[0]);        super.onProgressUpdate(values);    }}

这是我工作代码的不完整版本,但你应该得到要点.我希望这个解决方案也适合你!

总结

以上是内存溢出为你收集整理的如何从蓝牙条码扫描器读取数据符号CS3070到Android设备全部内容,希望文章能够帮你解决如何从蓝牙条码扫描器读取数据符号CS3070到Android设备所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1133720.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存