Merge pull request #96 from marcosdiez/dtr_and_rts
User can now set DTR and RTS on the fly
This commit is contained in:
commit
ccc8e8d3f0
|
@ -28,6 +28,8 @@ import android.hardware.usb.UsbDeviceConnection;
|
||||||
import android.hardware.usb.UsbManager;
|
import android.hardware.usb.UsbManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
import android.widget.ScrollView;
|
import android.widget.ScrollView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
@ -64,6 +66,8 @@ public class SerialConsoleActivity extends Activity {
|
||||||
private TextView mTitleTextView;
|
private TextView mTitleTextView;
|
||||||
private TextView mDumpTextView;
|
private TextView mDumpTextView;
|
||||||
private ScrollView mScrollView;
|
private ScrollView mScrollView;
|
||||||
|
private CheckBox chkDTR;
|
||||||
|
private CheckBox chkRTS;
|
||||||
|
|
||||||
private final ExecutorService mExecutor = Executors.newSingleThreadExecutor();
|
private final ExecutorService mExecutor = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
|
@ -95,8 +99,30 @@ public class SerialConsoleActivity extends Activity {
|
||||||
mTitleTextView = (TextView) findViewById(R.id.demoTitle);
|
mTitleTextView = (TextView) findViewById(R.id.demoTitle);
|
||||||
mDumpTextView = (TextView) findViewById(R.id.consoleText);
|
mDumpTextView = (TextView) findViewById(R.id.consoleText);
|
||||||
mScrollView = (ScrollView) findViewById(R.id.demoScroller);
|
mScrollView = (ScrollView) findViewById(R.id.demoScroller);
|
||||||
|
chkDTR = (CheckBox) findViewById(R.id.checkBoxDTR);
|
||||||
|
chkRTS = (CheckBox) findViewById(R.id.checkBoxRTS);
|
||||||
|
|
||||||
|
chkDTR.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
try {
|
||||||
|
sPort.setDTR(isChecked);
|
||||||
|
}catch (IOException x){}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
chkRTS.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
try {
|
||||||
|
sPort.setRTS(isChecked);
|
||||||
|
}catch (IOException x){}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
@ -112,6 +138,11 @@ public class SerialConsoleActivity extends Activity {
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void showStatus(TextView theTextView, String theLabel, boolean theValue){
|
||||||
|
String msg = theLabel + ": " + (theValue ? "enabled" : "disabled") + "\n";
|
||||||
|
theTextView.append(msg);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
@ -130,6 +161,15 @@ public class SerialConsoleActivity extends Activity {
|
||||||
try {
|
try {
|
||||||
sPort.open(connection);
|
sPort.open(connection);
|
||||||
sPort.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE);
|
sPort.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE);
|
||||||
|
|
||||||
|
showStatus(mDumpTextView, "CD - Carrier Detect", sPort.getCD());
|
||||||
|
showStatus(mDumpTextView, "CTS - Clear To Send", sPort.getCTS());
|
||||||
|
showStatus(mDumpTextView, "DSR - Data Set Ready", sPort.getDSR());
|
||||||
|
showStatus(mDumpTextView, "DTR - Data Terminal Ready", sPort.getDTR());
|
||||||
|
showStatus(mDumpTextView, "DSR - Data Set Ready", sPort.getDSR());
|
||||||
|
showStatus(mDumpTextView, "RI - Ring Indicator", sPort.getRI());
|
||||||
|
showStatus(mDumpTextView, "RTS - Request To Send", sPort.getRTS());
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG, "Error setting up device: " + e.getMessage(), e);
|
Log.e(TAG, "Error setting up device: " + e.getMessage(), e);
|
||||||
mTitleTextView.setText("Error opening device: " + e.getMessage());
|
mTitleTextView.setText("Error opening device: " + e.getMessage());
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" >
|
android:layout_height="match_parent" >
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/demoTitle"
|
android:id="@+id/demoTitle"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -15,15 +15,34 @@
|
||||||
<View
|
<View
|
||||||
android:id="@+id/separator"
|
android:id="@+id/separator"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dip"
|
||||||
|
android:background="#eeeeee" />
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/textBtnDTR"
|
||||||
|
android:id="@+id/checkBoxDTR" />
|
||||||
|
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/textBtnRTS"
|
||||||
|
android:id="@+id/checkBoxRTS" />
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/separator2"
|
||||||
|
android:layout_width="match_parent"
|
||||||
android:layout_below="@+id/demoTitle"
|
android:layout_below="@+id/demoTitle"
|
||||||
android:layout_height="1dip"
|
android:layout_height="1dip"
|
||||||
android:background="#eeeeee" />
|
android:background="#eeeeee" />
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
android:id="@+id/demoScroller"
|
android:id="@+id/demoScroller"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@+id/separator" >
|
>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/consoleText"
|
android:id="@+id/consoleText"
|
||||||
|
@ -32,5 +51,4 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:typeface="monospace" />
|
android:typeface="monospace" />
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
</LinearLayout>
|
||||||
</RelativeLayout>
|
|
||||||
|
|
|
@ -4,5 +4,7 @@
|
||||||
<string name="app_title">USB Serial Example</string>
|
<string name="app_title">USB Serial Example</string>
|
||||||
<string name="app_name">Serial Example</string>
|
<string name="app_name">Serial Example</string>
|
||||||
<string name="refreshing">Refreshing...</string>
|
<string name="refreshing">Refreshing...</string>
|
||||||
|
<string name="textBtnRTS">RTS - Request To Send</string>
|
||||||
|
<string name="textBtnDTR">DTR - Data Terminal Ready</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue