Read.java
package serial;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import javaxm.CommPortIdentifier;
import javaxm.SerialPort;
import javaxm.SerialPortEvent;
import javaxm.SerialPortEventListener;
import javaxm.UnsupportedCommOperationException;
public class read {
static CommPortIdentifier portId;
static Enumeration portList;
InputStream inputStream;
static SerialPort serialPort;
static InputStream input;
public static void main(String[] args) throws Exception{
PortIdentifiers();
while (portList.hasMoreElements()){
//强制转换为通讯端口类型
portId=(Element();
PortType() == CommPortIdentifier.PORT_SERIAL){
螺旋焊缝钢管
// System.out.Name());
if (Name().equals("COM2")) {
System.out.println("用于接收的串口:"+Name()); //打开串口
serialPort = (SerialPort) portId.open("send", 2000);
serialPort.addEventListener(new SerialPortEventListener(){
public void serialEvent(SerialPortEvent event) {
//设置串口通讯参数:波特率、数据位、停止位、奇偶校验
try {
serialPort.setSerialPortParams(9600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
}
压电陶瓷驱动器 catch (UnsupportedCommOperationException e) {}
byte[] readBuffer = new byte[1024];
try {
input = InputStream();
}
catch (IOException e) {}
try {
//读取数据流
while (input.available() > 0) {
ad(readBuffer);
}
String str=new String(readBuffer);
System.out.println(str);
}
catch (IOException e) { }
}
});
// 侦听到串口有数据,触发串口事件
ifyOnDataAvailable(true);
}
}
甲酸沸点
}
}
}
废盐焚烧炉选型Send.java
package serial;j biol chem
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Scanner;
import javaxm.CommPortIdentifier;
import javaxm.SerialPort;
public class send {
static CommPortIdentifier portId;
static Enumeration portList;
//声明RS-232串行端口
京洲灯饰 static SerialPort serialPort;
public static void main(String[] args) throws Exception{
//检测系统中可用的通讯端口类
PortIdentifiers();
while (portList.hasMoreElements()){
//强制转换为通讯端口类型
portId=(Element();
PortType() == CommPortIdentifier.PORT_SERIAL){
if (Name().equals("COM1")) {
System.out.println("用于发送的串口:"+Name());
//打开串口
serialPort = (SerialPort) portId.open("Read", 2000);
//设置串口通讯参数
serialPort.setSerialPortParams(9600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
String adLine();
//System.out.println(str);
byte[] b=new byte[1024];
Bytes();
//设置串口输出流
//OutputStream output = OutputStream();
PrintWriter output = new OutputStream());
//output.write(b);
output.println(str);
output.flush();
output.close();
serialPort.close();
}
}
}
}
}