Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when start acquisition mode #4

Closed
VadymKuriy opened this issue Apr 25, 2017 · 10 comments
Closed

Error when start acquisition mode #4

VadymKuriy opened this issue Apr 25, 2017 · 10 comments

Comments

@VadymKuriy
Copy link

Hello, when I do bitalino.start(new int[]{2}, 100) (status is connected) always have in BTHCommunication this exception:
java.io.IOException: bt socket closed, read return: -1
at android.bluetooth.BluetoothSocket.read(BluetoothSocket.java:733)
at android.bluetooth.BluetoothInputStream.read(BluetoothInputStream.java:96)
at java.io.InputStream.read(InputStream.java:162)
at info.plux.pluxapi.bitalino.bth.BTHCommunication$ConnectedThread.run(BTHCommunication.java:727)
Thx.

@GTelo
Copy link
Contributor

GTelo commented Apr 26, 2017

Hi @VadymKuriy,

Are you using the API's sample app?

You can only send a command to the API after receiving the device's description. For example in the sample-app module of this repository under src/java/info.plux.pluxapi.sampleapp in the DeviceActivity Class, after line 249 you have an example of an implementation that catches the description intent:

else if(ACTION_COMMAND_REPLY.equals(action)){
                String identifier = intent.getStringExtra(IDENTIFIER);

                if(intent.hasExtra(EXTRA_COMMAND_REPLY) && (intent.getParcelableExtra(EXTRA_COMMAND_REPLY) != null)){
                    Parcelable parcelable = intent.getParcelableExtra(EXTRA_COMMAND_REPLY);
                    if(parcelable.getClass().equals(BITalinoState.class)){ //BITalino
                        Log.d(TAG, ((BITalinoState)parcelable).toString());
                        resultsTextView.setText(parcelable.toString());
                    }
                    else if(parcelable.getClass().equals(BITalinoDescription.class)){ //BITalino
                        isBITalino2 = ((BITalinoDescription)parcelable).isBITalino2();
                        resultsTextView.setText("isBITalino2: " + isBITalino2 + "; FwVersion: " + String.valueOf(((BITalinoDescription)parcelable).getFwVersion()));

//                        if(identifier.equals(identifierBITalino2) && bitalino2 != null){
//                            try {
//                                bitalino2.start(new int[]{0,1,2,3,4,5}, 1);
//                            } catch (BITalinoException e) {
//                                e.printStackTrace();
//                            }
//                        }
                    }
                }
            }

It only is secure to start an acquisition and perform any other commands once you received this description.

If the problem still persists, please let me know.

Best regards,
Gonçalo Telo

@VadymKuriy
Copy link
Author

VadymKuriy commented May 1, 2017

So when I have this exception I need to start once more?

if (bluetoothDevice.getAddress().equals(identifier) && bitalino != null) {
                            try {
                                bitalino.start(new int[]{0, 1, 2, 3, 4, 5}, 1);
                            } catch (BITalinoException e) {
                                e.printStackTrace();
                            }
                        }

Because now I use only one device.
Thx.

@GTelo
Copy link
Contributor

GTelo commented May 2, 2017

Hi @VadymKuriy,

when you select the device in the Scan Activity, a new activity is started, the Device Activity, once in this activity you need to click on the Connect button, as the description will be show in the TextView available bellow the buttons in the view.

After this you can start your acquisition. The way to go is to uncomment the lines that are commented in the section of code that I added in my previous comment.

Best regards,
Gonçalo Telo

@VadymKuriy
Copy link
Author

Hi @GTelo
Yes, I use first connect

try {
                    bitalino.connect(bluetoothDevice.getAddress());
                } catch (BITalinoException e) {
                    e.printStackTrace();
                }

Than when status is connected I use

try {
                    bitalino.start(new int[]{0, 1, 2, 3, 4, 5}, 1);
                } catch (BITalinoException e) {
                    e.printStackTrace();
                }

And also have receiver

