我用了串口调试助手(UartAssist.exe串口调试助手 (CM版)) 
先把“按十六进制发送”勾上 
然后再输入A8 00 01 00 15 00 
或用sscom32.exe 
先把“hex发送”勾上 
然后再输入A8 00 01 00 15 00 
这样都可以从串口外部设备看到结果 
但是在程序中应该怎么处理呢?? 
我用的是comm.jar 

解决方案 »

  1.   

    我做过这样的!http://iffiffj.javaeye.com/
      

  2.   

    package serial;import java.io.*;
    import java.util.*;
    import javax.comm.*;public class SimpleWrite {
    static Enumeration portList;
    static CommPortIdentifier portId;
    //static String messageString = "A80001011500";
    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("COM1")) {
    // if (portId.getName().equals("/dev/term/a")) {
    try {
    serialPort = (SerialPort) portId.open("SimpleWriteApp",2000);
    } catch (PortInUseException e) {
    e.printStackTrace();
    }
    try {
    outputStream = serialPort.getOutputStream();
    } catch (IOException e) {
    e.printStackTrace();
    }
    try {
    serialPort.setSerialPortParams(1200,
    SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
    SerialPort.PARITY_NONE);
    } catch (UnsupportedCommOperationException e) {
    e.printStackTrace();
    }
    try {
    byte[] b = new byte[]{(byte)0xA8, (byte)0x00, (byte)0x01, 
    (byte)0x04, (byte)0x0F, (byte)0x00};
    outputStream.write(b);
    //outputStream.write(messageString.getBytes());
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }
    }
    }
    }
      

  3.   

    这是个简单的写操作
    最后我把A8 00 01 00 15 00 先写成十六进制的形式,然后强制转换成byte,再放到byte数组中
    byte[] b = new byte[]{(byte)0xA8, (byte)0x00, (byte)0x01, (byte)0x04, (byte)0x0F, (byte)0x00}; 
    也可以写成
    byte[] b = new byte[]{(byte)168, (byte)0, (byte)1, (byte)4, (byte)15, (byte)0};