|
@@ -92,50 +92,6 @@ public class MainActivity extends AppCompatActivity {
|
|
|
public void onDataSent(byte[] bytes) {
|
|
|
}
|
|
|
});
|
|
|
-// new SerialPortHelper(new SerialPortHelper.OnDataReceivedListener() {
|
|
|
-// @Override
|
|
|
-// public void onDataReceived(String data) {
|
|
|
-// MainActivity.data = data;
|
|
|
-// runOnUiThread(new Runnable() {
|
|
|
-// @Override
|
|
|
-// public void run() {
|
|
|
-// byte[] bytes = ByteUtil.addBytes(MainActivity.data.getBytes(), new byte[64]);
|
|
|
-//// for (int i = bytes.length; i < 64; i++) {
|
|
|
-//// bytes[i] = 0x0;
|
|
|
-//// }
|
|
|
-// setText(MainActivity.data, MainActivity.data.length());
|
|
|
-// if (serialPortManager.sendBytes(bytes)) {
|
|
|
-// Toast.makeText(getApplicationContext(), "发送成功 = " + MainActivity.data, Toast.LENGTH_SHORT).show();
|
|
|
-// } else {
|
|
|
-// Toast.makeText(getApplicationContext(), "发送失败", Toast.LENGTH_SHORT).show();
|
|
|
-// }
|
|
|
-// }
|
|
|
-// });
|
|
|
-// }
|
|
|
-// }).getStringData(serialPortManager);
|
|
|
- //////////////////////////////////////////////
|
|
|
-// serialPortManager.setOnSerialPortDataListener(new OnSerialPortDataListener() {
|
|
|
-// @Override
|
|
|
-// public void onDataReceived(final byte[] bytes) {
|
|
|
-// runOnUiThread(new Runnable() {
|
|
|
-// @Override
|
|
|
-// public void run() {
|
|
|
-// setText(new String(bytes), bytes.length);
|
|
|
-// }
|
|
|
-// });
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public void onDataSent(final byte[] bytes) {
|
|
|
-// runOnUiThread(new Runnable() {
|
|
|
-// @Override
|
|
|
-// public void run() {
|
|
|
-// setText(new String(bytes), bytes.length);
|
|
|
-// }
|
|
|
-// });
|
|
|
-// }
|
|
|
-// });
|
|
|
-// serialPortManager.openSerialPort(new File("/dev/ttyS1"), 115200);
|
|
|
}
|
|
|
|
|
|
private void setText(String data, int size) {
|
|
@@ -174,9 +130,9 @@ public class MainActivity extends AppCompatActivity {
|
|
|
closeSerial.setEnabled(false);
|
|
|
break;
|
|
|
case R.id.send:
|
|
|
- byte[] reportID = {0x0};
|
|
|
- byte[] data = ByteUtil.addBytes(reportID, editText.getText().toString().getBytes());
|
|
|
- boolean sendBytes = serialPortManager.sendBytes(data);
|
|
|
+ // byte[] reportID = {0x0};
|
|
|
+ // byte[] data = ByteUtil.addBytes(reportID, editText.getText().toString().getBytes());
|
|
|
+ boolean sendBytes = serialPortManager.sendBytes(editText.getText().toString().getBytes());
|
|
|
if (sendBytes) {
|
|
|
Toast.makeText(getApplicationContext(), "发送成功", Toast.LENGTH_SHORT).show();
|
|
|
} else {
|