请各位大侠帮我看看java串口通信的问题
java 进行串口通信的流程是什么样的?我这里有一段别人的代码,说的很详细,但是运行报错。
如下
/*
*
* IMU.java 1.0
* Main Program for Serial Communication
*
* Created: March 27, 2001
*
* Author : Qingye Jiang (John)
* American GNC Corporation
* 888 Easy St, Simi Valley CA 93065-1812
*
* Contact: (805) 582-0582 (Tel), (805) 582-0098 (Fax)
* qjiang@tsinghua.edu
*
*/
import javax.comm.*;
import java.io.*;
import java.util.*;
class IMU
{
static CommPortIdentifier portId;
static SerialPort serialPort;
static OutputStream out;
static InputStream in;
public static void main(String[] args)
{
try
{
//Declare the serial port, and open it.
portId = CommPortIdentifier.getPortIdentifier("COM1");
System.out.println("portId.getName()");
System.out.println(portId.getName());
try
{
serialPort = (SerialPort) portId.open("IMU_App", 2000);
} catch (PortInUseException e)
{
//System.out.println(e.getMessage());
System.out.println("2");
}
//Use InputStream in to read from the serial port, and utputStream
//out to write to the serial port.
try
{
in = serialPort.getInputStream();
out = serialPort.getOutputStream();
} catch (IOException e)
{
//System.out.println(e.getMessage());
System.out.println("3");
}
//Initialize the communication parameters to 9600, 8, 1, none.
try
{
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e)
{
//System.out.println(e.getMessage());
System.out.println("serial point error");
}
} catch (NoSuchPortException e)
{
//System.out.println(e.getMessage());
System.out.println(portId.getName());
}
//Declare the serial buffer area, a thread to read from the seriial port,
//a thread to read from the serial buffer for processing, and a thread
//to write to the serial port.
SerialBuffer SB = new SerialBuffer();
ReadSerial r1 = new ReadSerial(SB, in);
ReadBuffer r2 = new ReadBuffer(SB);
WriteSerial r3 = new WriteSerial(out);
//Start all three threads.
r1.start();
r2.start();
r3.start();
}
}
这是主类,调用三个线曾
还有其它的三个类,
但是portId = CommPortIdentifier.getPortIdentifier("COM1");
这一步经过验证,portId是null
请问这是怎么回师