易截截图软件、单文件、免安装、纯绿色、仅160KB

Java串口编程3

    终于完成了串口的编写,功能很简单,如下:
    做出一个简单界面,向串口发送特定的命令(串口上接有供测试用的串口设备),接收设备返回的数据在界面上显示:
import gnu.io.CommPortIdentifier;
import gnu.io.PortInUseException;
import gnu.io.SerialPort;
import gnu.io.SerialPortEvent;
import gnu.io.SerialPortEventListener;
import gnu.io.UnsupportedCommOperationException;
import java.awt.Button;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.TooManyListenersException;
class S_Frame extends Frame implements ActionListener,SerialPortEventListener {
   
    //检测系统中可用的通讯端口类
    static CommPortIdentifier portId;
    //Enumeration 为枚举型类,在util中
    static Enumeration portList;
   
    //输入输出流
    InputStream inputStream;
    OutputStream outputStream;
   
    //RS-232的串行口
    SerialPort serialPort;
   
    Thread readThread;
    String str = "";
   
    //界面
    Panel p = new Panel();
    TextArea in_message = new TextArea("打开COM1,波特率9600,数据位8,停止位1.");
    TextArea out_message = new TextArea("X010600Y");
    Button btnOpen = new Button("打开串口, 发送数据");
    Button btnClose = new Button("关闭串口, 停止发送数据");
    byte data[] = new byte[10240];


相关文档:

Java中集合容器类List和Set的用法

List的用法
List包括List接口以及List接口的所有实现类。因为List接口实现了Collection接口,所以List接口拥有Collection接口提供的所有常用方法,又因为List是列表类型,所以List接口还提供了一些适合于自身的常用方法,如表1所示。
表1  List接口定义的常用方法及功能
从表1可以看出,List接口提供的适合于自身的 ......

java:Object对象进行排序

package arrays.compara;
import java.util.Arrays;
public class Student {
 public static void main(String[] args) {
  Stu[] stus = new Stu[]{
    new Stu(156,34,"ad"),
    new Stu(153,24,"cc"),
    new Stu(126,37,"ab"), ......

java:经典文件写入和读取,速度超快

package arrays.file;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamRea ......

java:Set循环遍历的俩种方法使用

package collection;
import java.util.*;
public class NewSet {
 public static void main(String[] args) {
  Set<Student> students = new HashSet<Student>();
  for (int i = 0; i < 6; i++) {
   students.add(new Student("Happy"+i,"male"+i,20+i)) ......

java:Student类

package collection;
public class Student {
 
 public Student() {}
  
 public Student(String name, String sex, int age) {
  this.name = name;
  this.sex = sex;
  this.age = age;
 }
 @Override
 public String toString() { ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号