Quellcode durchsuchen

parse uavariable fields

Martin Kunz vor 9 Monaten
Ursprung
Commit
de02e6d1c5

+ 4 - 5
src/ua/UABaseNode.ts

@@ -11,7 +11,6 @@ export class UABaseNode implements IToXML{
 
     public static nullBaseNode=new UABaseNode({browseName: "", addressSpace: {} as IAddressSpace, nodeId: NodeId.nullNodeId});
 
-    //Default values from xsd
     public nodeId!: NodeId;
     public nodeClass="UABaseNode";
     public browseName!: string;
@@ -19,10 +18,10 @@ export class UABaseNode implements IToXML{
     public displayName: UALocalizedText[]=[]; 
     public description: UALocalizedText[]=[];
     public symbolicName?: string;
-    public releaseStatus: string="Released";
-    public hasNoPermissions: boolean=false; 
-    public writeMask: number=0; 
-    public userWriteMask: number=0;
+    public releaseStatus!: string;
+    public hasNoPermissions!: boolean; 
+    public writeMask!: number; 
+    public userWriteMask!: number;
     public category: string[]=[];
     public documentation?: string;
     public accessRestriction?: number; 

+ 1 - 0
src/ua/UAMethod.ts

@@ -6,6 +6,7 @@ import type { IAddressSpace } from "./IAddressSpace";
 export class UAMethod extends UABaseNode {
     constructor(options: UAMethodNodeOptions) {
                     super(options);
+                    Object.assign(this, options);  
                     this.nodeClass="Method";
     }
 

+ 14 - 5
src/ua/UAObject.ts

@@ -5,24 +5,33 @@ import type { IAddressSpace } from "./IAddressSpace";
 
 
 export class UAObject extends UABaseNode {
+    public parentNodeId?: string;
+    public eventNotifier: number=0;
+
 
 
     constructor(options: UAObjectNodeOptions) {
-                    super(options);
-                    this.nodeClass="Object";
+        super(options);
+        Object.assign(this, options);  
+        this.nodeClass="Object";
     }
 
     static  fromXML(uaObject: any, addressSpace: IAddressSpace): UAObject{
-        const bn=super.fromXML(uaObject, addressSpace)
-        return new UAObject(bn as UABaseNodeOptions);
+        const bn=super.fromXML(uaObject, addressSpace) as UAObjectNodeOptions;
+        bn.parentNodeId=uaObject['@_ParentNodeId'];
+        bn.eventNotifier=Number(uaObject['@_EventNotifier']||0);
+        return new UAObject(bn as UAObjectNodeOptions);
     }
 
     toXML(lnst:NamespaceTable, gnst:NamespaceTable): XMLElem {
         const elem =super.toXML(lnst, gnst);
+        elem.attr("ParentNodeId", this.parentNodeId);
+        elem.attr("EventNotifier", this.eventNotifier?.toString());
         return elem;
     }
 }
 
 export interface UAObjectNodeOptions extends UABaseNodeOptions{
-   
+    parentNodeId?: string;
+    eventNotifier?: number;
 }

+ 1 - 0
src/ua/UAObjectType.ts

@@ -8,6 +8,7 @@ export class UAObjectType extends UABaseNode{
   
     constructor(options: UAObjectTypeOptions) {
         super(options)
+        Object.assign(this, options);  
         this.isAbstract=options.isAbstract||false;
     }
 

+ 1 - 0
src/ua/UAReferenceType.ts

@@ -8,6 +8,7 @@ export class UAReferenceType extends UABaseNode{
 
     constructor(options: UAReferenceTypeOptions) {
         super(options)
+        Object.assign(this, options);  
         this.isAbstract=options.isAbstract||false;
     }
 

+ 34 - 6
src/ua/UAVariable.ts

@@ -3,28 +3,56 @@ import { UABaseNode, type UABaseNodeOptions } from "./UABaseNode";
 import type { NamespaceTable } from "./NameSpaceTable";
 import type { IAddressSpace } from "./IAddressSpace";
 
-
-
 export class UAVariable extends UABaseNode {
-
+    public parentNodeId?: string;
+    public dataType!: string;
+    public valueRank!: number;
+    public arrayDimensions?: string;
+    public accessLevel!: number;
+    public userAccessLevel!: number;
+    public minimumSamplingInterval!: number;
+    public historizing!: Boolean;
 
     constructor(options: UAVariableNodeOptions) {
                     super(options);
+                    Object.assign(this, options);  
                     this.nodeClass="Variable";
     }
 
     static  fromXML(uaObject: any, addressSpace: IAddressSpace): UAVariable{
-        const bn=super.fromXML(uaObject, addressSpace)
+        const bn=super.fromXML(uaObject, addressSpace) as UAVariableNodeOptions
+        bn.parentNodeId=uaObject['ParentNodeId'];
+        bn.dataType=uaObject['@_DataType']||"i=24";
+        bn.valueRank=Number(uaObject['@_ValueRank']||-1);
+        bn.arrayDimensions=uaObject['@_ArrayDimensions'];
+        bn.accessLevel=Number(uaObject['@_AccessLevel']||1);
+        bn.userAccessLevel=Number(uaObject['@_UserAccessLevel']||1);
+        bn.minimumSamplingInterval=Number(uaObject['@_MinimumSamplingInterval']||0);
+        bn.historizing=Boolean(uaObject['@_Historizing']||false);
         return new UAVariable(bn as UABaseNodeOptions);
     }
 
     toXML(lnst:NamespaceTable, gnst:NamespaceTable): XMLElem {
         const elem=super.toXML(lnst, gnst);
+        elem.attr("ParentNodeId", this.parentNodeId);
+        elem.attr("DataType", this.dataType);
+        elem.attr("ValueRank", this.valueRank.toString());
+        elem.attr("ArrayDimensions", this.arrayDimensions);
+        elem.attr("AccessLevel", this.accessLevel.toString());
+        elem.attr("UserAccessLevel", this.userAccessLevel.toString());
+        elem.attr("MinimumSamplingInterval", this.minimumSamplingInterval.toString());
+        elem.attr("Historizing", this.historizing.toString());
         return elem;
     }
-    
 }
 
 export interface UAVariableNodeOptions extends UABaseNodeOptions{
-
+    parentNodeId?: string;
+    dataType?: string;
+    valueRank?: number;
+    arrayDimensions?: string;
+    accessLevel?: number;
+    userAccessLevel?: number;
+    minimumSamplingInterval?: number;
+    historizing?: Boolean;
 }

+ 3 - 2
src/ua/UAVariableType.ts

@@ -4,11 +4,12 @@ import { UABaseNode, type UABaseNodeOptions } from "./UABaseNode";
 import type { IAddressSpace } from "./IAddressSpace";
 
 export class UAVariableType extends UABaseNode{
-    public isAbstract: boolean;
+    public isAbstract: boolean=false;
     
     constructor(options: UAVariableTypeOptions) {
         super(options)
-        this.isAbstract=options.isAbstract||false;
+        Object.assign(this, options);  
+        this.nodeClass="VariableType";
     }
 
     static  fromXML(xmlObjType: any, addressSpace: IAddressSpace): UAVariableType{