publicvoidserialEvent(SerialPortEventevent){switch(event.getEventType()){caseSerialPortEvent.BI;caseSerialPortEvent.OE;caseSerialPortEvent.FE;caseSerialPortEvent.PE;c...
public void serialEvent(SerialPortEvent event) {
switch(event.getEventType()) {
case SerialPortEvent.BI;
case SerialPortEvent.OE;
case SerialPortEvent.FE;
case SerialPortEvent.PE;
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[20];
int numBytes=0;
try {
while(inputStream.available() > 0) {
numBytes= inputStream.read(readBuffer);
}
char readPlace = (char)readBuffer[2];
char readCar= (char)readBuffer[4];
System.out.println(readPlace + readPlace);
System.out.println(readCar);
}catch (IOException e) {}
break;
}
}
public static void main(String[] args) {
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals("COM2")) {
SimpleRead reader = new SimpleRead();
}
}
}
}
}
我如何在其他的Java程序里面调用readPlace和readCar这两个变量
展开