use of javafish.clients.opc.exception.ConnectivityException in project TeachingInSimulation by ScOrPiOzzy.
the class FX3UPLCLogic method onReceivedLocal.
@Override
protected void onReceivedLocal(Terminal terminal) {
// plc工作电压
if (term_L == terminal || term_N == terminal || term_GND == terminal) {
MesureResult volt = R.matchRequiredVolt(Voltage.IS_AC, term_L, term_N, 220, 2);
boolean tmp = volt != null;
R r = R.getR(SIGNAL_EVN);
if (!workable && tmp) {
// 开始工作
workable = true;
// 输出24V电压
if (r == null) {
r = R.create(SIGNAL_EVN, Voltage.IS_DC, term_24V, term_0V, 24);
}
r.shareVoltage();
if (client != null) {
Pool.getOPCPool().submit(new Runnable() {
@Override
public void run() {
try {
client.connect();
} catch (ConnectivityException e) {
log.error("连接OPC server 失败!!" + e.getMessage(), e);
}
}
});
}
} else if (workable && !tmp) {
// 停止工作
workable = false;
if (r != null) {
r.shutPowerDown();
}
if (client != null) {
Pool.getOPCPool().submit(new Runnable() {
@Override
public void run() {
client.disconnect();
log.info("OPC 客户端断开连接");
}
});
}
}
if (client != null) {
client.setWorkable(workable);
}
return;
} else if (terminal == rda || terminal == rdb) {
}
if (!workable || client == null) {
return;
}
// 能有信号的连接头 以X开头
String prex = String.valueOf(terminal.getPO().getId().charAt(0)).toUpperCase();
if ("X".equals(prex)) {
MesureResult volt = R.matchRequiredVolt(Voltage.IS_DC, terminal, term_SS, 24, 2);
if (volt == null) {
volt = R.matchRequiredVolt(Voltage.IS_DC, term_SS, terminal, 24, 2);
}
// 满足电压的输入,将对应的X信号写入PLC
// FIXME 格式化信号格式
String signal = Signal.formatSignal(terminal.getName(), 3);
inputSignalMap.put(signal, volt != null);
assist.dealWithHSXSignal(signal, volt);
client.updateItemValue(deviceName + ".X." + signal, new Variant(volt != null));
}
}
Aggregations