Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

AndroidChuan Kou Tong Xun Zhu Shou ,Shi Yong C++Shi Xian .

Notifications You must be signed in to change notification settings

freyskill/SerialPortHelper

Repository files navigation

SerialPortHelper(AndroidChuan Kou Tong Xin )

AndroidChuan Kou Tong Xun Zhu Shou Ke Yi Yong Yu Xu Yao Shi Yong Chuan Kou Tong Xin De AndroidWai She ,Gai Ku You Ru Xia Te Dian :

  1. Chuan Kou Tong Xin Bu Fen Shi Yong C++Shi Xian ,Zai Bi Zhe Jie Hong De Bu Fen She Bei Shang Shi Ce ,Shi Yong C++Shi Xian Yu GoogleGuan Fang Ti Gong De DemoDe Fang Shi Yao Kuai ;
  2. Zhi Chi Qie Bi Xu She Zhi Chuan Kou Jie Shou Zui Da Shu Ju Chang Du ,Chu Shi Hua Ku Shi Tian Ru Gai Can Shu ,Zhe Yang She Zhi De Yuan Yin Shi Kao Lu Zai Shi Ji Shi Yong Zhong ,Gui Ding De Chuan Kou Tong Xin Xie Yi Ge Shi Yi Ban Hui Gu Ding You Zui Da Chang Du ,Fang Bian Dui Shu Ju Jin Xing Chu Li ;
  3. Zhi Chi Ming Ling Yi Fa Yi Shou ,Tong Guo Dui Chuan Kou De Du Xie Xian Cheng Jin Xing Tong Bu Kong Zhi ,Ming Ling Hui Xian Jia Ru Dao Dui Lie Ran Hou Yi Ci Fa Song He Jie Shou ,Qian Ti Xu Yao She Zhi Chao Shi Shi Jian Yi Ji Chao Shi Chu Li ,Can Kao Xia Mian Di 4, 5Dian ;
  4. Zhi Chi Chao Shi She Zhi ,She Zhi Chao Shi Shi Jian Hou ,Ru Guo Ming Ling Zai She Zhi De Shi Jian Nei Wei Fan Kui ,Ze Hui Gen Ju She Zhi De Cao Zuo Jin Xing Zhong Fa Huo Tui Chu Gai Ming Ling ;
  5. Zhi Chi Chao Shi Zhong Fa (Ke Yi NCi Zhong Fa ,Ju Ti An Xu She Zhi )Yu Tui Chu ,Tui Chu Hui Diao Yong Jie Shou Hui Diao De onComplete Fang Fa .

1, DEMOYan Shi

Shi Yong Gai Ku Jian Dan Shi Xian De Chuan Kou Diao Shi Zhu Shou Gong Ju ,APKXia Zai

2, Jie Ru Fang Shi

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

allprojects {
repositories {
...
maven { url 'https://www.jitpack.io' }
}
}

Step 2. Add the dependency

dependencies {
implementation 'com.github.freyskill:SerialPortHelper:v1.0.1'
}

3, Shi Yong Shuo Ming

Chu Shi Hua Xu Yao She Zhi maxSize,Ye Ke Yi She Zhi isReceiveMaxSizeGai Can Shu Mo Ren Wei false,Xiang Xi Shuo Ming Ru Xia :

int maxSize; // She Zhi Chuan Kou Du Qu De Zui Da Shu Ju Chang Du

boolean isReceiveMaxSize; // She Zhi Shi Fou Jie Shou Ming Ling An Zui Da Chang Du Jin Xing Fan Hui ,Bi Ru Chuan Kou Xie Yi Ding Yi De Ge Shi Chang Du Wei 16Ge Zi Jie ,Zhe Yang Ke Yi She Zhi maxSizeWei 16,Ran Hou She Zhi Gai Can Shu Wei true,Ze Jie Shou De Ming Ling Jiu Hui Fan Hui 16Ge Zi Jie De Chang Du .

Ti Shi : She Zhi isReceiveMaxSizeWei trueShi Wei Liao Chu Li Ming Ling Fan Hui Bu Wan Zheng De Qing Kuang ,Li Ru Wan Zheng Ming Ling Chang Du Wei 16,Dan Shi Chuan Kou Du De Guo Cheng Fen Ji Ci Fan Hui .

SerialPortHelper serialPortHelper = new SerialPortHelper(32);
SerialPortHelper serialPortHelper = new SerialPortHelper(32,true);

3.1.Chu Shi Hua Chuan Kou

