sample-uartloopback icon indicating copy to clipboard operation
sample-uartloopback copied to clipboard

UART Cant open

Open Ragulmurugan opened this issue 7 years ago • 6 comments

E/Exception: UART cant opencom.google.android.things.pio.PioException: android.os.ServiceSpecificException: UART0 is already in use (code 16)

Ragulmurugan avatar Feb 12 '18 13:02 Ragulmurugan

Seems like you've opened it in another activity without closing it. See this Stackoverflow answer to learn more.

Fleker avatar Feb 12 '18 21:02 Fleker

But I'm closing UART before passing the Intent in every activity and this problem occurs randomly if it occurs always I can consider I forget to Close somewhere even I had the main thread.sleep before passing the Intent but nothing solved this problem.

Ragulmurugan avatar Feb 15 '18 14:02 Ragulmurugan

Where are you closing it? In the activity's onDestroy method? Do you need to architect your application with multiple activities?

Fleker avatar Feb 15 '18 19:02 Fleker

I'm closing it before passing the intent like

            try {
                closeUart();
            } catch (IOException e) {
                Log.e(TAG, "Error closing UART device:", e);
            }
            Intent i = new Intent(MainActivity.this,MainActivity2.class);
            String strName = "j";
            i.putExtra(Intent.EXTRA_TEXT, strName);
            startActivity(i);
            overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);finish();
            finish();

I'm not closing it in onDestroy method.

Ragulmurugan avatar Feb 16 '18 07:02 Ragulmurugan

Can you add a type of asynchronous wait before starting your activity, like using a Handler:

try {
    closeUart();
} catch (IOException e) {
    Log.e(TAG, "Error closing UART device:", e);
}
h = new Handler(Looper.getMainLooper()) {
    @Override
    public void handleMessage(int what) {
        Intent i = new Intent(MainActivity.this,MainActivity2.class);
        String strName = "j";
        i.putExtra(Intent.EXTRA_TEXT, strName);
        startActivity(i);
        overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);finish();
        finish();
    }
};
h.sendEmptyMessageDelayed(0, 50);

(this code wasn't tested, so it may not be completely valid)

Fleker avatar Feb 16 '18 21:02 Fleker

I have tried using main thread timer before passing the intent. Like Thread.sleep(1000). This time I'll try your idea let me use handler . Thanks dude

Ragulmurugan avatar Feb 18 '18 12:02 Ragulmurugan