java - 如何修复错误 : 'Could not load library ' toscomm': no toscomm in java. library.path'?

标签 java makefile serial-port tinyos

我正在熟悉Tiny OS环境,目前正在学习第4课“Mote-PC串行通信和SerialForwarder” 我被困在必须监听串行端口以获取任何传入数据的部分。我正在尝试实现一个简单的示例,其中我需要使用 TestSerial 脚本来监听任何传入消息,但是当我运行时

java TestSerial -comm serial@/dev/ttyUSB0:iris

我的输出看起来像这样:

Error loading the TinyOS JNI libraries the conventional way!
Attempting to load library 'toscomm'
Could not load library 'toscomm': no toscomm in java.library.path
----------
java.lang.UnsatisfiedLinkError: no toscomm in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1865)
    at java.lang.Runtime.loadLibrary0(Runtime.java:870)
    at java.lang.System.loadLibrary(System.java:1119)
    at net.tinyos.util.TOSLibraryLoader.load(TOSLibraryLoader.java:85)
    at net.tinyos.comm.TOSCommJNI.<clinit>(TOSCommJNI.java:14)
    at net.tinyos.comm.NativeSerial.getTOSCommMap(NativeSerial.java:207)
    at net.tinyos.comm.TOSSerial.<init>(TOSSerial.java:277)
    at net.tinyos.packet.SerialByteSource.openStreams(SerialByteSource.java:67)
    at net.tinyos.packet.StreamByteSource.open(StreamByteSource.java:61)
    at net.tinyos.packet.Packetizer.openSource(Packetizer.java:149)
    at net.tinyos.packet.AbstractSource.open(AbstractSource.java:78)
    at net.tinyos.packet.Packetizer.open(Packetizer.java:142)
    at net.tinyos.packet.PhoenixSource.run(PhoenixSource.java:178)
----------

In order to load the library 'toscomm' Java tries to locate the file 'libtoscomm.so' in one of the following paths:
/usr/java/packages/lib/i386:/lib:/usr/lib

The operating system is 'Linux' (i386)

Trying to locate the file 'linux_x86_toscomm.lib' in the classpath
Temporary file created: '/tmp/toscomm3780740783398787473.lib'
Library copied successfully. Let's load it.
Library loaded successfully
serial@/dev/ttyUSB0:57600: resynchronising
Sending packet 0
Sending packet 1

而不是

Sending packet 1
Received packet sequence number 4
Sending packet 2
Received packet sequence number 5

如教程中所述

我担心运行此脚本时收到的警告,尤其是这个

Attempting to load library 'toscomm'
Could not load library 'toscomm': no toscomm in java.library.path

根据教程,可以通过运行来解决此错误

sudo tos-install-jni,

但是,当我输入此内容时,我收到错误消息:找不到 tos 命令。 我尝试进入 tinyos-2.x/tools/tinyos/java. 目录并输入 sudo make 和 sudo make install ,尽管如此,这不起作用,也给了我以下错误:

make[1]: Entering directory '/home/wsn/tinyos-main/tools'
/bin/sh ./config.status --recheck
running CONFIG_SHELL=/bin/sh /bin/sh ./configure --no-create --no-recursion
checking for a BSD-compatible install... /bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking dependency style of g++... gcc3
checking for ranlib... ranlib
checking for a Python3 interpreter with version >= 3.0... python3
checking for python3... /bin/python3
checking for python3 version... 
checking for python3 platform... linux
checking for python3 script directory... ${prefix}/lib/python3.4/site-packages
checking for python3 extension module directory... /lib/python/site-packages
checking for a Python interpreter with version >= 2.5... python2
checking for python2... /bin/python2
checking for python2 version... 2.7
checking for python2 platform... linux2
checking for python2 script directory... ${prefix}/lib/python2.7/site-packages
checking for python2 extension module directory... (cached) /lib/python/site-packages
checking for perl... /bin/perl
checking for python2... /bin/python2
checking for python3... /bin/python3
checking for python2.7-config... /bin/python2.7-config
checking for dot... no
configure: I can't find dot. dot is required for documentation.
checking for nescc... /bin/nescc
checking for cygwin... no
checking for JDK location... configure: error: java not found
Makefile:377: recipe for target 'config.status' failed
make[1]: *** [config.status] Error 1
make[1]: Leaving directory '/home/wsn/tinyos-main/tools'
Makefile:374: recipe for target '../../config.status' failed
make: *** [../../config.status] Error 2

当我尝试对基站脚本运行相同的命令时,程序会给出相同的警告,并且此时会被卡住:

serial@/dev/ttyUSB0:57600: resynchronising

所以我什至没有看到任何发送或接收的数据包!

不知道问题出在哪里,请帮忙。

我正在使用带有 Fedora 操作系统的虚拟机

我正在尝试在 mib520 平台上运行该程序,并且我使用 iris motes

我的java版本

openjdk版本“1.8.0_31” OpenJDK 运行时环境(内部版本 1.8.0_31-b13) OpenJDK 服务器虚拟机(版本 25.31-b07,混合模式)

最佳答案

我认为您的问题不在于 toscomm,只要库最终成功加载,您就不应该遇到任何问题。我总是遇到同样的异常,每次我使用串口时都会遇到同样的异常,但从来没有费心去修复它,因为它并没有真正妨碍串口的操作。

最后,我通过将 libtoscomm{TOS_ROOT}/tools/tinyos/java/serial/ 目录复制到其中一个目录来摆脱异常TinyOS 正在寻找库。在您的情况下,您可以将 libtoscomm 文件的副本放入目录之一 /usr/java/packages/lib/i386/lib/usr/lib

您可以尝试这样做,看看是否可以解决您的异常问题。

我怀疑可能导致您出现问题的是您没有将 TestSerialAppC 加载到您的节点上并连接到串行端口。您确定节点已连接到串行端口吗?

我在节点上加载并运行了应用程序并得到了以下输出,因此问题不在于 TestSerialAppC

serial@/dev/tty.usbserial-FTYRYAHT:115200: resynchronising
Sending packet 0
Received packet sequence number 3
Sending packet 1
Received packet sequence number 4
Sending packet 2

关于java - 如何修复错误 : 'Could not load library ' toscomm': no toscomm in java. library.path'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55306927/

相关文章:

makefile - 在 Makefile if 语句中获取退出代码 1

c++ - 自动工具问题和生成 C++ 库

c - GNU、autotools 的 makefile - 构建 C 语言源代码的规则和方法

bash - 在适用于 Linux 的 Windows 子系统 (WSL) 中查找事件串行端口

c# - Linux 开发中的资源权限

Java GUI - MouseListener 和 ActionListener 可以在同一个类中吗?

java - 从 Selenium Webdriver 的下拉列表中选择选项时忽略大小写

java - 为什么将首选大小设置为 Double.POSITIVE_INFINITY 或 Double.MAX_VALUE 在 JavaFX 中不起作用,而 10000 却可以?

Java线程同步方法

linux - Linux 中的虚拟 COM 驱动程序用于从 USB 设备接收数据