use of com.cas.circuit.util.R in project TeachingInSimulation by ScOrPiOzzy.
the class SwitchCtrl method doSwitch.
/**
* 按钮将其控制的state切换
* @param index index不为null则强制切换到某档
*/
public void doSwitch(Integer index) {
if (disable) {
return;
}
if (switchIndex == index) {
// System.err.println("但是 已经处于这种状态了,不跳变");
return;
}
// System.err.println(this + "跳变 " + switchIndex + " -> " + index);
Set<String> envs = new HashSet<String>();
if (resisStateIds.size() > 0) {
// System.err.println(elecComp.getResisStatesMap() + " :: " + resisStateIds +" , " + resisStateIds.get(switchIndex));
ResisState oldState = elecComp.getResisStatesMap().get(resisStateIds.get(switchIndex));
if (oldState != null) {
// 把原来的state控制的relation删除
List<ResisRelation> oldRelationList = oldState.getResisRelationList();
oldRelationList.forEach(r -> {
elecComp.resisRelationRemoved(r);
// 找出两个连接头上所有的电源环境,用来通知对应的电源电路发生了变化,重新计算电路
envs.addAll(r.getTerm1().getResidualVolt().keySet());
envs.addAll(r.getTerm2().getResidualVolt().keySet());
});
}
}
if (index == null) {
changeStateIndex(index);
} else {
switchIndex = index;
}
if (resisStateIds.size() > 0) {
// 开灯
ResisState newState = elecComp.getResisStatesMap().get(resisStateIds.get(switchIndex));
if (newState != null) {
// 把当前的state控制的relation增加
List<ResisRelation> newRelationList = newState.getResisRelationList();
newRelationList.forEach(r -> {
elecComp.resisRelationAdded(r);
// 找出两个连接头上所有的电源环境,用来通知对应的电源电路发生了变化,重新计算电路
envs.addAll(r.getTerm1().getResidualVolt().keySet());
envs.addAll(r.getTerm2().getResidualVolt().keySet());
// 如果这两个连接头上都没有找到电源环境,则有可能是两端都有电阻,所以电没有到达这两个连接头,但是闭合这两个连接头后会通路。
R tmpR = new R("Tmp_REMOVE", r.getTerm1(), r.getTerm2());
R.findAllIsopotential(tmpR.getStartTerminal(), tmpR, true);
R.findAllIsopotential(tmpR.getEndTerminal(), tmpR, true);
tmpR.getAllIsopoList().forEach(ip -> {
ip.getTerminals().forEach(t -> envs.addAll(t.getIsopotential().keySet()));
});
envs.remove("Tmp_REMOVE");
tmpR.shutPowerDown();
});
}
}
// System.out.println("SwitchCtrl.doSwitch() -----------shareVoltage-----------");
try {
for (String env : envs) {
if (Util.isEmpty(env)) {
continue;
}
R r = R.getR(env);
if (r != null) {
r.shareVoltage();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.cas.circuit.util.R in project TeachingInSimulation by ScOrPiOzzy.
the class SwitchCtrl method switchEnd.
public void switchEnd() {
if (disable) {
return;
}
if (resisStateIds.size() == 0) {
return;
}
// 开灯
ResisState newState = elecComp.getResisStatesMap().get(resisStateIds.get(switchIndex));
Set<String> envs = new HashSet<String>();
if (newState != null) {
// 把当前的state控制的relation增加
List<ResisRelation> newRelationList = newState.getResisRelationList();
newRelationList.forEach(r -> {
elecComp.resisRelationAdded(r);
// 找出两个连接头上所有的电源环境,用来通知对应的电源电路发生了变化,重新计算电路
HashSet<String> tmpEnvs = new HashSet<String>();
tmpEnvs.addAll(r.getTerm1().getResidualVolt().keySet());
tmpEnvs.addAll(r.getTerm2().getResidualVolt().keySet());
// 如果这两个连接头上都没有找到电源环境,则有可能是两端都有电阻,所以电没有到达这两个连接头,但是闭合这两个连接头后会通路。
R tmpR = new R("Tmp_REMOVE", r.getTerm1(), r.getTerm2());
R.findAllIsopotential(tmpR.getStartTerminal(), tmpR, true);
R.findAllIsopotential(tmpR.getEndTerminal(), tmpR, true);
List<IP> allIP = tmpR.getAllIsopoList();
for (IP ip : allIP) {
ip.getTerminals().forEach(t -> tmpEnvs.addAll(t.getIsopotential().keySet()));
}
tmpEnvs.remove("Tmp_REMOVE");
tmpR.shutPowerDown();
envs.addAll(tmpEnvs);
});
}
try {
for (String env : envs) {
if (Util.isEmpty(env)) {
continue;
}
R r = R.getR(env);
if (r != null) {
r.shareVoltage();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.cas.circuit.util.R in project TeachingInSimulation by ScOrPiOzzy.
the class SwitchCtrl method switchStart.
public void switchStart(Integer index) {
if (disable) {
return;
}
if (switchIndex == index) {
return;
}
Set<String> envs = new HashSet<String>();
if (resisStateIds.size() == 0) {
return;
}
// Terminal terminal = null;
// 关灯
ResisState oldState = elecComp.getResisStatesMap().get(resisStateIds.get(switchIndex));
// }
if (oldState != null) {
// 把原来的state控制的relation删除
List<ResisRelation> oldRelationList = oldState.getResisRelationList();
oldRelationList.forEach(r -> {
elecComp.resisRelationRemoved(r);
// 找出两个连接头上所有的电源环境,用来通知对应的电源电路发生了变化,重新计算电路
envs.addAll(R.findEnvsOn(r.getTerm1(), r.getTerm2()));
});
}
if (index == null) {
changeStateIndex(index);
} else {
switchIndex = index;
}
try {
for (String env : envs) {
if (Util.isEmpty(env)) {
continue;
}
R r = R.getR(env);
if (r != null) {
r.shareVoltage();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.cas.circuit.util.R in project TeachingInSimulation by ScOrPiOzzy.
the class Wire method shareTerm.
private void shareTerm(Terminal term) {
Set<String> envs = term.getResidualVolt().keySet();
R r = null;
for (String env : envs) {
r = R.getR(env);
r.shareVoltage();
}
}
use of com.cas.circuit.util.R 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