Search in sources :

Example 1 with R

use of com.cas.circuit.util.R in project TeachingInSimulation by ScOrPiOzzy.

the class ElecCompCPU method elecCompStart.

/**
 * 开元器件指示灯<br>
 * 产生信号电<br>
 */
protected void elecCompStart() {
    LOG.info("开始启动{}{}", elecComp.getName(), elecComp.getProxy().getTagName());
    // System.err.println(this.getClass().getCanonicalName() + ".elecCompStart(start...)");
    getElecComp().getLightIOList().forEach(l -> l.openLight());
    // 信号电压起源
    R r = null;
    Terminal ipHigher = null;
    Terminal ipLower = null;
    // CBX - CB104 CB105 CB106 CB107
    if (cb_evn_names != null) {
        for (int i = 0; i < cb_evn_names.size(); i++) {
            r = R.getR(cb_evn_names.get(i));
            if (r == null) {
                ipLower = cbx_jacks.get(i).getStitch(1);
                ipHigher = cbx_jacks.get(i).getStitch(2);
                if (ipHigher == null || ipLower == null) {
                    // System.err.println(getClass() + cbx_jacks.get(i).getId() + "中找不到1 或 2号针脚");
                    continue;
                }
                r = R.createSignal(cb_evn_names.get(i), ipHigher, ipLower, CB_SIGNAL_VOLT);
            }
            r.shareVoltage();
        }
    }
    // JF - JD1A JD1B
    if (jf_evn_names != null) {
        for (int i = 0; i < jf_evn_names.size(); i++) {
            r = R.getR(jf_evn_names.get(i));
            if (r == null) {
                ipHigher = jf_jacks.get(i).getStitch(3);
                ipLower = jf_jacks.get(i).getStitch(13);
                if (ipHigher == null || ipLower == null) {
                    // System.err.println(getClass() + jf_jacks.get(i).getId() + "中找不到3 或 13号针脚");
                    continue;
                }
                r = R.createSignal(jf_evn_names.get(i), ipHigher, ipLower, JF_SIGNAL_VOLT);
            }
            r.shareVoltage();
        }
    }
    // COP - COP10B COP10B
    if (cop_jacks != null) {
        for (int i = 0; i < cop_evn_names.size(); i++) {
            r = R.getR(cop_evn_names.get(i));
            if (r == null) {
                ipHigher = cop_jacks.get(i).getStitch(1);
                ipLower = cop_jacks.get(i).getStitch(3);
                if (ipHigher == null || ipLower == null) {
                    LOG.warn("{}.{}中找不到1 或 3号针脚", getClass(), cop_jacks.get(i).getId());
                    continue;
                }
                r = R.createSignal(cop_evn_names.get(i), ipHigher, ipLower, COP_SIGNAL_VOLT);
            }
            r.shareVoltage();
        }
    }
    // jfr* - jfr1 jfr2
    if (jfr_jacks != null) {
        String env = null;
        for (int i = 0; i < jfr_evn_names.size(); i++) {
            for (int j = 0; j < jfrEnvEnds.length; j++) {
                // env = jfr_evn_names.get(i) + jfrEnvEnds[j][0] + "_" + jfrEnvEnds[j][1];
                env = MessageFormat.format("{0}{1}_{2}", jfr_evn_names.get(i), jfrEnvEnds[j][0], jfrEnvEnds[j][1]);
                r = R.getR(env);
                if (r == null) {
                    ipHigher = jfr_jacks.get(i).getStitch(jfrEnvEnds[j][0]);
                    ipLower = jfr_jacks.get(i).getStitch(jfrEnvEnds[j][1]);
                    if (ipHigher == null || ipLower == null) {
                        // System.err.println(getClass() + jfr_jacks.get(i).getId() + "中找不到" + jfrEnvEnds[j][0] + " 或 " + jfrEnvEnds[j][1] + "号针脚");
                        continue;
                    }
                    r = R.createSignal(env, ipHigher, ipLower, COP_SIGNAL_VOLT);
                }
                r.shareVoltage();
            }
        }
    }
    // System.err.println(this.getClass().getCanonicalName() + ".elecCompStart(end...)");
    LOG.info("{}{}启动完成!", elecComp.getName(), elecComp.getProxy().getTagName());
}
Also used : R(com.cas.circuit.util.R) Terminal(com.cas.circuit.vo.Terminal)

