Java 我需要帮助使用ftdi usb到串行电缆写入/读取串行端口
我想首先写入串行端口。为此,我使用usb到串行ftdi电缆。该电缆连接到COM4。运行64位Windows 7 a) 使用RXTX项目。 要使用RXTX 我试着按照这些指示去做Java 我需要帮助使用ftdi usb到串行电缆写入/读取串行端口,java,serial-port,Java,Serial Port,我想首先写入串行端口。为此,我使用usb到串行ftdi电缆。该电缆连接到COM4。运行64位Windows 7 a) 使用RXTX项目。 要使用RXTX 我试着按照这些指示去做 下载rxtx-2.1-7-bins-r2.zip 解开它 将rxtxSerial.dll复制到c:\program files\java\jre version\bin目录中 将RXTXcomm.jar复制到c:\program files\java\jre version\lib\ext dir 将所有引用从“jav
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package twowayserialcomm;
/**
*
* @author HP
*/
import java.io.InputStream;
import java.io.OutputStream;
import gnu.io.SerialPort;
import gnu.io.CommPortIdentifier;
import gnu.io.CommPort;
public class TwoWaySerialComm {
/**
* @param args the command line arguments
*
*/
void connect( String portName ) throws Exception {
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier( portName );
if( portIdentifier.isCurrentlyOwned() ) {
System.out.println( "Error: Port is currently in use" );
} else {
int timeout = 10000;
CommPort commPort = portIdentifier.open( this.getClass().getName(), timeout );
if( commPort instanceof SerialPort ) {
SerialPort serialPort = ( SerialPort )commPort;
serialPort.setSerialPortParams( 9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE );
//InputStream in = serialPort.getInputStream();
OutputStream outputStream = serialPort.getOutputStream();
outputStream.write( 53 );
//outputStream.write( 1 );
//outputStream.write( 20 );
//outputStream.write( 0 );
//outputStream.write( 83 );
//CommPort port = serialPort;
System.out.println( "Write done" );
//( new Thread( new SerialReader( in,port ) ) ).start();
} else {
System.out.println( "Error: Only serial ports are handled by this example." );
}
}
}
public static void main(String[] args) {
try {
TwoWaySerialComm alex = new TwoWaySerialComm();
//( new TwoWaySerialComm() ).connect( "COM4" );
alex.connect("COM4");
} catch( Exception e ) {
e.printStackTrace();
}
}
}
运行时:
run:
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
Exception in thread "main" java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:83)
at twowayserialcomm.TwoWaySerialComm.connect(TwoWaySerialComm.java:26)
at twowayserialcomm.TwoWaySerialComm.main(TwoWaySerialComm.java:61)
C:\Users\HP\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 1 second)
这是netbeans的项目窗口
串口Java
您得到的错误意味着在
java.library.path
中找不到dll
,因此您需要通过添加-Djava.library.path=“C:\path\to\your\dll”,将系统属性设置为包含库的文件夹对应的路径
作为虚拟机选项
有关的更多详细信息您得到的错误意味着在
java.library.path
中找不到dll
,因此您需要通过添加-Djava.library.path=“C:\path\to\your\dll”,将系统属性设置为包含库的文件夹对应的路径
作为虚拟机选项
有关的更多详细信息您得到的错误意味着在
java.library.path
中找不到dll,因此您需要将系统属性java.library.path
设置为与包含库的文件夹对应的路径,请检查,谢谢Nicolas,这是有效的。如何将您的评论标记为答案?好消息,不,您不能将评论标记为答案,您只能对评论进行投票或标记。将rxtxSerial.dll放在C:\Windows\System32上您收到的错误意味着在java.library.path
中找不到该dll,因此,您需要将系统属性java.library.path
设置为包含lib的文件夹对应的路径,检查Thank Nicolas,这是有效的。如何将您的评论标记为答案?好消息,不,您不能将评论标记为答案您只能对评论进行投票或标记。请将rxtxSerial.dll放在C:\Windows\System32上
run:
javax.comm.NoSuchPortException
at javax.comm.CommPortIdentifier.getPortIdentifier(CommPortIdentifier.java:105)
at twowayserialcomm.TwoWaySerialComm.connect(TwoWaySerialComm.java:26)
at twowayserialcomm.TwoWaySerialComm.main(TwoWaySerialComm.java:61)