Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Send() os not working #80

Open
vidyajejurkar opened this issue May 15, 2017 · 5 comments
Open

Send() os not working #80

vidyajejurkar opened this issue May 15, 2017 · 5 comments

Comments

@vidyajejurkar
Copy link

vidyajejurkar commented May 15, 2017

Need help.I am not able to send data to device.

@swallowsonny
Copy link

public void run() {
byte[] buffer;
ArrayList arr_byte = new ArrayList();

        // Keep listening to the InputStream while connected
        while (true) {
            try {
                int data = mmInStream.read();
                if (data == CheckCode.FLAG_BEGIN) {     //_fix this_ 
                    arr_byte.clear();
                    arr_byte.add(data);
                } else if (data == CheckCode.FLAG_END) {   //_fix this_
                    arr_byte.add(data);
                    buffer = new byte[arr_byte.size()];
                    for (int i = 0; i < arr_byte.size(); i++) {
                        buffer[i] = arr_byte.get(i).byteValue();
                    }
                    mHandler.obtainMessage(BluetoothState.MESSAGE_READ, buffer.length, -1, buffer).sendToTarget();
                    arr_byte.clear();
                } else {
                    arr_byte.add(data);
                }
            } catch (IOException e) {
                connectionLost();
                break;
            }
        }
    }

@vidyajejurkar
Copy link
Author

Still not working :-(

public void run() {
byte[] buffer;
ArrayList arr_byte = new ArrayList();

        // Keep listening to the InputStream while connected
        while (true) {
            try {
                int data = mmInStream.read();
                if(data == 0x0A) {
                } else if(data == 0x0D) {
                    buffer = new byte[arr_byte.size()];
                    for(int i = 0 ; i < arr_byte.size() ; i++) {
                        buffer[i] = arr_byte.get(i).byteValue();
                    }
                    // Send the obtained bytes to the UI Activity
                    mHandler.obtainMessage(BluetoothState.MESSAGE_READ
                            , buffer.length, -1, buffer).sendToTarget();
                    arr_byte = new ArrayList<Integer>();
                } else {
                    arr_byte.add(data);
                }
            } catch (IOException e) {
                connectionLost();
                // Start the service over to restart listening mode
                BluetoothService.this.start(BluetoothService.this.isAndroid);
                break;
            }
        }
    }

@KingOfSu
Copy link

i have the same issue, but i use sample can send data, i put the code in my project is not working.

@KingOfSu
Copy link

i solve it but i dont know why

@DragonSoul1
Copy link

All is working except send functoin.
API 25

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants