树莓派编译jssc-2.9.2 实现自定义波特率

安装java8

sudo apt-get install openjdk-8-jdk
如果安装失败: 运行sudo apt-get update --fix-missing后再次安装

sudo nano /etc/profile
最后面添加:
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-armhf/
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:JAVA_HOME/lib/dt.jar:JAVA_HOME/lib/tools.jar

source /etc/profile

安装Maven, CMake

sudo apt install maven cmake g++ file

jssc-2.9.2点击到下载页下载源码

sudo unzip jssc-2.9.2.zip //解压
cd jssc-2.9.2/
sudo nano /usr/include/asm-generic/termbits.h
termios改为termios1(驱动中引用sudo nano /usr/include/arm-linux-gnueabihf/bits/termios.h中termios,避免冲突)

sudo nano src/main/cpp/_nix_based/jssc.cpp
#include <sys/ioctl.h>后添加
#include <asm/ioctls.h>
#include <asm/termbits.h>

替换
    #ifdef __SunOS
        goto methodEnd;//Solaris don't support non standart baudrates
    #elif defined __linux__
        //Try to calculate a divisor for setting non standart baudrate
        serial_struct *serial_info = new serial_struct();
        if(ioctl(portHandle, TIOCGSERIAL, serial_info) < 0){ //Getting serial_info structure
            delete serial_info;
            goto methodEnd;
        }
        else {
            serial_info->flags |= ASYNC_SPD_CUST;
            serial_info->custom_divisor = (serial_info->baud_base/baudRate); //Calculate divisor
            if(serial_info->custom_divisor == 0){ //If divisor == 0 go to method end to prevent "division by zero" error
                delete serial_info;
                goto methodEnd;
            }
            settings->c_cflag |= B38400;
            if(cfsetispeed(settings, B38400) < 0 || cfsetospeed(settings, B38400) < 0){
                delete serial_info;
                goto methodEnd;
            }
            if(ioctl(portHandle, TIOCSSERIAL, serial_info) < 0){//Try to set new settings with non standart baudrate
                delete serial_info;
                goto methodEnd;
            }
            delete serial_info;
        }
    #endif
为:
        struct termios2 t;
        if (ioctl(portHandle, TCGETS2, &t)) {
            goto methodEnd;
        }

        t.c_cflag &= ~CBAUD;
        t.c_cflag |= BOTHER;
        t.c_ospeed = t.c_ispeed = baudRate;

        if (ioctl(portHandle, TCSETS2, &t)) {
            goto methodEnd;
        }
mvn //执行编译后 jar包在target/中生成
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值