📄 plccontrol.java
字号:
package Application;
import java.io.*;
import java.util.*;
import javax.comm.*;
public class Plccontrol {
Enumeration portList;
CommPortIdentifier portId;
SerialPort serialPort;
OutputStream outputStream;
// BufferedReader buf;
String messageString = "\r";
public Plccontrol() {
}
public void LightControl(String abyte, SerialPort serialPort) {
try {
byte[] controlByte={0x55, 0x43, 0x40, 0x00, 0x00, 0x01, 0x00};
serialPort.setSerialPortParams(
19200,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_ODD);
serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
outputStream = serialPort.getOutputStream();
System.out.println(controlByte);
outputStream.write(controlByte);
outputStream.close();
serialPort.close();
System.out.println("鑿╁摝鍌堜环宸卞倣");
} catch (Exception e) {
System.err.println(e);
}
}
public void Plccontrol(String rtype, SerialPort serialPort) {
try {
int abyte;
/*
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals("COM6")) {
try {
// System.out.println("durl");
serialPort = (SerialPort)
portId.open("SimpleWriteApp", 2000);
} catch (PortInUseException e) {}
try {
outputStream = serialPort.getOutputStream();
} catch (IOException e) {}
try {
serialPort.setSerialPortParams(19200,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
*/
try {
outputStream = serialPort.getOutputStream();
} catch (IOException e) {
}
try {
outputStream.write(messageString.charAt(0));
String asciis = rtype;
abyte = asciis.charAt(0);
System.out.println(abyte);
outputStream.write(abyte);
outputStream.close();
} catch (IOException e) {
}
} catch (Exception e) {
System.err.println(e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -