基于微嵌安卓屏的串口测试程序开发

在工业平板中,串口是经常可以见到的,也是在工业控制中用的比较多的接口,通常就是一个工业平板通过串口连接设备进行数据的传输,所以今天我们就来学习如何在微嵌的安卓平板上实现串口的使用

 

 串口的通信比较简单,一般设置好对应的参数即可,数据的接收是通过开启一个接收线程来实现,因为是编写一个测试程序,所以发送数据可选择单次发送和循环发送,同时也可以对接受和发送的数据进行统计,最后就是一个计时功能

布局和布局的代码如下,作为测试程序,页面布局比较简单,注重实用性,计时功能是在按下循环发送时即可自动计时

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

  <RelativeLayout
      android:layout_width="0dp"
      android:layout_height="match_parent"
      android:layout_weight="1" >

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="8">

      <TextView
          android:id="@+id/comNameText1"
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_weight="1"
          android:layout_marginStart="10dp"
          android:text="串    口:"
          android:gravity="center_vertical"
          android:textSize="30sp" />

      <TextView
          android:id="@+id/baudText"
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_weight="1"
          android:layout_marginStart="10dp"
          android:text="波特率:"
          android:gravity="center_vertical"
          android:textSize="30sp" />

      <TextView
          android:id="@+id/dataText"
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_weight="1"
          android:layout_marginStart="10dp"
          android:text="数据位:"
          android:gravity="center_vertical"
          android:textSize="30sp" />

      <TextView
          android:id="@+id/parityText"
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_weight="1"
          android:layout_marginStart="10dp"
          android:text="校验位:"
          android:gravity="center_vertical"
          android:textSize="30sp" />

      <TextView
          android:id="&#
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值