Example #1
0
        public static AdminShellV20.SubmodelElementCollection CreateCollection(
            AdminShellV20.AdministrationShellEnv env, Iec61360Data data)
        {
            var collection = new AdminShellV20.SubmodelElementCollection()
            {
                idShort = data.IdShort,
                kind    = AdminShellV20.ModelingKind.CreateAsInstance(),
            };

            InitSubmodelElement(env, collection, data);
            return(collection);
        }
Example #2
0
        //SubmodelElementData Creation
        //always the same pattern -> mapping Data
        //

        private static string CreateSubmodelElementCollection(AdminShellV20.SubmodelElementCollection collection)
        {
            UAObject coll = new UAObject();

            coll.NodeId     = "ns=1;i=" + masterID.ToString();
            coll.BrowseName = "1:Collection";
            masterID++;
            List <Reference> refs = new List <Reference>();

            refs.Add(CreateHasTypeDefinition("1:AASSubmodelElementCollectionType"));
            foreach (AdminShellV20.SubmodelElementWrapper elem in collection.value)
            {
                refs.Add(CreateReference("HasComponent", CreateSubmodelElement(elem.submodelElement)));
            }
            refs.Add(
                CreateReference(
                    "HasProperty",
                    CreateProperty(
                        collection.allowDuplicates.ToString().ToLower(), "BaseVariableType", "AllowDublication",
                        "Boolean")));
            coll.References = refs.ToArray();
            root.Add((UANode)coll);
            return(coll.NodeId);
        }
