【发布时间】:2014-12-12 04:32:24
【问题描述】:
我曾尝试使用 TelnetSerialPort 和 jSSC 库创建虚拟串口,但无法正常工作。它没有创建虚拟串口,它使用现有的串口进行通信。
这是我使用 jSSc 库的程序
public class VirtualSerialPort
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
SerialPort serialPort = new SerialPort("COM12");
try
{
System.out.println("Port opened: " + serialPort.openPort());
System.out.println("Params setted: " + serialPort.setParams(9600, 8, 1, 0));
System.out.println("\"Hello World!!!\" successfully writen to port: " + serialPort.writeBytes("Hello World!!!".getBytes()));
System.out.println("Port closed: " + serialPort.closePort());
}
catch (SerialPortException ex)
{
System.out.println(ex);
}
}
}
它给出以下输出
Port opened: false
jssc.SerialPortException: Port name - EMPTY; Method name - setParams(); Exception type - Port not opened.
【问题讨论】:
-
什么是虚拟串口?
-
虚拟是指在设备管理器中创建com口,无需将com口物理连接到PC
-
祝你好运。
-
@Elliot Frisch 谢谢
-
这需要调用专门的操作系统 API。如果你能从 Java 中做到这一点,我会感到惊讶。
标签: java virtual-serial-port jssc