use of javafish.clients.opc.variant.VariantList 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;
}
}
}
use of javafish.clients.opc.variant.VariantList in project TeachingInSimulation by ScOrPiOzzy.
the class FX3UPLCLogicAssist method count.
private void count(final String outputAddr) {
int count = dest.get(outputAddr);
int higher = count / 65536;
int lower = count % 65536;
VariantList variantList = new VariantList(Variant.VT_ARRAY);
variantList.add(new Variant((short) lower & 0xFFFF));
variantList.add(new Variant((short) higher & 0xFFFF));
Variant new_variant = new Variant(variantList);
if ("Y0".equals(outputAddr)) {
logic.getOPCClient().updateItemValue(logic.getDeivceName() + ".D.D8340", new_variant);
} else if ("Y1".equals(outputAddr)) {
logic.getOPCClient().updateItemValue(logic.getDeivceName() + ".D.D8350", new_variant);
}
}
Aggregations