`
- 浏览:
675969 次
- 性别:
- 来自:
北京
-
1.(comm包的下载以及配置就不说了,这里主要说工具的使用)
下载VSPD(创建虚拟串口并监视通信流量的工具,用它可以创建一对虚拟串口,例如com2-com3
,那么可以用com2发数据,com2将数据发给com3,我们可以从com3接收数据)
2.下载com模拟工具(LP-COMM,或Commix,或BoastSerialTool)
这些工具不是必须的,他可以连接某个com口,你可以把数据填写到输入框,点击发送按钮,就把数据发送了。
这样比较方便,一般情况下,我们用程序发送数据,但为了调试,每次都启动程序很麻烦,这样就比较方便。
但这些工具都不能接受数据!你想看看发的数据到底发送成功没有,需要写一个从comm口读取数据的程序,
先启动它,当你用上述工具发送时,可以看到控制台输出的数据(当然前提时你的程序里有输出语句)
3.从VSPD也可以看出数据发送了,只是它只显示流量,比如从com2发送了5kb的数据,com3接受了5kb的数据
,根据这个也可以判断数据的走向,只是具体发的什么你不清楚。所以还是建议写一个读取数据的程序,
并将读取的内容在控制台打印出来,比较直观。下面附上两个程序,可供使用:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
package com.mypro;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Enumeration;
import javax.comm.CommPortIdentifier;
import javax.comm.PortInUseException;
import javax.comm.SerialPort;
import javax.comm.UnsupportedCommOperationException;
public class CommWrite {
static Enumeration portList;
static CommPortIdentifier portId;
static String messageString = "Hello, world!\n";
static SerialPort serialPort;
static OutputStream outputStream;
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")) {
try {
serialPort = (SerialPort)
portId.open("SimpleWriteApp", 2000);
} catch (PortInUseException e) {}
try {
outputStream = serialPort.getOutputStream();
} catch (IOException e) {}
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
try {
for(int i=0;i<1000;i++){
messageString+="the time "+i+"--\n"+messageString+"\n";
outputStream.write(messageString.getBytes());
}
} catch (IOException e) {}
}
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
package com.mypro;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.TooManyListenersException;
import javax.comm.CommPortIdentifier;
import javax.comm.PortInUseException;
import javax.comm.SerialPort;
import javax.comm.SerialPortEvent;
import javax.comm.SerialPortEventListener;
import javax.comm.UnsupportedCommOperationException;
public class CommRead implements SerialPortEventListener {
static CommPortIdentifier portId;
static Enumeration portList;
static InputStream inputStream;
static SerialPort serialPort;
Thread readThread;
public CommRead(){
init();
}
private void init() {
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals("COM3")) {
try {
serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
} catch (PortInUseException e) {}
//加串口事件
try {
serialPort.addEventListener(this);
} catch (TooManyListenersException e) {}
//获取输入流
try {
inputStream = serialPort.getInputStream();
} catch (IOException e) {}
serialPort.notifyOnDataAvailable(true);
//设置参数
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
}
}
}
}
//串口事件
public void serialEvent(SerialPortEvent event) {
switch(event.getEventType()) {
case SerialPortEvent.BI:{System.out.println("SerialPortEvent.BI");}
case SerialPortEvent.OE:{System.out.println("SerialPortEvent.OE");}
case SerialPortEvent.FE:{System.out.println("SerialPortEvent.FE");}
case SerialPortEvent.PE:{System.out.println("SerialPortEvent.PE");}
case SerialPortEvent.CD:{System.out.println("SerialPortEvent.CD");}
case SerialPortEvent.CTS:{System.out.println("SerialPortEvent.CTS");}
case SerialPortEvent.DSR:{System.out.println("SerialPortEvent.DSR");}
case SerialPortEvent.RI:{System.out.println("SerialPortEvent.RI");}
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[200];
try {
while (inputStream.available() > 0) {
int numBytes = inputStream.read(readBuffer);
// System.out.println("-----"+numBytes);
System.out.print(new String(readBuffer));
}
// System.out.print(new String(readBuffer));
} catch (IOException e) {}
break;
}
}
public static void main(String[] args) {
CommRead cc=new CommRead();
}
}
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
虚拟串口工具 虚拟串口工具 虚拟串口工具
虚拟串口工具,可以直接虚拟出一对或多对串口,不依赖硬件 虚拟串口工具,可以直接虚拟出一对或多对串口,不依赖硬件 虚拟串口工具,可以直接虚拟出一对或多对串口,不依赖硬件
虚拟串口工具
PLC远程下载调试虚拟串口工具用于PLC远程下载、PLC远程调试、PLC远程维护。通过PLC远程下载调试虚拟串口工具,工程师不需要到现场,可以远程通过网络,配合PLC远程网关D225等设备对PLC进行维护。
虚拟串口工具,增加虚拟串口方便本地串口调试
VSPD虚拟串口工具,方便测试软件,可添加多个虚拟端口供开发者调试
虚拟串口工具,用于调试串口程序,在win7 64位下测试正常
虚拟串口工具,方便串口调试,解压后直接安装,串口测试软件,Java与C#版本都可以去我博客里找。。。。
虚拟串口工具VSPD(Virtual Serial Port Driver)6.9安装包
虚拟串口工具安装rar,虚拟串口工具安装
VSPD虚拟串口工具.zip
虚拟串口调试工具,虚拟串口调试工具,虚拟串口调试工具,虚拟串口调试工具,虚拟串口调试工具,虚拟串口调试工具,
电脑虚拟串口工具vspd,无需安装,直接打开即可创建虚拟串口,通常我们的电脑只有两个USB接口,一个用来连接鼠标,另一个用来U盘,对于特殊情况需要多个串口时,使用该工具可创建虚拟串口,无数量限制,哪怕是几十个...
虚拟串口工具
虚拟串口工具+调试助手,可直接使用
增加虚拟串口,方便计算内软件之间进行数据交互,例如组态软件要读取dtu数据可将dtu数据发送至虚拟串口,然后在用组态软件读取对应的串口,
稳定的虚拟串口工具,XP/WIN7/WIN10通用。 32bit/64bit都可以。
没串口的笔记本可以不用担心调试串口程序了,直接可以虚拟串口,
虚拟串口工具,最多可虚拟256个串口。方便232开发调试