📄 lampcontrol.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -