国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Android Studio的筆記--SerialPort串口通訊學(xué)習(xí)和使用

這篇具有很好參考價值的文章主要介紹了Android Studio的筆記--SerialPort串口通訊學(xué)習(xí)和使用。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。


摘要:本篇介紹android中SerialPort串口通訊學(xué)習(xí)和使用。主要用到android-serialport-api。

SerialPort

幾個工程參考學(xué)習(xí)使用

android-serialport-api

Google開源的Android串口通信Demo android-serialport-api

源碼下載

cepr/android-serialport-api
SerialPort獲取串口輸入輸出流
SerialPortFinder獲取硬件地址
Android Studio的筆記--SerialPort串口通訊學(xué)習(xí)和使用,Android,android studio,筆記,學(xué)習(xí)
可以推薦看android串口通信——android-serialport-api 源

Android-SerialPort-API

源碼下載

licheedev/Android-SerialPort-API
Android Studio的筆記--SerialPort串口通訊學(xué)習(xí)和使用,Android,android studio,筆記,學(xué)習(xí)

readme

Android Studio的筆記--SerialPort串口通訊學(xué)習(xí)和使用,Android,android studio,筆記,學(xué)習(xí)
Android Studio的筆記--SerialPort串口通訊學(xué)習(xí)和使用,Android,android studio,筆記,學(xué)習(xí)

版本

添加依賴:implementation ‘com.licheedev:android-serialport:2.1.3’

allprojects {
    repositories {
        ...
        jcenter()
        mavenCentral() // since 2.1.3
    }
}
dependencies {
        implementation 'com.licheedev:android-serialport:2.1.3'
}

除了選擇2.1.3版本,還可以看 releases 選擇其他版本。
Android Studio的筆記--SerialPort串口通訊學(xué)習(xí)和使用,Android,android studio,筆記,學(xué)習(xí)

Android-SerialPort-Tool

源碼下載

licheedev/Android-SerialPort-Tool
Android Studio的筆記--SerialPort串口通訊學(xué)習(xí)和使用,Android,android studio,筆記,學(xué)習(xí)

Android-Serialport

源碼下載

xmaihh/Android-Serialport
Android Studio的筆記--SerialPort串口通訊學(xué)習(xí)和使用,Android,android studio,筆記,學(xué)習(xí)

使用方法

Android移植谷歌官方串口庫支持校驗位、數(shù)據(jù)位、停止位、流控配置

1. 檢驗參數(shù)合法性
    /* Check arguments */
    {
        speed = getBaudrate(baudrate);
        if (speed == -1) {
            /* TODO: throw an exception */
            LOGE("Invalid baudrate");
            return NULL;
        }
    }
2. 打開串口
    /* Opening device */
    {
        jboolean iscopy;
        const char *path_utf = (*env)->GetStringUTFChars(env, path, &iscopy);
        LOGD("Opening serial port %s with flags 0x%x", path_utf, O_RDWR | flags);
        fd = open(path_utf, O_RDWR | flags);
        LOGD("open() fd = %d", fd);
        (*env)->ReleaseStringUTFChars(env, path, path_utf);
        if (fd == -1) {
            /* Throw an exception */
            LOGE("Cannot open port");
            /* TODO: throw an exception */
            return NULL;
        }
    }