private final BroadcastReceiver updateReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();
            if (ACTION_STATE_CHANGED.equals(action)) {
                ...
            } else if (ACTION_DATA_AVAILABLE.equals(action)) {
                ...
            } else if (ACTION_COMMAND_REPLY.equals(action)) {
                String identifier = intent.getStringExtra(IDENTIFIER);
                if (intent.hasExtra(EXTRA_COMMAND_REPLY) && (intent.getParcelableExtra(EXTRA_COMMAND_REPLY) != null)) {
                    Parcelable parcelable = intent.getParcelableExtra(EXTRA_COMMAND_REPLY);
if (parcelable.getClass().equals(BITalinoDescription.class)) { //BITalino
                        if (bluetoothDevice.getAddress().equals(identifier) && bitalino != null) {
                            try {
                                bitalino.start(new int[]{0, 1, 2, 3, 4, 5}, 1);
                            } catch (BITalinoException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            }
        }
    };

But I recieved only 3 BITalinoFrame's and than device disconect.
This are logs for states changes from updateReceiver:

05-02 13:36:58.391  DeviceActivity: "" -> CONNECTED
05-02 13:36:58.591 DeviceActivity: "" -> ACQUISITION_OK
05-02 13:37:00.621 DeviceActivity: "" -> DISCONNECTED
05-02 13:37:00.621 DeviceActivity: "" -> CONNECTING
05-02 13:37:00.831  DeviceActivity: ""-> DISCONNECTED
05-02 13:37:00.851 DeviceActivity: "" -> CONNECTING
05-02 13:37:01.401 DeviceActivity: "" -> CONNECTED
05-02 13:37:01.611DeviceActivity: "" -> ACQUISITION_OK
05-02 13:37:03.631 DeviceActivity: "" -> DISCONNECTED

Thx,

@GTelo
Copy link
Contributor

GTelo commented May 2, 2017

The start should be only called after you receive the BITalino's description:

else if(ACTION_COMMAND_REPLY.equals(action)){
                String identifier = intent.getStringExtra(IDENTIFIER);

                if(intent.hasExtra(EXTRA_COMMAND_REPLY) && (intent.getParcelableExtra(EXTRA_COMMAND_REPLY) != null)){
                    Parcelable parcelable = intent.getParcelableExtra(EXTRA_COMMAND_REPLY);
                    if(parcelable.getClass().equals(BITalinoState.class)){ //BITalino
                        Log.d(TAG, ((BITalinoState)parcelable).toString());
                        resultsTextView.setText(parcelable.toString());
                    }
                    else if(parcelable.getClass().equals(BITalinoDescription.class)){ //BITalino
                        isBITalino2 = ((BITalinoDescription)parcelable).isBITalino2();
                        resultsTextView.setText("isBITalino2: " + isBITalino2 + "; FwVersion: " + String.valueOf(((BITalinoDescription)parcelable).getFwVersion()));

                        //the device is ready
                        if(identifier.equals(identifierBITalino2) && bitalino2 != null){
                            try {
                                bitalino2.start(new int[]{0,1,2,3,4,5}, 1);
                            } catch (BITalinoException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            }

This behaviour is used as a a check of the device's firmware version and only after that you can give commands. For this reason, you should only give the start command after that.

@VadymKuriy
Copy link
Author

VadymKuriy commented May 2, 2017

I have the same problem. Device after acquisition mode return 3 data frames and disconect. Log's are the same.

05-02 14:37:26.801 -> ACQUISITION_OK
05-02 14:37:27.861 Seq: 0; Analog: [0, 0, 0, 318, 47, 0]; Digital: [1, 1, 1, 1]
05-02 14:37:28.861 Seq: 1; Analog: [0, 0, 112, 317, 47, 0]; Digital: [1, 1, 1, 1]
05-02 14:37:29.861 Seq: 2; Analog: [0, 0, 1, 316, 47, 0]; Digital: [1, 1, 1, 1]
05-02 14:37:33.811 -> DISCONNECTED
05-02 14:37:33.811 -> CONNECTING
05-02 14:37:33.991 -> DISCONNECTED
05-02 14:37:34.011 -> CONNECTING
05-02 14:37:34.591 -> CONNECTED
...
05-02 14:38:09.051 -> ACQUISITION_OK
05-02 14:38:10.111 Seq: 0; Analog: [1021, 0, 439, 316, 47, 0]; Digital: [1, 1, 1, 1]
05-02 14:38:11.111 Seq: 1; Analog: [1021, 0, 263, 317, 47, 0]; Digital: [1, 1, 1, 1]
05-02 14:38:12.131 Seq: 2; Analog: [1022, 0, 0, 316, 47, 0]; Digital: [1, 1, 1, 1]`

@GTelo
Copy link
Contributor

GTelo commented May 2, 2017

Which BITalino version are you using?

@VadymKuriy
Copy link
Author

@GTelo 3.3.

@GTelo GTelo closed this as completed in 63f2c17 May 2, 2017
@GTelo
Copy link
Contributor

GTelo commented May 2, 2017

The problem is fixed. If you update your local project it will work fine.

Thank you for your feedback.

Best regards,
Gonçalo Telo

@VadymKuriy
Copy link
Author

@GTelo Thx. Everything works!!!

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

No branches or pull requests

2 participants