Search in sources :

Example 6 with Variant

use of javafish.clients.opc.variant.Variant in project TeachingInSimulation by ScOrPiOzzy.

the class FX3UPLCLogicAssist method M0511.

/**
 * HEE 频率
 * @param variant
 */
public void M0511(Variant variant) {
    if (variant.getBoolean()) {
        Variant value = logic.getItemValue(logic.getDeivceName() + ".D.D113");
        int vt_int = value.getWord() & 0xFFFF;
        Map<String, String> data = new HashMap<String, String>();
        data.put("HEE", String.valueOf(vt_int));
        logic.s_rs485(data);
    } else {
        Map<String, String> data = new HashMap<String, String>();
        data.put("HEE", "0");
        logic.s_rs485(data);
    }
}
Also used : Variant(javafish.clients.opc.variant.Variant) HashMap(java.util.HashMap)

Example 7 with Variant

use of javafish.clients.opc.variant.Variant in project TeachingInSimulation by ScOrPiOzzy.

the class FX3UPLCLogicAssist method M0560.

// 回零
public void M0560(final Variant variant) {
    if (variant.getBoolean()) {
        // 回零
        String value = entry.get("M0560");
        final List<String> arr = StringUtil.split(value, ' ');
        // 回零速度
        Integer sp = MathUtil.parseInt(arr.get(1).substring(1), 20000);
        // 使用回零速度
        int[] d = getPulseSome(sp);
        // 多久数一次
        int period = d[0];
        // 一次数多少
        final int pulsePeriod = d[1];
        final Timer timer = new Timer();
        final String outputAddr = arr.get(4);
        Integer current = dest.get(outputAddr);
        final Integer pulseAmount = 0;
        // true表示正,false表示负,
        final boolean dir = current < pulseAmount;
        final Map<String, String> data = new HashMap<String, String>();
        data.put("pulseAmount", arr.get(1).substring(1));
        data.put("pulseFrequency", arr.get(2).substring(1));
        dealWithYSignal(outputAddr, new Variant(true), data);
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                try {
                    System.out.println("FX3UPLCLogicAssist.M0560(...).new TimerTask() {...}.run()" + variant.getBoolean());
                    boolean crawl = logic.getInputSignal(arr.get(3));
                    // 使用爬行速度
                    if (crawl) {
                        timer.cancel();
                        // 爬行速度
                        Integer cp = MathUtil.parseInt(arr.get(2).substring(1), 1000);
                        // 使用回零速度
                        int[] d = getPulseSome(cp);
                        // 多久数一次
                        int period = d[0];
                        // 一次数多少
                        final int pulsePeriod = d[1];
                        final Timer timer2 = new Timer();
                        timer2.schedule(new TimerTask() {

                            @Override
                            public void run() {
                                String outputAddr = arr.get(4);
                                Integer current = dest.get(outputAddr);
                                Integer pulseAmount = 0;
                                // true表示正,false表示负,
                                boolean dir = current < pulseAmount;
                                if (dir) {
                                    dest.put(outputAddr, dest.get(outputAddr) + pulsePeriod);
                                    if (dest.get(outputAddr) >= pulseAmount) {
                                        dest.put(outputAddr, pulseAmount);
                                        // 数完脉冲后 断开对应Y端口
                                        dealWithYSignal(outputAddr, new Variant(false), null);
                                        timer2.cancel();
                                    }
                                } else {
                                    dest.put(outputAddr, dest.get(outputAddr) - pulsePeriod);
                                    if (dest.get(outputAddr) <= pulseAmount) {
                                        dest.put(outputAddr, pulseAmount);
                                        // 数完脉冲后 断开对应Y端口
                                        dealWithYSignal(outputAddr, new Variant(false), null);
                                        timer2.cancel();
                                    }
                                }
                                count(outputAddr);
                            }
                        }, 0, period);
                    }
                    if (dir) {
                        dest.put(outputAddr, dest.get(outputAddr) + pulsePeriod);
                    } else {
                        dest.put(outputAddr, dest.get(outputAddr) - pulsePeriod);
                    }
                    count(outputAddr);
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                }
            }
        }, 0, period);
    } else {
    }
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) VariantTypeException(javafish.clients.opc.exception.VariantTypeException) Variant(javafish.clients.opc.variant.Variant) Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Aggregations

Variant (javafish.clients.opc.variant.Variant)7 HashMap (java.util.HashMap)4 Timer (java.util.Timer)2 TimerTask (java.util.TimerTask)2 VariantTypeException (javafish.clients.opc.exception.VariantTypeException)2 VariantList (javafish.clients.opc.variant.VariantList)2 MesureResult (com.cas.circuit.util.MesureResult)1 R (com.cas.circuit.util.R)1 IOException (java.io.IOException)1 ConnectivityException (javafish.clients.opc.exception.ConnectivityException)1