Esempio n. 1
0
    /// <summary>
    /// Build new database entry based on LinkedData and OPC UA.
    /// </summary>
    /// <returns>New database object</returns>
    /// <param name="ldResponse">Linked Data response object.</param>
    /// <param name="module">Name of the module</param>
    private DeviceGUI BuildDatabaseEntry(LinkedDataObject ldResponse, String module)
    {
        // Validate the Device and get the new device back.
        Device local = devVali.Validator(ldResponse.PlantTag, module, istNodeIds);

        local.LinkedData_data = ldResponse;         // Safe LinkedData
        // Now OPC UA Data:
        if (istNodeIds.TagToNodeId [module].ContainsKey(ldResponse.PlantTag))
        {
            // There are opc ua inforamtion
            local.InitOPCUAData(restAPI.getNode(istNodeIds.TagToNodeId [module] [ldResponse.PlantTag].Core), restAPI.getNode(sollNodeIds.SollNodeId [module] [ldResponse.PlantTag]));
        }
        else if (local.DeviceType == "Tank")
        {
            // There are opc ua information for the submoduls
            local.InitOPCUAData(istNodeIds, sollNodeIds, restAPI);
        }
        else
        {
            local = new HandValve(local.Tag);
            local.InitOPCUAData(null, null);
        }

        try {
            return((DeviceGUI)local);            // return the object
        } catch (Exception e) {
            Debug.Log(local.LinkedData_data.PlantTag + ": TypeCast faild -> " + e.Message);
            DeviceGUI newLocal = new DeviceGUI(local.LinkedData_data.PlantTag);
            return(newLocal);
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Identifies the class/type of the device and returns it.
    /// </summary>
    /// <param name="plantTag">Plant tag</param>
    /// <param name="module">Name of the module in plant</param>
    /// <param name="istIds">Mapping of opc ua node id's</param>
    /// <returns></returns>
    public Device Validator(string plantTag, string module, IstOPCUANodeIds istIds)
    {
        Device local;

        switch (plantTag[0].ToString())
        {
        case "P":
            switch (plantTag)
            {
            case "PIC":
                local = new Device(plantTag);
                break;

            case "PROP_V":
                local = new Device(plantTag);
                break;

            default:
                local = new Pump(plantTag);
                break;
            }
            break;

        case "V":
            // Valve modeld in opc ua
            if (istIds.TagToNodeId[module].ContainsKey(plantTag))
            {
                // RelayValve
                if (istIds.TagToNodeId[module][plantTag].Core.Contains("#"))
                {
                    local = new RelayValve(plantTag);
                }
                else                     // Normal valve
                {
                    local = new Valve(plantTag);
                }
            }
            else                 // only modeld in Linked Data
                                 // Handventil. Achtung codedopplung.
            {
                local = new HandValve(plantTag);
            }
            break;

        case "F":
            // TODO: Fix device typ
            local = new Device(plantTag);
            break;

        case "L":
            // TODO: NIcht eindeutig ob binär oder linear
            local = new BinarySensor(plantTag);
            break;

        case "R":
            local = new Mixer(plantTag);
            break;

        case "T":
            local = new TemperatureSensor(plantTag);
            break;

        case "B":
            local = new Tank(plantTag);
            break;

        case "W":
            // Spechial case: WT
            if (plantTag [1].ToString() == "T")
            {
                local = new DeviceGUI(plantTag);
            }
            else
            {
                local = new Device(plantTag);
            }
            break;

        default:
            local = new Device(plantTag);
            break;
        }
        return(local);
    }