Example 2 with R

use of com.cas.circuit.util.R in project TeachingInSimulation by ScOrPiOzzy.

the class Encoder method onTargetStart.

public void onTargetStart() {
    // System.out.println("Encoder.onTargetStart()");
    R.SERVICE.execute(() -> {
        // 设置abz与0v接通
        ResisRelation resis = new ResisRelation(_0v, _A, 0f, true);
        _A.getResisRelationMap().put(_0v, resis);
        _0v.getResisRelationMap().put(_A, resis);
        resis.setActivated(true);
        resis = new ResisRelation(_0v, _B, 0f, true);
        _B.getResisRelationMap().put(_0v, resis);
        _0v.getResisRelationMap().put(_B, resis);
        resis.setActivated(true);
        Set<String> envs = _0v.getResidualVolt().keySet();
        R r = null;
        for (String env : envs) {
            r = R.getR(env);
            r.getVoltage().putData("PulsePerMillis", String.valueOf(degPerMillis / degPerPulse));
            r.getVoltage().putData("PulseDir", String.valueOf(dir));
            r.shareVoltage();
        }
    });
}
Also used : ResisRelation(com.cas.circuit.vo.ResisRelation) R(com.cas.circuit.util.R)

Example 3 with R

use of com.cas.circuit.util.R in project TeachingInSimulation by ScOrPiOzzy.

the class Inverter method onReceivedLocal.

@Override
protected void onReceivedLocal(Terminal terminal) {
    super.onReceivedLocal(terminal);
    if (_r == terminal || _s == terminal || _t == terminal) {
        // 分别测量uvw三者之间的电压情况
        MesureResult resultUV = R.matchRequiredVolt(Voltage.IS_AC, _r, _s, 380, 10);
        MesureResult resultVW = R.matchRequiredVolt(Voltage.IS_AC, _s, _t, 380, 10);
        MesureResult resultWU = R.matchRequiredVolt(Voltage.IS_AC, _t, _r, 380, 10);
        // 判断三者之间是否存在电势差
        boolean tmp = Util.notEmpty(resultUV) && Util.notEmpty(resultWU) && Util.notEmpty(resultVW);
        List<R> controlVoltPower = R.get3Phase(controlVoltEnv);
        if (tmp && !workable) {
            workable = true;
        // if (controlVoltPower == null) {
        // controlVoltPower = R.create3Phase(controlVoltEnv, _u, _v, _w, new Terminal(), 380);
        // }
        // R.set3PhaseFrequency(controlVoltEnv, frequency);
        // R.reversePhase(controlVoltEnv, dir == Dir.CW);
        // 
        // for (R r : controlVoltPower) {
        // r.shareVoltage();
        // }
        } else if (!tmp && workable) {
            if (controlVoltPower != null) {
                for (R r : controlVoltPower) {
                    r.shutPowerDown();
                }
            }
            workable = false;
        }
    } else if (!workable) {
        return;
    } else if (_rda == terminal || _rdb == terminal) {
        // 处理PLC侧发来的数据
        MesureResult result = R.matchRequiredVolt(Voltage.IS_DC, _rda, _rdb, 5, 1);
        if (result != null) {
            Map<String, String> data = R.getR(result.getEvn()).getVoltage().getData();
            assist.decode(data);
        }
        if (voltNeedChange) {
            List<R> controlVoltPower = R.get3Phase(controlVoltEnv);
            if (controlVoltPower != null) {
                // 断电
                for (R r : controlVoltPower) {
                    r.shutPowerDown();
                }
            }
            if (dir != null) {
                controlVoltPower = R.create3Phase(controlVoltEnv, _u, _v, _w, new Terminal(), 380);
                // 通电
                // System.err.println("Inverter.onReceivedLocal()" + frequency);
                R.set3PhaseFrequency(controlVoltEnv, frequency);
                R.reversePhase(controlVoltEnv, dir == Dir.CW);
                for (R r : controlVoltPower) {
                    r.shareVoltage();
                }
            }
        }
    } else {
    }
}
Also used : MesureResult(com.cas.circuit.util.MesureResult) R(com.cas.circuit.util.R) Terminal(com.cas.circuit.vo.Terminal)

Example 4 with R

use of com.cas.circuit.util.R in project TeachingInSimulation by ScOrPiOzzy.

