리눅스의 USB GSM 모뎀과 시리얼 통신을하고 싶습니다. 다음 코드를 사용했습니다. 그러나 portList.hashElements는 false로 반환됩니다. RXTX librarry 2.1.7 버전을 사용했습니다. 도와주세요.포트가 등록되지 않았습니다.
코드
import java.io.*;
import java.util.*;
import gnu.io.*;
public class SimpleWrite {
static Enumeration portList;
static CommPortIdentifier portId;
static String messageString = "Hello, world!\n";
static SerialPort serialPort;
static OutputStream outputStream;
private static SerialPort p;
public static void main(String[] args) throws NoSuchPortException {
Enumeration ports = CommPortIdentifier.getPortIdentifiers();
System.out.println("start: "+ ports.hasMoreElements());
while(ports.hasMoreElements())
{
CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();
System.out.print(port.getName() + " -> " + port.getCurrentOwner() + " -> ");
switch(port.getPortType())
{
case CommPortIdentifier.PORT_PARALLEL:
System.out.println("parell");
break;
case CommPortIdentifier.PORT_SERIAL:
System.out.println("serial");
try {
p = (SerialPort) port.open("SimpleWrite", 1000);
int baudRate = 57600; // 57600bps
p.setSerialPortParams(
baudRate,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (PortInUseException e) {
System.out.println(e.getMessage());
} catch (UnsupportedCommOperationException e) {
System.out.println(e.getMessage());
}
break;
}
}
System.out.println("stop");
}
}
출력은 다음과 같습니다
안정 도서관
기본 LIB 버전 = RXTX-2.1-7 자바 버전 LIB = RXTX-2.1- 7 시작 : 거짓 정지 실험 : JNI_OnLoad가 호출되었습니다.
System.out.println ("start :"+ ports.hasMoreElements()); false으로 인쇄 중입니다. 도와주세요. 감사합니다.
은 USB가 아닌 LTP 및 COM 포트 용 RXTX 라이브러리처럼 보입니다. – user1516873