概述
用java从串口读取数据然后显示在网页上,能实现。
以下是对串口读写代码,来自网友62616964757a686964616fe4b893e5b19e31333363376364百度知道网友。其它如何传递到网页自己搜索吧。
public static void process() {
try {
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements())
{
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)//如果端口类型是串口则判断名称
{
if(portId.getName().equals("COM1")){//如果是COM1端口则退出循环
break;
}else{
portId=null;
}
}
}
SerialPort serialPort = (SerialPort)portId.open("Serial_Communication", 1000);//打开串口的超时时间为1000ms
serialPort.setSerialPortParams(9600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);//设置串口速率为9600,数据位8位,停止位1们,奇偶校验无
InputStream in = serialPort.getInputStream();//得到输入流
OutputStream out = serialPort.getOutputStream();//得到输出流
//进行输入输出操作
//操作结束后
in.close();
out.close();
serialPort.close();//关闭串口
} catch (PortInUseException e) {
e.printStackTrace();
} catch (UnsupportedCommOperationException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
最后
以上就是傲娇小蘑菇为你收集整理的java读取串口数据并可在网页上调用_用java从串口读取数据然后显示在网页上,能实现吗...的全部内容,希望文章能够帮你解决java读取串口数据并可在网页上调用_用java从串口读取数据然后显示在网页上,能实现吗...所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复