lampcontrol.java

来自「一个基于sensor的中间件」· Java 代码 · 共 76 行

JAVA
76
字号
package Utopia;/* * To change this template, choose Tools | Templates * and open the template in the editor. */import java.io.*;import java.util.*;import javax.comm.*;public class LampControl {    void TurnOn() {        try {            byte[] abyte = {0x55, 0x43, 0x40, 0x00, 0x00, 0x01, 0x01};            //byte [] abyte1 = {0x55, 0x43, 0x40, 0x00, 0x00, 0x01, 0x00};            CommPortIdentifier ports =                    CommPortIdentifier.getPortIdentifier("COM6");            SerialPort port = (SerialPort) ports.open("SimpleWriteApp", 2000);// SerialPort port = (SerialPort) ports.open("SimpleReadApp2", 1000);            port.setSerialPortParams(                    19200,                    SerialPort.DATABITS_8,                    SerialPort.STOPBITS_1,                    SerialPort.PARITY_ODD);            port.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);            OutputStream out = port.getOutputStream();            System.out.println(abyte);            out.write(abyte);            out.close();            port.close();            System.out.println("鑿╁摝鍌堜环宸卞倣");        } catch (Exception e) {            System.out.println("Error:" + e.getMessage());        }    }    void TurnOff() {        try {            // byte [] abyte = {0x55, 0x43, 0x40, 0x00, 0x00, 0x01, 0x01};            byte[] abyte1 = {0x55, 0x43, 0x40, 0x00, 0x00, 0x01, 0x00};            CommPortIdentifier ports =                    CommPortIdentifier.getPortIdentifier("COM6");            SerialPort port = (SerialPort) ports.open("SimpleWriteApp", 2000);// SerialPort port = (SerialPort) ports.open("SimpleReadApp2", 1000);            port.setSerialPortParams(                    19200,                    SerialPort.DATABITS_8,                    SerialPort.STOPBITS_1,                    SerialPort.PARITY_ODD);            port.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);            OutputStream out = port.getOutputStream();            System.out.println(abyte1);            out.write(abyte1);            out.close();            port.close();            System.out.println("鑿╁摝鍌堜环宸卞倣");        } catch (Exception e) {            System.out.println("Error:" + e.getMessage());        }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?