Forum > Android

LAMW arduino serial comm via android usb otg

<< < (3/3)

Mongkey:
it was run, but nothing happened, i did wireless debugging for testing, i got this, ha ha this kind of a hard component development


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type=1400 audit(0.0:270327): avc:  denied  { getopt } for  path="/dev/socket/usap_pool_secondary" scontext=u:r:untrusted_app_30:s0:c18,c257,c512,c768 tcontext=u:r:zygote:s0 tclass=unix_stream_socket permissive=0 app=org.lamw.applamwproject1
thank you

Mongkey:
May be this jar library is more easy to use on pascal, thank you,

https://github.com/ksksue/PhysicaloidLibrary/blob/master/PhysicaloidLibrary/bin/physicaloidlibrary.jar


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---package com.physicaloid.tutorial1; import java.io.UnsupportedEncodingException; import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.TextView; import com.physicaloid.lib.Physicaloid; public class Tutorial1Activity extends Activity {    private static final String TAG = Tutorial1Activity.class.getSimpleName();    /*     * !!! You need to import PhysicaloidLibrary. !!!     * If you have errors, check Project -> Properties -> Android -> Library.     */     /*     * In this tutorial, You can learn     *  - how to use open/close/read/write     *       *  You might check TODO tags.     */     //****************************************************************    // TODO : Add <uses-feature android:name="android.hardware.usb.host" /> to AndroidManifest.xml    //****************************************************************    Button btOpen, btClose, btRead, btWrite;    EditText etWrite;    TextView tvRead;     Physicaloid mPhysicaloid;     @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_tutorial1);         btOpen  = (Button) findViewById(R.id.btOpen);        btClose = (Button) findViewById(R.id.btClose);        btRead  = (Button) findViewById(R.id.btRead);        btWrite = (Button) findViewById(R.id.btWrite);        etWrite = (EditText) findViewById(R.id.etWrite);        tvRead  = (TextView) findViewById(R.id.tvRead);         setEnabledUi(false);         //****************************************************************        // TODO : create a new instance        mPhysicaloid = new Physicaloid(this);        //****************************************************************    }     public void onClickOpen(View v) {        //****************************************************************        // TODO : open a device        if(mPhysicaloid.open()) { // default 9600bps            setEnabledUi(true);        }        //****************************************************************    }     public void onClickClose(View v) {        //****************************************************************        // TODO : close the device        if(mPhysicaloid.close()) {            setEnabledUi(false);        }        //****************************************************************    }     public void onClickRead(View v) {        byte[] buf = new byte[256];        int readSize=0;         //****************************************************************        // TODO : read from the device to a buffer and get read size        readSize = mPhysicaloid.read(buf);        //****************************************************************         if(readSize>0) {            String str;            try {                str = new String(buf, "UTF-8");                tvRead.append(str);            } catch (UnsupportedEncodingException e) {                Log.e(TAG,e.toString());            }        }    }     public void onClickWrite(View v) {        String str = etWrite.getText().toString();        if(str.length()>0) {            byte[] buf = str.getBytes();            //****************************************************************            // TODO : write a buffer to the device            mPhysicaloid.write(buf, buf.length);            //****************************************************************        }    }     private void setEnabledUi(boolean on) {        if(on) {            btOpen.setEnabled(false);            btClose.setEnabled(true);            btRead.setEnabled(true);            btWrite.setEnabled(true);            etWrite.setEnabled(true);            tvRead.setEnabled(true);        } else {            btOpen.setEnabled(true);            btClose.setEnabled(false);            btRead.setEnabled(false);            btWrite.setEnabled(false);            etWrite.setEnabled(false);            tvRead.setEnabled(false);        }    }} 

Mongkey:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---package org.lamw.physicaloidbridge; import android.app.Activity;import android.os.Environment;import android.util.Log;import com.physicaloid.lib.Physicaloid;import com.physicaloid.lib.Boards;import com.physicaloid.lib.programmer.avr.UploadErrors;import com.physicaloid.lib.programmer.avr.UploadListener;import com.physicaloid.lib.usb.driver.uart.ReadLisener; public class PhysicaloidBridge {     private Physicaloid physicaloid;    private StringBuilder receivedData = new StringBuilder();     public PhysicaloidBridge(Activity activity) {        physicaloid = new Physicaloid(activity);    }     public boolean open() {        return physicaloid.open();    }     public void close() {        physicaloid.close();    }     public boolean isOpened() {        return physicaloid.isOpened();    }     public void write(String text) {        if (isOpened()) {            physicaloid.write(text.getBytes(), text.length());        }    }     public void addReadListener() {        if (isOpened()) {            physicaloid.addReadListener(new ReadLisener() {                @Override                public void onRead(int size) {                    byte[] buf = new byte[size];                    physicaloid.read(buf, size);                    String str = new String(buf);                    receivedData.append(str);                    Log.d("PhysicaloidBridge", "Received: " + str);                }            });        }    }     public String getReceivedData() {        String data = receivedData.toString();        receivedData.setLength(0); // clear buffer        return data;    }     public void uploadHexFile(String hexFilePath) {        physicaloid.upload(Boards.ARDUINO_UNO, hexFilePath, new UploadListener() {            @Override            public void onUploading(int value) {                Log.d("PhysicaloidBridge", "Uploading: " + value + "%");            }             @Override            public void onUploadSuccess() {                Log.d("PhysicaloidBridge", "Upload success!");            }             @Override            public void onUploadFailed(UploadErrors err) {                Log.e("PhysicaloidBridge", "Upload failed: " + err.toString());            }             @Override            public void onUploadCanceled() {                Log.d("PhysicaloidBridge", "Upload canceled.");            }        });    }} 

Mongkey:
gradle

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---dependencies {    implementation files('libs/physicaloidlibrary.jar')} 
manifest

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---<uses-feature android:name="android.hardware.usb.host" /><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> 
for uploading more arduino boards with option "hex" file


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---public void uploadHexFile(String boardName, String hexFilePath) {    Boards board = Boards.ARDUINO_UNO; // default     switch (boardName.toLowerCase()) {        case "uno":            board = Boards.ARDUINO_UNO;            break;        case "mega":        case "mega2560":            board = Boards.ARDUINO_MEGA2560;            break;        case "nano":            board = Boards.ARDUINO_NANO;            break;        case "leonardo":            board = Boards.ARDUINO_LEONARDO;            break;        case "micro":            board = Boards.ARDUINO_MICRO;            break;        case "pro":        case "promini":            board = Boards.ARDUINO_PROMINI;            break;        case "duemilanove":            board = Boards.ARDUINO_DUEMILANOVE;            break;        // add others as needed        default:            Log.w("PhysicaloidBridge", "Unknown board: " + boardName + ", defaulting to UNO");    }     physicaloid.upload(board, hexFilePath, new UploadListener() {        @Override        public void onUploading(int value) {            Log.d("PhysicaloidBridge", "Uploading: " + value + "%");        }         @Override        public void onUploadSuccess() {            Log.d("PhysicaloidBridge", "Upload success!");        }         @Override        public void onUploadFailed(UploadErrors err) {            Log.e("PhysicaloidBridge", "Upload failed: " + err.toString());        }         @Override        public void onUploadCanceled() {            Log.d("PhysicaloidBridge", "Upload canceled.");        }    });} 
This one created by using AI help.

Navigation

[0] Message Index

[*] Previous page

Go to full version