//Fang Shi Yi :Kuai Su Jie Ru Fang Shi ,She Zhi Hao Chuan Kou Di Zhi ,Huo Zhe Di Zhi He Bo Te Lu Ji Ke ,Shu Ju Wei , Ting Zhi Wei , Xiao Yan Lei Xing Fen Bie Mo Ren Wei 8, 1, N.
SerialPortHelper serialPortHelper = new SerialPortHelper(32);
//serialPortHelper.openDevice("dev/ttyS0");
serialPortHelper.openDevice("dev/ttyS0",11520);
// Shu Ju Jie Shou Hui Diao
serialPortHelper.setSphResultCallback(new SphResultCallback() {
@Override
public void onSendData(SphCmdEntity sendCom) {
Log.d(TAG, "Fa Song Ming Ling :" + sendCom.commandsHex);
}

@Override
public void onReceiveData(SphCmdEntity data) {
Log.d(TAG, "Shou Dao Ming Ling :" + data.commandsHex);

}

@Override
public void onComplete() {
Log.d(TAG, "Wan Cheng ");
}
});
//Fang Shi Er :Tong Guo SerialPortConfigShe Zhi Xiang Guan Chuan Kou Can Shu

//Chuan Kou Can Shu
SerialPortConfig serialPortConfig = new SerialPortConfig();
serialPortConfig.mode = 0; // Shi Fou Shi Yong Yuan Shi Mo Shi (Raw Mode)Fang Shi Lai Tong Xun
serialPortConfig.path = path; // Chuan Kou Di Zhi
serialPortConfig.baudRate = baudRate; // Bo Te Lu
serialPortConfig.dataBits = dataBits; // Shu Ju Wei Qu Zhi Wei 7Huo 8
serialPortConfig.parity = checkBits;// Jian Yan Lei Xing Qu Zhi N ,E, O
serialPortConfig.stopBits = stopBits; // Ting Zhi Wei Qu Zhi 1 Huo Zhe 2

// Chu Shi Hua Chuan Kou
serialPortHelper = new SerialPortHelper(16);
// She Zhi Chuan Kou Can Shu
serialPortHelper.setConfigInfo(serialPortConfig);
// Kai Qi Chuan Kou
isOpen = serialPortHelper.openDevice();
if(!isOpen){
Toast.makeText(this,"Chuan Kou Da Kai Shi Bai !",Toast.LENGTH_LONG).show();
}
// Shu Ju Jie Shou Hui Diao
serialPortHelper.setSphResultCallback(new SphResultCallback() {
@Override
public void onSendData(SphCmdEntity sendCom) {
Log.d(TAG, "Fa Song Ming Ling :" + sendCom.commandsHex);
}

@Override
public void onReceiveData(SphCmdEntity data) {
Log.d(TAG, "Shou Dao Ming Ling :" + data.commandsHex);

}

@Override
public void onComplete() {
Log.d(TAG, "Wan Cheng ");
}
});

3.2.Shu Ju Fa Song Yu Jie Shou

// Fa Song Shu Ju
serialPortHelper.addCommands(sendHexTxt); // Fa Song Shi Liu Jin Zhi Zi Fu Chuan
serialPortHelper.addCommands(sendComBytes); // Fa Song Zi Jie Shu Zu

// Fa Song Shu Ju Shi Ti
SphCmdEntity comEntry = new SphCmdEntity();
comEntry.commands = commands; // Fa Song Ming Ling Zi Jie Shu Zu
comEntry.flag = flag; // Bei Yong Biao Shi
comEntry.commandsHex = DataConversion.encodeHexString(commands); // Fa Song Shi Liu Jin Zhi Zi Fu Chuan
comEntry.timeOut = 100; // Chao Shi Shi Jian ms
comEntry.reWriteCom = false; // Chao Shi Shi Fou Zhong Fa Mo Ren false
comEntry.reWriteTimes = 5; // Zhong Fa Ci Shu
comEntry.receiveCount = 1; // Jie Shou Shu Ju Tiao Shu ,Mo Ren Wei 1
serialPortHelper.addCommands(comEntry);
// Shu Ju Jie Shou Hui Diao
serialPortHelper.setSphResultCallback(new SphResultCallback() {
@Override
public void onSendData(SphCmdEntity sendCom) {
Log.d(TAG, "Fa Song Ming Ling :" + sendCom.commandsHex);
}

@Override
public void onReceiveData(SphCmdEntity data) {
// Dui Yu Jie Shou Shu Ju De SphCmdEntity,Qi Zhong Xu Yao Shi Yong De You
// commandsHex Fan Hui De Shi Liu Jin Zhi Shu Ju
// commands Fan Hui De Zi Jie Shu Zu
// flag Bei Yong Biao Shi ,Li Ru Biao Shi Gai Ming Ling Shi Xiang Guan Cao Zuo
Log.d(TAG, "Shou Dao Ming Ling :" + data.commandsHex);

}

@Override
public void onComplete() {
Log.d(TAG, "Wan Cheng ");
}
});

4, Guan Bi Chuan Kou

serialPortHelper.closeDevice();

About

AndroidChuan Kou Tong Xun Zhu Shou ,Shi Yong C++Shi Xian .

Topics

Resources

Readme

Stars

Watchers

Forks

Packages

Contributors