1、现有场景如下
关机场景
关机流程图
2、开机流程图
通电开机流程图
3、电脑关机控制程序如下
package com.ahies.stm.app.nec;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import java.util.Enumeration;
import java.util.Properties;
import java.util.TooManyListenersException;
import gnu.io.CommPort;
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 lombok.extern.slf4j.Slf4j;
@Slf4j
public class PcPowerController implements Runnable, SerialPortEventListener {
private static final String propertiesFilePath = "d:\\PowerController.properties";
private int interval = 60000;
//检测系统中可用的通讯端口类
private CommPortIdentifier portId;
//枚举类型
private Enumeration<CommPortIdentifier> portList;
private SerialPort serialPort;
//输入输出流
private InputStream inputStream;
//主控板向电脑端串口发送的控制命令
private String boardCommand = "";
//pc的串口
private String pcPortName = "";
//延时关机时间
private int pcShutdownDelayTime = 0;
//是否配置了投影儀 0沒有配置
private int enableProjector = 0;
//投影儀串口名
private String pcPortName4Projector = "";
//投影儀 波特率
private int projectorBaudRate = 9600;
//投影仪数据位数
private int projectorBitNum = 8;
//投影仪停止位
private int projectorStopBit = 1;
//投影仪校验位
private int projectorCheckBit = 0;
//投影仪开机命令
private String projectorStartupCommand = "";
//投影仪关机命令
private String projectorShutdownCommand = "";
//投影仪开机延时
private int projectorStartupDelayTime = 0;
private static final int PROJECTOR_STARTUP = 1;
private static final int PROJECTOR_SHUTDOWN = 2;
//初始化串口
public void init() {
//读取配置
loadConfig();
//启动投影仪
controlProjector(PROJECTOR_STARTUP);
//建立电脑与中控板串口通讯链接
setupBoardComm();
}
private void setupBoardComm() {
//建立电脑与中控板串口通讯链接
//获取系统中所有的通讯端口
portList = CommPortIdentifier.getPortIdentifiers();
//循环通讯端口
while (portList.hasMoreElements()) {
portId = portList.nextElement();
log.debug("Found pc port: " + portId.getName());
//判断是否是串口
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
//比较串口名称是否是电脑端与中控板连接的串口
if (pcPortName.equals(portId.getName())) {
log.debug("Found pc power control port.");
//打开串口
try {
//open:(应用程序名【随意命名】,阻塞时等待的毫秒数)