use of javafish.clients.opc.exception.VariantTypeException in project TeachingInSimulation by ScOrPiOzzy.
the class FX3UPLCLogicAssist method dealWithHSXSignal.
/**
* 处理高速输入信号 <br>
* dealWith High-Speed input signal
* @param signalX
* @param i
*/
public void dealWithHSXSignal(String signalX, final MesureResult result) {
if (!hs.containsKey(signalX)) {
return;
}
hs.put(signalX, result != null);
if ("X000".equals(signalX) || "X001".equals(signalX)) {
boolean tmp = hs.get("X000").booleanValue() && hs.get("X001").booleanValue();
if (tmp && !counting) {
// System.out.println("FX3UPLCLogicAssist.dealWithHSXSignal(counting = true)");
counting = true;
// FIXME 渣代码
Pool.getCachedPool("计数器").execute(new Runnable() {
private char[] currentPulseCount;
public void run() {
pulsePerMillis = MathUtil.parseFloat(result.getData(Encoder.KEY_PulsePerMillis), pulsePerMillis);
dir = MathUtil.parseInt(result.getData(Encoder.KEY_PulseDir), dir);
float higher = 0;
float lower = 0;
try {
VariantList currentPulseCount = logic.getOPCClient().getItemValue(logic.getDeivceName() + ".C.CN251").getArray();
lower = currentPulseCount.get(0).getWord() & 0xFFFF;
higher = currentPulseCount.get(1).getWord() & 0xFFFF;
// System.out.println("FX3UPLCLogicAssist.dealWithHSXSignal(...).new Runnable() {...}.run()" + currentPulseCount);
} catch (VariantTypeException e) {
log.error(e.getMessage(), e);
}
while (counting && logic.isWorkable()) {
lower += pulsePerMillis * dir;
// System.err.println(currentPulseCount);
if (lower >= 65535) {
lower = 0;
higher += 1;
} else if (lower <= 0) {
lower = 65534;
higher -= 1;
if (higher < 0) {
higher = 65534;
}
}
VariantList variantList = new VariantList(Variant.VT_ARRAY);
variantList.add(new Variant((short) lower & 0xFFFF));
variantList.add(new Variant((short) higher & 0xFFFF));
Variant variant = new Variant(variantList);
logic.getOPCClient().updateItemValue(logic.getDeivceName() + ".C.CN251", variant);
// }
try {
Thread.sleep(1);
} catch (InterruptedException e) {
log.error(e.getMessage(), e);
}
}
counting = false;
}
});
} else if (!tmp && counting) {
// System.out.println("FX3UPLCLogicAssist.dealWithHSXSignal(counting = false)");
counting = false;
}
}
}
Aggregations