Example #3
0
        /*
         * static ulong ChangeNumber = 0;
         *
         * static bool setChangeNumber(AdminShell.Referable r, ulong changeNumber)
         * {
         *  do
         *  {
         *      r.ChangeNumber = changeNumber;
         *      if (r != r.parent)
         *      {
         *          r = r.parent;
         *      }
         *      else
         *          r = null;
         *  }
         *  while (r != null);
         *
         *  return true;
         * }
         */

        public static bool timeSeriesSampling(bool final)
        {
            if (Program.isLoading)
            {
                return(true);
            }

            // ulong newChangeNumber = ChangeNumber + 1;
            // bool useNewChangeNumber = false;
            DateTime timeStamp = DateTime.Now;

            foreach (var tsb in timeSeriesBlockList)
            {
                if (tsb.sampleStatus.value == "stop")
                {
                    tsb.sampleStatus.value = "stopped";
                    final = true;
                }
                else
                {
                    if (tsb.sampleStatus.value != "start")
                    {
                        continue;
                    }
                }

                if (tsb.sampleRate == null)
                {
                    continue;
                }

                tsb.threadCounter -= 100;
                if (tsb.threadCounter > 0)
                {
                    continue;
                }

                tsb.threadCounter = Convert.ToInt32(tsb.sampleRate.value);

                int actualSamples             = Convert.ToInt32(tsb.actualSamples.value);
                int maxSamples                = Convert.ToInt32(tsb.maxSamples.value);
                int actualSamplesInCollection = Convert.ToInt32(tsb.actualSamplesInCollection.value);
                int maxSamplesInCollection    = Convert.ToInt32(tsb.maxSamplesInCollection.value);

                if (final || actualSamples < maxSamples)
                {
                    int updateMode = 0;
                    if (!final)
                    {
                        int valueCount = 1;
                        if (tsb.sourceType == "json" && tsb.sourceAddress != "")
                        {
                            AdminShell.SubmodelElementCollection c =
                                tsb.block.value.FindFirstIdShortAs <AdminShell.SubmodelElementCollection>("jsonData");
                            if (c == null)
                            {
                                c                 = new AdminShellV20.SubmodelElementCollection();
                                c.idShort         = "jsonData";
                                c.TimeStampCreate = timeStamp;
                                tsb.block.Add(c);
                                c.setTimeStamp(timeStamp);
                            }
                            parseJSON(tsb.sourceAddress, "", "", c);

                            foreach (var el in c.value)
                            {
                                if (el.submodelElement is AdminShell.Property p)
                                {
                                    if (!tsb.samplesProperties.Contains(p))
                                    {
                                        tsb.samplesProperties.Add(p);
                                        tsb.samplesValues.Add("");
                                    }
                                }
                            }
                        }
                        if (tsb.sourceType == "opchd" && tsb.sourceAddress != "")
                        {
                            GetHistory(tsb);
                            valueCount = 0;
                            if (table != null)
                            {
                                valueCount = table.Count;
                            }
                        }
                        if (tsb.sourceType == "opcda" && tsb.sourceAddress != "")
                        {
                            valueCount = GetDAData(tsb);
                        }

                        DateTime dt;
                        int      valueIndex = 0;
                        while (valueIndex < valueCount)
                        {
                            if (tsb.sourceType == "opchd" && tsb.sourceAddress != "")
                            {
                                dt = (DateTime)table[valueIndex][0];
                                Console.WriteLine(valueIndex + " " + dt + " " + table[valueIndex][1] + " " + table[valueIndex][2]);
                            }
                            else
                            {
                                dt = DateTime.Now;
                            }
                            if (tsb.samplesTimeStamp == "")
                            {
                                tsb.samplesTimeStamp += dt.ToString("yy-MM-dd HH:mm:ss.fff");
                            }
                            else
                            {
                                tsb.samplesTimeStamp += "," + dt.ToString("HH:mm:ss.fff");
                            }

                            for (int i = 0; i < tsb.samplesProperties.Count; i++)
                            {
                                if (tsb.samplesValues[i] != "")
                                {
                                    tsb.samplesValues[i] += ",";
                                }

                                if ((tsb.sourceType == "opchd" || tsb.sourceType == "opcda") && tsb.sourceAddress != "")
                                {
                                    if (tsb.sourceType == "opchd")
                                    {
                                        string value = "";
                                        if (table[valueIndex] != null && table[valueIndex][i + 1] != null)
                                        {
                                            value = table[valueIndex][i + 1].ToString();
                                        }
                                        tsb.samplesValues[i] += value;
                                    }
                                    if (tsb.sourceType == "opcda")
                                    {
                                        tsb.samplesValues[i] += opcDAValues[i];
                                        Console.WriteLine(tsb.opcNodes[i] + " " + opcDAValues[i]);
                                    }
                                }
                                else
                                {
                                    var p = tsb.samplesProperties[i];
                                    tsb.samplesValues[i] += p.value;
                                    // tsb.samplesValues[i] += dummy++;
                                }
                            }
                            tsb.samplesValuesCount++;
                            actualSamples++;
                            tsb.actualSamples.value = "" + actualSamples;
                            tsb.actualSamples.setTimeStamp(timeStamp);
                            actualSamplesInCollection++;
                            tsb.actualSamplesInCollection.value = "" + actualSamplesInCollection;
                            tsb.actualSamplesInCollection.setTimeStamp(timeStamp);
                            if (actualSamples >= maxSamples)
                            {
                                if (tsb.sampleMode.value == "continuous")
                                {
                                    var first =
                                        tsb.data.value.FindFirstIdShortAs <AdminShell.SubmodelElementCollection>(
                                            "data" + tsb.lowDataIndex.value);
                                    if (first != null)
                                    {
                                        actualSamples          -= maxSamplesInCollection;
                                        tsb.actualSamples.value = "" + actualSamples;
                                        tsb.actualSamples.setTimeStamp(timeStamp);
                                        AasxRestServerLibrary.AasxRestServer.TestResource.eventMessage.add(
                                            first, "Remove", tsb.submodel, (ulong)timeStamp.Ticks);
                                        tsb.data.Remove(first);
                                        tsb.data.setTimeStamp(timeStamp);
                                        tsb.lowDataIndex.value = "" + (Convert.ToInt32(tsb.lowDataIndex.value) + 1);
                                        tsb.lowDataIndex.setTimeStamp(timeStamp);
                                        updateMode = 1;
                                    }
                                }
                            }
                            if (actualSamplesInCollection >= maxSamplesInCollection)
                            {
                                if (actualSamplesInCollection > 0)
                                {
                                    if (tsb.highDataIndex != null)
                                    {
                                        tsb.highDataIndex.value = "" + tsb.samplesCollectionsCount;
                                        tsb.highDataIndex.setTimeStamp(timeStamp);
                                    }
                                    var nextCollection = AdminShell.SubmodelElementCollection.CreateNew("data" + tsb.samplesCollectionsCount++);
                                    var p = AdminShell.Property.CreateNew("timeStamp");
                                    p.value = tsb.samplesTimeStamp;
                                    p.setTimeStamp(timeStamp);
                                    p.TimeStampCreate    = timeStamp;
                                    tsb.samplesTimeStamp = "";
                                    nextCollection.Add(p);
                                    nextCollection.setTimeStamp(timeStamp);
                                    nextCollection.TimeStampCreate = timeStamp;
                                    for (int i = 0; i < tsb.samplesProperties.Count; i++)
                                    {
                                        p = AdminShell.Property.CreateNew(tsb.samplesProperties[i].idShort);
                                        nextCollection.Add(p);
                                        p.value = tsb.samplesValues[i];
                                        p.setTimeStamp(timeStamp);
                                        p.TimeStampCreate    = timeStamp;
                                        tsb.samplesValues[i] = "";
                                    }
                                    tsb.data.Add(nextCollection);
                                    tsb.data.setTimeStamp(timeStamp);
                                    AasxRestServerLibrary.AasxRestServer.TestResource.eventMessage.add(
                                        nextCollection, "Add", tsb.submodel, (ulong)timeStamp.Ticks);
                                    tsb.samplesValuesCount              = 0;
                                    actualSamplesInCollection           = 0;
                                    tsb.actualSamplesInCollection.value = "" + actualSamplesInCollection;
                                    tsb.actualSamplesInCollection.setTimeStamp(timeStamp);
                                    updateMode = 1;
                                    var json = JsonConvert.SerializeObject(nextCollection, Newtonsoft.Json.Formatting.Indented,
                                                                           new JsonSerializerSettings
                                    {
                                        NullValueHandling = NullValueHandling.Ignore
                                    });
                                    Program.connectPublish(tsb.block.idShort + "." + nextCollection.idShort, json);
                                }
                            }
                            valueIndex++;
                        }
                    }
                    if (final || actualSamplesInCollection >= maxSamplesInCollection)
                    {
                        if (actualSamplesInCollection > 0)
                        {
                            if (tsb.highDataIndex != null)
                            {
                                tsb.highDataIndex.value = "" + tsb.samplesCollectionsCount;
                                tsb.highDataIndex.setTimeStamp(timeStamp);
                            }
                            var nextCollection = AdminShell.SubmodelElementCollection.CreateNew("data" + tsb.samplesCollectionsCount++);
                            var p = AdminShell.Property.CreateNew("timeStamp");
                            p.value = tsb.samplesTimeStamp;
                            p.setTimeStamp(timeStamp);
                            p.TimeStampCreate    = timeStamp;
                            tsb.samplesTimeStamp = "";
                            nextCollection.Add(p);
                            nextCollection.setTimeStamp(timeStamp);
                            nextCollection.TimeStampCreate = timeStamp;
                            for (int i = 0; i < tsb.samplesProperties.Count; i++)
                            {
                                p       = AdminShell.Property.CreateNew(tsb.samplesProperties[i].idShort);
                                p.value = tsb.samplesValues[i];
                                p.setTimeStamp(timeStamp);
                                p.TimeStampCreate    = timeStamp;
                                tsb.samplesValues[i] = "";
                                nextCollection.Add(p);
                            }
                            tsb.data.Add(nextCollection);
                            tsb.data.setTimeStamp(timeStamp);
                            AasxRestServerLibrary.AasxRestServer.TestResource.eventMessage.add(
                                nextCollection, "Add", tsb.submodel, (ulong)timeStamp.Ticks);
                            tsb.samplesValuesCount              = 0;
                            actualSamplesInCollection           = 0;
                            tsb.actualSamplesInCollection.value = "" + actualSamplesInCollection;
                            tsb.actualSamplesInCollection.setTimeStamp(timeStamp);
                            updateMode = 1;
                        }
                    }
                    if (updateMode != 0)
                    {
                        Program.signalNewData(updateMode);
                    }
                }
            }

            if (!test)
            {
                Thread.Sleep(100);
            }

            return(!final);
        }
