{"action":"closed","issue":{"url":"https://api.github.com/repos/felHR85/UsbSerial/issues/3","labels_url":"https://api.github.com/repos/felHR85/UsbSerial/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/felHR85/UsbSerial/issues/3/comments","events_url":"https://api.github.com/repos/felHR85/UsbSerial/issues/3/events","html_url":"https://github.com/felHR85/UsbSerial/issues/3","id":53333875,"number":3,"title":"main program for communication usb serial","user":{"login":"alfakr","id":8857736,"avatar_url":"https://avatars.githubusercontent.com/u/8857736?v=3","gravatar_id":"","url":"https://api.github.com/users/alfakr","html_url":"https://github.com/alfakr","followers_url":"https://api.github.com/users/alfakr/followers","following_url":"https://api.github.com/users/alfakr/following{/other_user}","gists_url":"https://api.github.com/users/alfakr/gists{/gist_id}","starred_url":"https://api.github.com/users/alfakr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alfakr/subscriptions","organizations_url":"https://api.github.com/users/alfakr/orgs","repos_url":"https://api.github.com/users/alfakr/repos","events_url":"https://api.github.com/users/alfakr/events{/privacy}","received_events_url":"https://api.github.com/users/alfakr/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-01-04T11:39:58Z","updated_at":"2015-01-30T09:28:12Z","closed_at":"2015-01-30T09:28:12Z","body":"hallo @felHR85 ,\r\nfirst of all thank you for your usb serial library, \r\ni would ask about main program for simple read and write via usb serial with using your library, (Im using Prolific usb-to-serial  PL2303) \r\nI newby on developing android so its hard enough for me to start writing code,, \r\nthis is a code I write, and yes there is an error when I click button, its force closed, \r\nhope you have a little time for helping me, \r\nThanks\r\n\r\npackage com.android.testcomserial;\r\n\r\nimport android.app.Activity;\r\nimport android.hardware.usb.UsbDevice;\r\nimport android.hardware.usb.UsbDeviceConnection;\r\nimport android.os.Bundle;\r\nimport android.util.Log;\r\nimport android.view.View;\r\nimport android.widget.Button;\r\nimport android.widget.Toast;\r\n\r\nimport com.felhr.usbserial.PL2303SerialDevice;\r\nimport com.felhr.usbserial.UsbSerialInterface;\r\n\r\npublic class MainActivity extends Activity {\r\n\t\r\n\t//UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);\r\n\tprivate static UsbDevice device;\r\n\tprivate static UsbDeviceConnection usbConnection;\r\n\tprivate final PL2303SerialDevice pl2303 = new PL2303SerialDevice(device, usbConnection); \r\n\t\r\n\tButton buttonWrite;\r\n        \r\n        @Override\r\n\t    protected void onPause() {\r\n\t        super.onPause();\r\n\t        if (pl2303 != null) {\r\n\t            try {\r\n\t            \tpl2303.close();\r\n\t            } catch (Exception e) {\r\n\t                Log.e(\"LOG\", e.toString());\r\n\t            }\r\n\t        }\r\n\t        finish();\r\n\t    }\r\n\r\n\t @Override\r\n\t protected void onResume() {\r\n\t        super.onResume();\r\n\t        if (pl2303 == null) {\r\n\t            Toast.makeText(getApplicationContext(), \"No serial device.\", Toast.LENGTH_LONG).show();\r\n\t        } else {\r\n\t            try {\r\n\t            \tpl2303.open();\r\n\t            \tpl2303.setBaudRate(115200);\r\n\t            \tpl2303.setDataBits(UsbSerialInterface.DATA_BITS_8);\r\n\t            \tpl2303.setParity(UsbSerialInterface.PARITY_NONE);\r\n\t            } catch (Exception e) {\r\n\t                Log.e(\"Error setting up device: \", e.toString());\r\n\t                //pl2303.close();\r\n\t            }\r\n\t        }\t\t\r\n\t}\r\n\t\r\n\t \r\n\t@Override\r\n\tprotected void onCreate(Bundle savedInstanceState) {\r\n\t\tsuper.onCreate(savedInstanceState);\r\n\t\tsetContentView(R.layout.activity_main);\r\n\t\tbuttonWrite = (Button)findViewById(R.id.buttonWrite);\r\n\t\tbuttonWrite.setOnClickListener(new View.OnClickListener() {\r\n\t\t\t@Override\r\n\t\t\tpublic void onClick(View v) {\r\n\t\t\t\t// TODO Auto-generated method stub\r\n\t\t\t\tpl2303.write(\"DATA FROM ANDROID\".getBytes());\r\n\t\t\t\t\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\t}\r\n\t\r\n\t private UsbSerialInterface.UsbReadCallback mCallback = new UsbSerialInterface.UsbReadCallback() {\r\n\r\n        @Override\r\n        public void onReceivedData(byte[] arg0) \r\n        {\r\n            // Code here :) // what should I write here??\r\n        \tToast.makeText(getApplicationContext(), \"new data receive\", Toast.LENGTH_LONG).show();\r\n        }\r\n\t };\r\n}\r\n\r\n"}}