简化版的串口通信,非常的简单,看了以后,会很简洁,很清晰,本人亲测,这个博客的例子完美运行
好吧,来看看如何使用SerialPort串口通信
1.首先我们来看一下,运行的效果图:
2.添加依赖,在app下的builder.gradle
//gogle serialPort
implementation 'com.aill:AndroidSerialPort:1.0.8'
3.下发和接收数据:
package com.example.administrator.testz;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.TextViewCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.aill.androidserialport.SerialPort;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
* Created by jiang on 2017/12/28.
*/
public class SerialportTestAct extends AppCompatActivity implements View.OnClickListener {
private StringBuffer seriapPortMsg = new StringBuffer();
private final String TAG = "SerialportTestAct:";
private InputStream mInputStream;
private OutputStream mOutputStream;
private TextView log;
private EditText serMsg;
private Button sendMsg;
private SerialPort serialPort;
private final String SERIALPORT_NO3 = "/dev/ttyS1";//串口号3
private final int BAUDRATE = 115200;//波特率
private Context mContext;
//记住 我们的程序 不