the class MMT_4QLogic method onReceivedLocal.

@Override
protected void onReceivedLocal(Terminal terminal) {
    MesureResult dcinResult = R.matchRequiredVolt(Voltage.IS_DC, dcin1, dcin2, 24, 2);
    R r1 = R.getR("MMT_4Q_OUT2-OUT1" + this.hashCode());
    R r2 = R.getR("MMT_4Q_OUT1-OUT2" + this.hashCode());
    if (dcinResult == null) {
        if (r1 != null) {
            r1.shutPowerDown();
        }
        if (r2 != null) {
            r2.shutPowerDown();
        }
        return;
    }
    MesureResult output = R.mesureVoltage(en, com1);
    // en--com1之间为24V则不输出,0V则输出
    if (output == null || Math.abs(output.getVolt() - 24) <= 2) {
        if (r1 != null) {
            r1.shutPowerDown();
        }
        if (r2 != null) {
            r2.shutPowerDown();
        }
        return;
    }
    MesureResult direction = R.mesureVoltage(dir, com2);
    // dir--com2之间为24V则正转,0V则反转
    if (direction == null) {
        if (r1 != null) {
            r1.shutPowerDown();
        }
        if (r2 != null) {
            r2.shutPowerDown();
        }
    } else if (Math.abs(direction.getVolt() - 24) <= 2) {
        if (r1 == null) {
            r1 = R.create("MMT_4Q_OUT2-OUT1" + this.hashCode(), Voltage.IS_DC, out2, out1, 24);
            r1.shareVoltage();
        }
        if (r2 != null) {
            r2.shutPowerDown();
        }
    } else if (Math.abs(direction.getVolt()) <= 2) {
        if (r2 == null) {
            r2 = R.create("MMT_4Q_OUT1-OUT2" + this.hashCode(), Voltage.IS_DC, out1, out2, 24);
            r2.shareVoltage();
        }
        if (r1 != null) {
            r1.shutPowerDown();
        }
    }
}
Also used : MesureResult(com.cas.circuit.util.MesureResult) R(com.cas.circuit.util.R)

Example 5 with R

use of com.cas.circuit.util.R in project TeachingInSimulation by ScOrPiOzzy.

the class ElecCompDef method doMagnetism.