3.配置波特率
    /* Configure device */
    {
        struct termios cfg;
        LOGD("Configuring serial port");
        if (tcgetattr(fd, &cfg)) {
            LOGE("tcgetattr() failed");
            close(fd);
            /* TODO: throw an exception */
            return NULL;
        }

        cfmakeraw(&cfg);
        cfsetispeed(&cfg, speed);
        cfsetospeed(&cfg, speed);
4.配置數(shù)據(jù)位
        cfg.c_cflag &= ~CSIZE;
        switch (dataBits) {
            case 5:
                cfg.c_cflag |= CS5;    //使用5位數(shù)據(jù)位
                break;
            case 6:
                cfg.c_cflag |= CS6;    //使用6位數(shù)據(jù)位
                break;
            case 7:
                cfg.c_cflag |= CS7;    //使用7位數(shù)據(jù)位
                break;
            case 8:
                cfg.c_cflag |= CS8;    //使用8位數(shù)據(jù)位
                break;
            default:
                cfg.c_cflag |= CS8;
                break;
        }
5.配置校驗位
        switch (parity) {
            case 0:
                cfg.c_cflag &= ~PARENB;    //無奇偶校驗
                break;
            case 1:
                cfg.c_cflag |= (PARODD | PARENB);   //奇校驗
                break;
            case 2:
                cfg.c_iflag &= ~(IGNPAR | PARMRK); // 偶校驗
                cfg.c_iflag |= INPCK;
                cfg.c_cflag |= PARENB;
                cfg.c_cflag &= ~PARODD;
                break;
            default:
                cfg.c_cflag &= ~PARENB;
                break;
        }
6.配置停止位
        switch (stopBits) {
            case 1:
                cfg.c_cflag &= ~CSTOPB;    //1位停止位
                break;
            case 2:
                cfg.c_cflag |= CSTOPB;    //2位停止位
                break;
            default:
                break;
        }
7.配置流控
        switch (flowCon) {
            case 0:
                cfg.c_cflag &= ~CRTSCTS;    //不使用流控
                break;
            case 1:
                cfg.c_cflag |= CRTSCTS;    //硬件流控
                break;
            case 2:
                cfg.c_cflag |= IXON | IXOFF | IXANY;    //軟件流控
                break;
            default:
                cfg.c_cflag &= ~CRTSCTS;
                break;
        }

readme

Android Studio的筆記--SerialPort串口通訊學(xué)習(xí)和使用,Android,android studio,筆記,學(xué)習(xí)
Android Studio的筆記--SerialPort串口通訊學(xué)習(xí)和使用,Android,android studio,筆記,學(xué)習(xí)
Android Studio的筆記--SerialPort串口通訊學(xué)習(xí)和使用,Android,android studio,筆記,學(xué)習(xí)

android中使用串口通信

使用android-serialport-api方式

import android.serialport.SerialPort;

第1種 鏈接

在gradle/build.gradle中添加

maven { url "https://jitpack.io" }

在app/build.gradle文件配置中的dependencies,加上

implementation 'com.github.licheedev.Android-SerialPort-API:serialport:1.0.1'

第2種 導(dǎo)入SerialPort庫

1、將android-serialport-api中的libs的so庫資源放到項目libs中
Android Studio的筆記--SerialPort串口通訊學(xué)習(xí)和使用,Android,android studio,筆記,學(xué)習(xí)

Android Studio的筆記--SerialPort串口通訊學(xué)習(xí)和使用,Android,android studio,筆記,學(xué)習(xí)
2、將Android-SerialPort-API中的java下的文件復(fù)制到項目中java
Android Studio的筆記--SerialPort串口通訊學(xué)習(xí)和使用,Android,android studio,筆記,學(xué)習(xí)
Android Studio的筆記--SerialPort串口通訊學(xué)習(xí)和使用,Android,android studio,筆記,學(xué)習(xí)
3、修改app的build.gradle文件,在android {}里添加支持的cpu架構(gòu)

    defaultConfig {
        ndk {
            abiFilters "armeabi","armeabi-v7a"  // "x86", "arm64-v8a"
        }
    }

第3種 編譯SerialPort模塊

1、將Android-SerialPort-API中的serialport模塊復(fù)制到工程中,目錄與app文件同級
Android Studio的筆記--SerialPort串口通訊學(xué)習(xí)和使用,Android,android studio,筆記,學(xué)習(xí)
Android Studio的筆記--SerialPort串口通訊學(xué)習(xí)和使用,Android,android studio,筆記,學(xué)習(xí)
2、修改settings.gradle,將改成如下,即增加serialport模塊

rootProject.name = "SerialPort"
include ':app',':serialport'

3、修改app的build.gradle文件,在dependencies{}中添加project

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation project(':serialport')
}

串口通信部分代碼

待續(xù)

好的文章推薦參考

Android串口通訊SerialPort(使用篇)
與君共勉!待續(xù)
歡迎指錯,一起學(xué)習(xí)文章來源地址http://www.zghlxwxcb.cn/news/detail-739584.html