Example #4
0
        private static string CreateSubmodelElement(AdminShellV20.SubmodelElement element)
        {
            UAObject elem = new UAObject();

            elem.BrowseName = "1:" + element.idShort;
            elem.NodeId     = "ns=1;i=" + masterID.ToString();
            masterID++;

            List <Reference> refs = new List <Reference>();

            refs.Add(CreateHasTypeDefinition("1:AASSubmodelElementType"));

            refs.Add(
                CreateReference(
                    "HasProperty", CreateProperty(element.category, "PropertyType", "Category", "String")));
            refs.Add(CreateReference("HasComponent", CreateSemanticId(element.semanticId)));

            //add Referable &
            //add Description if it exists
            if (element.description == null)
            {
                refs.Add(CreateReference("HasInterface", CreateReferable(element.category, null)));
            }
            else
            {
                refs.Add(
                    CreateReference(
                        "HasInterface", CreateReferable(element.category, element.description.langString)));
            }

            //add Kind if it exists
            if (element.kind != null)
            {
                refs.Add(
                    CreateReference(
                        "HasProperty",
                        CreateProperty(element.kind.kind, "1:AASModelingKindDataType", "ModellingKind", "String")));
            }


            //add Qualifier if it exists
            if (element.qualifiers != null)
            {
                foreach (AdminShellV20.Qualifier qualifier in element.qualifiers)
                {
                    refs.Add(
                        CreateReference(
                            "HasComponent", CreateAASQualifier(qualifier.type, qualifier.value, qualifier.valueId)));
                }
            }

            //Set Elementspecific Data
            string type = element.GetElementName();

            switch (type)
            {
            case "SubmodelElementCollection":
                AdminShellV20.SubmodelElementCollection coll = (AdminShellV20.SubmodelElementCollection)element;
                refs.Add(CreateReference("HasComponent", CreateSubmodelElementCollection(coll)));
                break;

            case "Property":
                AdminShellV20.Property prop = (AdminShellV20.Property)element;
                refs.Add(CreateReference("HasComponent", CreatePropertyType(prop.value, prop.valueId)));
                break;

            case "Operation":
                AdminShellV20.Operation op = (AdminShellV20.Operation)element;
                refs.Add(CreateReference("HasComponent", CreateAASOperation(op.inputVariable, op.outputVariable)));
                break;

            case "Blob":
                AdminShellV20.Blob blob = (AdminShellV20.Blob)element;
                refs.Add(CreateReference("HasComponent", CreateAASBlob(blob.value, blob.mimeType)));
                break;

            case "File":
                AdminShellV20.File file = (AdminShellV20.File)element;
                refs.Add(CreateReference("HasComponent", CreateAASFile(file.value, file.mimeType)));
                break;

            case "RelationshipElement":
                AdminShellV20.RelationshipElement rela = (AdminShellV20.RelationshipElement)element;

                refs.Add(
                    CreateReference(
                        "HasComponent",
                        CreateAASRelationshipElement(rela.first.ToString(), rela.second.ToString())));
                break;

            case "ReferenceElement":
                AdminShellV20.ReferenceElement refe = (AdminShellV20.ReferenceElement)element;
                refs.Add(CreateReference("HasComponent", CreateReferenceElement(refe.value.ToString())));
                break;
            }

            elem.References = refs.ToArray();
            root.Add((UANode)elem);
            return(elem.NodeId);
        }