// 电生磁->磁生电或力3版
public final void doMagnetism() {
    if (magnetismList.size() == 0) {
        return;
    }
    // System.out.println(ref.getTagName());
    // if ("VC1".equals(ref.getTagName())) {
    // System.out.println(this + "@" + hashCode() + ref.getTagName() + " createdEnv=" + createdEnv);
    // }
    // ref.getCompState().getEquipmentState().getEquipment().getNumber() + ref.getTagName() + ref.hashCode();
    String env_prefix = "";
    for (Magnetism magnetism : magnetismList) {
        float bili = 0;
        VoltageIO effectVoltageIO = null;
        for (VoltageIO voltageIO : magnetism.getInputVoltageIOs()) {
            // String termIds = voltageIO.getTerm1Id() + "-" + voltageIO.getTerm2Id();
            // 需求电压值和类型
            float requireVolt = voltageIO.getRequireVolt();
            int requireType = voltageIO.getVoltage().getType();
            MesureResult realVolt = R.matchRequiredVolt(requireType, voltageIO.getTerm1(), voltageIO.getTerm2(), requireVolt, voltageIO.getDeviation(), ElecCompCPU.Power_Evn_Filter);
            // 电生磁成功-- 不是自己创建的点才符合接入条件
            if (realVolt != null && (createdEnv == null || !createdEnv.contains(realVolt.getEvn()))) {
                bili = realVolt.getVolt() / requireVolt;
                effectVoltageIO = voltageIO;
                if (!magnetism.isEffect() && voltageIO.getResisStateIds().size() == 2) {
                    voltageIO.doSwitch(1);
                }
                break;
            }
        }
        R r = null;
        if (bili > 0 && !magnetism.isEffect()) {
            // 磁生电 -- 找出output的VoltageIO
            List<VoltageIO> outputVoltIOs = new ArrayList<VoltageIO>();
            outputVoltIOs.addAll(magnetism.getOutputVoltageIOs());
            outputVoltIOs.remove(effectVoltageIO);
            for (VoltageIO outputVoltIO : outputVoltIOs) {
                MesureResult checkVolt = R.matchRequiredVolt(outputVoltIO.getVoltage().getType(), outputVoltIO.getTerm1(), outputVoltIO.getTerm2(), outputVoltIO.getRequireVolt() * bili, outputVoltIO.getDeviation(), ElecCompCPU.Power_Evn_Filter);
                if (checkVolt == null) {
                    String env = env_prefix + outputVoltIO.getTerm1Id() + "-" + outputVoltIO.getTerm2Id();
                    // System.out.println("ElecCompDef.doMagnetism()");
                    addCreatedEnv(env);
                    r = R.create(env, outputVoltIO.getVoltage().getType(), outputVoltIO.getTerm1(), outputVoltIO.getTerm2(), outputVoltIO.getRequireVolt() * bili);
                    r.shareVoltage();
                // }else{
                // if("VC1".equals(ref.getTagName())){
                // System.err.println(outputVoltIO.getVoltType() +":"+outputVoltIO.getTerm1().getResidualVolt() +","+ outputVoltIO.getTerm2().getResidualVolt() +" volt=" + outputVoltIO.getRequireVolt() * bili +"Deviation="+  outputVoltIO.getDeviation());
                // }
                }
            }
            // 磁生力
            for (final ControlIO outputControlIO : magnetism.getOutputControlIOs()) {
                if (ControlIO.INTERACT_PRESS.equals(outputControlIO.getInteract())) {
                    if (!magnetism.isEffect() && outputControlIO.getSwitchIndex() == 0) {
                        outputControlIO.switchStateChanged(null);
                    // FIXME outputControlIO.playMotion(Dispatcher.getIns().getMainApp().getAssetManager(), null);
                    }
                }
            }
            // 指示灯
            for (LightIO lightIO : magnetism.getLightIOList()) {
                lightIO.openLight();
            }
            magnetism.setEffect(true);
        } else if (bili == 0 && magnetism.isEffect()) {
            // System.err.println(ref.getTagName() + "上不满足输入条件");
            for (final ControlIO outputControlIO : magnetism.getOutputControlIOs()) {
                if (ControlIO.INTERACT_PRESS.equals(outputControlIO.getInteract())) {
                    if (magnetism.isEffect() && outputControlIO.getSwitchIndex() == 1) {
                        // outputControlIO.doSwitch(0);
                        outputControlIO.switchStateChanged(null);
                    // FIXME outputControlIO.playMotion(Dispatcher.getIns().getMainApp().getAssetManager(), null);
                    }
                }
            }
            if (magnetism.isEffect()) {
                for (VoltageIO inputVoltIO : magnetism.getInputVoltageIOs()) {
                    if (inputVoltIO.getResisStateIds().size() == 2) {
                        inputVoltIO.doSwitch(0);
                    }
                }
            }
            for (VoltageIO outputVoltIO : magnetism.getOutputVoltageIOs()) {
                String powerEnv = env_prefix + outputVoltIO.getTerm1Id() + "-" + outputVoltIO.getTerm2Id();
                // System.out.println(this + "@" + hashCode() + createdEnv);
                if (createdEnv != null && createdEnv.contains(powerEnv)) {
                    // if ("VC1".equals(ref.getTagName())) {
                    // System.out.println("清除电源 " + powerEnv + "上输出的电压" + powerEnv + System.nanoTime());
                    // }
                    r = R.getR(powerEnv);
                    if (r != null) {
                        r.shutPowerDown();
                        removeCreatedEvn(powerEnv);
                    }
                }
            }
            for (LightIO lightIO : magnetism.getLightIOList()) {
                lightIO.closeLight();
            }
            magnetism.setEffect(false);
        }
    }
}
Also used : MesureResult(com.cas.circuit.util.MesureResult) R(com.cas.circuit.util.R) ArrayList(java.util.ArrayList)

Aggregations

R (com.cas.circuit.util.R)19 Terminal (com.cas.circuit.vo.Terminal)7 MesureResult (com.cas.circuit.util.MesureResult)6 ResisRelation (com.cas.circuit.vo.ResisRelation)3 HashSet (java.util.HashSet)3 Jack (com.cas.circuit.vo.Jack)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 ConnectivityException (javafish.clients.opc.exception.ConnectivityException)1 Variant (javafish.clients.opc.variant.Variant)1