欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: Android串口顯示加+MVAndroidchart圖表 [打印本頁]

作者: herui123456    時間: 2021-11-17 10:47
標題: Android串口顯示加+MVAndroidchart圖表


1.串口使用   

  1.     private fun openSerialPort(){
  2.         serialPortFinder = SerialPortFinder()
  3.         serialHelper = object : SerialHelper() {
  4.             override fun onDataReceived(comBean: ComBean) {
  5.                 runOnUiThread {
  6. //                    Toast.makeText(
  7. //                        baseContext,
  8. //                        FuncUtil.ByteArrToHex(comBean.bRec),
  9. //                        Toast.LENGTH_SHORT
  10. //                    ).show()
  11.                     /*
  12.                     * TODO 將獲取的數據進行列表適配
  13.                     * */
  14.                     map = HashMap()
  15.                     (map as HashMap<String, Any>)["Value"] =comBean.sRecTime + ":   " +
  16.                             ByteUtil.hexStringToString(ByteUtil.bytesToHexString(comBean.bRec))
  17.                     list.add(map as HashMap<String, Any>)
  18.                     Handler(Looper.getMainLooper()).postDelayed({
  19.                         /**
  20.                          * 列表數據的溢處理已經適配
  21.                          * */
  22.                         if (list.size>12){
  23.                             map = list[0]
  24.                             list.remove(map)

  25.                         }
  26.                         initAdapter()
  27.                     }, 300)

  28.                 }
  29.             }
  30.         }

  31.         //獲取串口地址
  32.         val ports = serialPortFinder!!.allDevicesPath
  33.         //設置波特率地址
  34.         val botes = arrayOf(
  35.             "0",
  36.             "50",
  37.             "75",
  38.             "110",
  39.             "134",
  40.             "150",
  41.             "200",
  42.             "300",
  43.             "600",
  44.             "1200",
  45.             "1800",
  46.             "2400",
  47.             "4800",
  48.             "9600",
  49.             "19200",
  50.             "38400",
  51.             "57600",
  52.             "115200",
  53.             "230400",
  54.             "460800",
  55.             "500000",
  56.             "576000",
  57.             "921600",
  58.             "1000000",
  59.             "1152000",
  60.             "1500000",
  61.             "2000000",
  62.             "2500000",
  63.             "3000000",
  64.             "3500000",
  65.             "4000000"
  66.         )
  67.         val spAdapter = SpAdapter(this)
  68.         /*
  69.          * TODO 適配下拉列表(串口地址)
  70.         * */
  71.         spAdapter.setDatas(ports)
  72.         binding.spSerial.adapter = spAdapter
  73.         binding.spSerial.onItemSelectedListener = object : OnItemSelectedListener {
  74.             override fun onItemSelected(
  75.                 parent: AdapterView<*>?,
  76.                 view: View,
  77.                 position: Int,
  78.                 id: Long
  79.             ) {
  80.                 serialHelper?.close()

  81.                 serialHelper?.port = ports[position]

  82.                 binding.EditText1.setText(ports[position])
  83.                 binding.open.text = "關閉串口"

  84.             }

  85.             override fun onNothingSelected(parent: AdapterView<*>?) {}
  86.         }
  87.         /*
  88.          * TODO 適配下拉列表(波特率地址)
  89.         * */
  90.         val spAdapter2 = SpAdapter(this)
  91.         spAdapter2.setDatas(botes)
  92.         binding.spBote.adapter = spAdapter2
  93.         binding.spBote.onItemSelectedListener = object : OnItemSelectedListener {
  94.             override fun onItemSelected(
  95.                 parent: AdapterView<*>?,
  96.                 view: View,
  97.                 position: Int,
  98.                 id: Long
  99.             ) {
  100.                 serialHelper?.close()
  101.                 serialHelper?.setBaudRate(botes[position])
  102.                 binding.EditText2.setText(botes[position])
  103.                 binding.open.text = "關閉串口"

  104.             }

  105.             override fun onNothingSelected(parent: AdapterView<*>?) {}
  106.         }
  107.     }
  108.     override fun initListener() {
  109.         //打開串口
  110.         binding.open.setOnClickListener{
  111.             try {
  112.                 serialHelper?.open()
  113.                 binding.open.text = "打開成功"
  114.                 showToast("打開成功")


  115.             } catch (e: IOException) {
  116.                 e.printStackTrace()
  117.             }
  118.         }
  119.         //發送消息
  120.         binding.send.setOnClickListener{

  121.             if (binding.radioGroup.getCheckedRadioButtonId() == R.id.radioButton1) {
  122.                 if (binding.SendText.text.toString().isNotEmpty()) {
  123.                     if (serialHelper!!.isOpen) {
  124.                         serialHelper!!.sendTxt(binding.SendText.text.toString())
  125.                     } else {
  126.                         showToast("搞毛啊,串口都沒打開")
  127.                     }
  128.                 } else {
  129.                     showToast("填數據吧")
  130.                 }
  131.             } else {
  132.                 if (binding.SendText.text.toString().length > 0) {
  133.                     if (serialHelper!!.isOpen) {
  134.                         serialHelper!!.sendHex(binding.SendText.text.toString())
  135.                     } else {
  136.                         showToast("搞毛啊,串口都沒打開")
  137.                     }
  138.                 } else {
  139.                     showToast("填數據吧")
  140.                 }
  141.             }
  142.         }

  143.         //toolbar返回按鈕監聽
  144.         binding.toolbar.setNavigationOnClickListener { finish() }
  145.     }
復制代碼

項目地址:HTTPS ://gitee.com/herui12/教MVAndroidchart

                











歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1