Search in sources :

Example 1 with OPCClientImpl

use of com.cas.opc.OPCClientImpl in project TeachingInSimulation by ScOrPiOzzy.

the class FX3UPLCLogic method initialize.

@Override
public void initialize(Node elecCompMdl) {
    super.initialize(elecCompMdl);
    assist = new FX3UPLCLogicAssist(this);
    ElecCompDef elecCompDef = elecComp.getDef();
    term_SS = elecCompDef.getTerminal("S/S");
    term_24V = elecCompDef.getTerminal("24V");
    if (term_24V == null) {
        term_24V = elecCompDef.getTerminal("24V_1");
    }
    if (term_24V == null) {
        term_24V = elecCompDef.getTerminal("24V_2");
    }
    term_0V = elecCompDef.getTerminal("0V");
    if (term_0V == null) {
        term_0V = elecCompDef.getTerminal("0V_1");
    }
    if (term_0V == null) {
        term_0V = elecCompDef.getTerminal("0V_2");
    }
    // Jack jack = elecCompDef.getJackMap().get("RS-485");
    sda = elecCompDef.getTerminal("SDA");
    sdb = elecCompDef.getTerminal("SDB");
    rda = elecCompDef.getTerminal("RDA");
    rdb = elecCompDef.getTerminal("RDB");
    SIGNAL_EVN = "PLC" + hashCode();
    // opc中设备名对应的并非工作站,而是针对具体某一个PLC元器件,所以opc相关信息写入
    // 1、引用的PLC模型的userdata中,elecCompMdl.getUserdata("device")。注意:并不是elecCompMdl.getChild(0).getUserData("device")。
    // 2、在应用PLC元器件配置文件的文本域中,elecComp.getProperty("deivce");
    final String deviceName = elecComp.getProperty("device");
    if (Util.isEmpty(deviceName)) {
        throw new RuntimeException("需要给" + elecComp + "声明opc中的device");
    }
    this.deviceName = deviceName;
    try {
        client = new OPCClientImpl(InetAddress.getLocalHost().getHostAddress());
        client.setDeviceName(deviceName);
        client.addOPCSignalVisitor(this);
    } catch (UnknownHostException e) {
        log.error(e.getMessage(), e);
    }
    initialize = true;
}
Also used : ElecCompDef(com.cas.circuit.vo.ElecCompDef) UnknownHostException(java.net.UnknownHostException) OPCClientImpl(com.cas.opc.OPCClientImpl)

Aggregations

ElecCompDef (com.cas.circuit.vo.ElecCompDef)1 OPCClientImpl (com.cas.opc.OPCClientImpl)1 UnknownHostException (java.net.UnknownHostException)1