gpt4 book ai didi

java - 将 RXTX 从 迁移到 Raspbian

转载 作者:太空宇宙 更新时间:2023-11-04 13:02:02 25 4
gpt4 key购买 nike

我在从 Windows 迁移到 Raspbian (raspberry pi 2) 时遇到问题。我无法使用 RXTX 库与 rs232 进行通信。在 Windows 上,此代码运行良好,但对于树莓派,我有一个 Null 响应。应用程序使用 Java8 编写并在 Windows 8 上编译。

我正在使用 netty 和 RXTXcomm:

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-rxtx</artifactId>
<version>4.0.0.CR1</version>
</dependency>

<dependency>
<groupId>net.cloudhopper</groupId>
<artifactId>RXTXcomm</artifactId>
<version>2.2-20081207</version>
</dependency>

启动代码:

public void startUp() {
try {
this.channelHandler = new MyChannelHandler(this.readTimeout);
this.group = new OioEventLoopGroup();
this.bootstrap = new Bootstrap();
this.bootstrap.group(this.group)
.channel(RxtxChannel.class)
.handler(new ChannelInitializer<RxtxChannel>() {
@Override
protected void initChannel(final RxtxChannel rxtxChannel) throws Exception {
ChannelPipeline pipeline = rxtxChannel.pipeline();
pipeline.addLast("frameDecoder", new FrameDecoder());
pipeline.addLast("encoder", new MessageEncoder());
pipeline.addLast("decoder", new MessageDecoder());
pipeline.addLast("handler", channelHandler);
}
});
this.bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000);
this.bootstrap.option(RxtxChannelOption.BAUD_RATE, this.baudRate);
this.bootstrap.option(RxtxChannelOption.PARITY_BIT, Paritybit.NONE);
this.bootstrap.option(RxtxChannelOption.DATA_BITS, Databits.DATABITS_8);
this.bootstrap.option(RxtxChannelOption.STOP_BITS, Stopbits.STOPBITS_1);
LOGGER.info("Started adapter " + this.toString());
} catch (Throwable t) {
LOGGER.error("Couldn't to start adapter. Reason: " + ExceptionUtils.getStackTrace(t));
}

并创建连接:

public Channel connect() {
// Make a new connection
String port = File.separator+"dev"+File.separator+"ttyUSB0");
ChannelFuture connectFuture = this.bootstrap.connect(new RxtxDeviceAddress(port);
// Wait until the connection is made successfully
Channel channel = connectFuture.awaitUninterruptibly().channel();

return channel;
}

我已经从存储库下载了库:

sudo apt-get install librxtx-java

以防万一,我更改了串行文件的权限:

sudo chmod 777 /dev/ttyUSB0

当我插入设备时,dmeseg 显示:

[  996.380535] usb 1-1.2: new full-speed USB device number 9 using dwc_otg
[ 996.508021] usb 1-1.2: New USB device found, idVendor=0403, idProduct=6001
[ 996.508048] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 996.508066] usb 1-1.2: Product: FT232R USB UART
[ 996.508082] usb 1-1.2: Manufacturer: FTDI
[ 996.508098] usb 1-1.2: SerialNumber: AL00B3PT
[ 996.517387] ftdi_sio 1-1.2:1.0: FTDI USB Serial Device converter detected
[ 996.517765] usb 1-1.2: Detected FT232RL
[ 996.518998] usb 1-1.2: FTDI USB Serial Device converter now attached to ttyUSB0

在应用程序日志中我有:

Stable Library
=========================================
Native lib Version = RXTX-2.2pre2
Java lib Version = RXTX-2.1-7
WARNING: RXTX Version mismatch
Jar version = RXTX-2.1-7
native lib Version = RXTX-2.2pre2

所以库已正确加载。

帮忙吗?

最佳答案

Java 库和 native 库不匹配。尝试对两者使用相同的版本。

关于java - 将 RXTX 从 迁移到 Raspbian,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33633932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com