到了這里,關(guān)于Android Studio的筆記--SerialPort串口通訊學(xué)習(xí)和使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • C# SerialPort串口ReadTimeout 超時異常?!癝ystem.TimeoutException”

    一、簡介 系統(tǒng)采用之前的系統(tǒng): 相關(guān)的鏈接為 https://blog.csdn.net/u011854789/article/details/51895014 https://blog.csdn.net/weixinhum/article/details/53684151 http://www.cnblogs.com/Traveller-Lee/p/6940221.html(主要參考) (一)WPF工程做上位機與彩屏(或單片機)進行串口通信、解決彩屏(或單片機)只能

    2024年02月09日
    瀏覽(13)
  • Android Studio開發(fā)之使用內(nèi)容組件Content獲取通訊信息講解及實戰(zhàn)(附源碼 包括添加手機聯(lián)系人和發(fā)短信)

    Android Studio開發(fā)之使用內(nèi)容組件Content獲取通訊信息講解及實戰(zhàn)(附源碼 包括添加手機聯(lián)系人和發(fā)短信)

    運行有問題或需要源碼請點贊關(guān)注收藏后評論區(qū)留言 在實際開發(fā)中,普通App很少會開放數(shù)據(jù)接口給其他應(yīng)用訪問。內(nèi)容組件能夠派上用場的情況往往是App想要訪問系統(tǒng)應(yīng)用的通訊數(shù)據(jù),比如查看聯(lián)系人,短信,通話記錄等等,以及對這些通訊數(shù)據(jù)及逆行增刪改查。 首先要給

    2024年02月09日
    瀏覽(55)
  • MATLAB :【11】一文帶你讀懂serialport串口收發(fā)原理與實現(xiàn)

    MATLAB :【11】一文帶你讀懂serialport串口收發(fā)原理與實現(xiàn)

    碎碎念: 這周的主要工作還是集中于FOC中,因為羨慕稚暉君做出的漂亮Qt面板,因此在利用MATLAB復(fù)刻過程中,學(xué)習(xí)了一下serialport的使用。FOC的GUI部分就在加班加點寫作中啦,同時最近打算開一個新坑,大家可以期待一下哈哈哈。 歡迎大佬們點贊+收藏+關(guān)注~ o(* ̄▽ ̄*)ブ 目錄

    2023年04月18日
    瀏覽(43)
  • 《Android 移動應(yīng)用基礎(chǔ)教程(Android Studio)(第2版)》【學(xué)習(xí)筆記】【2023春】【附源碼】

    《Android 移動應(yīng)用基礎(chǔ)教程(Android Studio)(第2版)》【學(xué)習(xí)筆記】【2023春】【附源碼】

    《Android 移動應(yīng)用基礎(chǔ)教程(Android Studio)(第2版)》黑馬程序員 源代碼 Android——六大基本布局總結(jié)/CSDN@小馬 同學(xué) 【Android】線性布局(LinearLayout)最全解析/CSDN@Teacher.Hu 一個不錯的計算器界面?? Android Studio App LinearLayout多層布局嵌套/CSDN@pythontojava 一個簡單的布局?? Andro

    2024年02月01日
    瀏覽(29)
  • Android Studio 簡易通訊錄制作 (Java)

    Android Studio 簡易通訊錄制作 (Java)

    通訊錄首頁: ?添加聯(lián)系人頁面: ?修改聯(lián)系人: 刪除聯(lián)系人: ?程序代碼: MainActivity.java MyAdapter.java ?DBHelper.java User.java ?activity_main.xml dialog.xml ?item.xml colors.xml ?詳細見:https://gitee.com/love1213/Android-Studio-Contacts.git

    2024年02月11日
    瀏覽(26)
  • 串口通訊UART/RS232/RS485/RS-422筆記

    串口通訊UART/RS232/RS485/RS-422筆記

    串口通訊是指數(shù)據(jù)按位(bit)發(fā)送和接收字節(jié)的一種傳輸方式。一個字節(jié)的數(shù)據(jù)傳輸要分為8次進行,由低位到高位按順序一位一位的進行傳送。 由于串行通信的數(shù)據(jù)是逐位傳輸?shù)?,所以發(fā)送方和接收方都需要具有固定的時間間隔來發(fā)送/接收每一位,也就是要保證通訊雙方具

    2024年02月15日
    瀏覽(23)
  • STM32學(xué)習(xí):串口通訊(proteus仿真)

    STM32學(xué)習(xí):串口通訊(proteus仿真)

    本次通過CubeMx+proteus進行stm32串口仿真 具體功能: 1、開機后,向串口1發(fā)送“Welcome” 2、串口1接收字節(jié)指令“0xa1\\\",打開LED1,回傳“LED1 OPEN!” 3、串口1接收字節(jié)指令“0xa2\\\",關(guān)閉LED1,回傳“LED1 Close!” 4、在串口發(fā)送過程中,打開LED2作為發(fā)送數(shù)據(jù)指示燈 1、COMPIM元件 作用:把仿

    2024年02月03日
    瀏覽(22)
  • STM32學(xué)習(xí)----RS232串口通訊

    STM32學(xué)習(xí)----RS232串口通訊

    一、RS232相關(guān)概念 ? ? ? ?RS ==Recommend Standard ==推薦標(biāo)準(zhǔn); ? ? ? ? 232==標(biāo)識號,第232號; ? ? ? ? 時間:1962年 ? ? ? ? 地點:美國 ? ? ? ? 人物:美國電子工業(yè)協(xié)會 == Electronic Industries Association ==(美國)電子工業(yè)協(xié)會 ? ? ? ? 事件:發(fā)布了一個串行通信的物理接口結(jié)合邏

    2024年02月06日
    瀏覽(15)
  • STC15系列單片機學(xué)習(xí)4:串口通訊

    STC15系列單片機學(xué)習(xí)4:串口通訊

    在使用單片機的串口前,得先知道所使用的單片機有幾個串口,再結(jié)合你的硬件電路圖來使用哪個串口。 以下是STC15各系列單片機的串口數(shù)量,STC15W4K32S4系列有4個串口 工作模式0:同步移位寄存器(官方建議初學(xué)者不學(xué)) 工作模式1:8位串口,波特率可變 工作模式2:9位串口

    2024年04月13日
    瀏覽(27)
  • Android Studio初學(xué)者實例:SQLite實驗:綠豆通訊錄

    Android Studio初學(xué)者實例:SQLite實驗:綠豆通訊錄

    本次實驗是使用SQLite對一個通訊錄表進行簡單增刪改查 以下是實驗效果: ?首先是繼承SQLiteOpenHelper的數(shù)據(jù)庫自定義類 對于此類必須繼承于SQLiteOpenHelper ,當(dāng)new創(chuàng)造該類的實例的時候會執(zhí)行創(chuàng)建數(shù)據(jù)庫以及表的操作,例如本代碼中數(shù)據(jù)庫名為itcast,數(shù)據(jù)庫表名為informatoin。db

    2024年02月08日
    瀏覽(29)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包