我曾尝试使用 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.