Serialport communcation using android app

serial write not wroking at second time ,i get only first write statement using serial read.

BroadcastReceiver broadcastReceiver = new BroadcastReceiver(){ //Broadcast Receiver to automatically start and stop the Serial connection.
        public void onReceive(Context context, Intent intent) {

            if (intent.getAction().equals(ACTION_USB_PERMISSION)) {
                boolean granted = intent.getExtras().getBoolean(UsbManager.EXTRA_PERMISSION_GRANTED);
                Toast.makeText(context, "boolean" + granted, Toast.LENGTH_LONG).show();
                if (granted) {
                    connection = usbManager.openDevice(device);
                    Toast.makeText(context, "connection" + connection, Toast.LENGTH_LONG).show();
                    serialPort = UsbSerialDevice.createUsbSerialDevice(device, connection);
                    if (serialPort != null) {
                        if ( { //Set Serial Connection Parameters.
                            serialPort.write(SET_COMMD.getBytes());// this shown by serial read
                            serialPort.write(SET_COMMD2.getBytes());// _but this read stmt not_ shown_emphasized text_
                            Toast.makeText(context, "serialopened", Toast.LENGTH_LONG).show();
                           Toast.makeText(context, "HEY BUDDY TESTING", Toast.LENGTH_SHORT).show();
                        } else {
                            Log.d("SERIAL", "PORT NOT OPEN");
                            Toast.makeText(context, "PORT NOT OPEN", Toast.LENGTH_LONG).show();
                    } else {
                        Log.d("SERIAL", "PORT IS NULL");
                        Toast.makeText(context, "PORT IS NULL", Toast.LENGTH_LONG).show();
                } else {
                    Log.d("SERIAL", "PERM NOT GRANTED");
                    Toast.makeText(context, "PERM NOT GRANTED", Toast.LENGTH_LONG).show();
            } else if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
            } else if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_DETACHED)) {
                serialPort.close(); Toast.makeText(getBaseContext(), "HEY BUDDY supper it stopped", Toast.LENGTH_SHORT).show();}
             if(intent.getAction().equals(CUSTOM_INTENT_WRITE)) {
                 str = intent.getStringExtra("PARAM");
                   //  serialPort.write(str.getBytes());
                                      Toast.makeText(getBaseContext(), "HEY BUDDY supper it works"+str, Toast.LENGTH_SHORT).show();
                 Log.d("broadcast user",str);

@vijayapriya, is this related to Particle devices?

I’m using ftdi device which is same like method that You used in particle device.
Will you please suggest how to solve this issue I’m begginer

I’m sorry but the Particle devices do not use FTDI for USB serial–they have built-in support in the MCU for USB.

None of that code looks familiar at all. I don’t think we can help you here.

1 Like

This topic was automatically closed after 24 hours. New replies are no longer allowed.