UAVariable.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { XMLElem } from "@/util/XmlElem";
  2. import { UABaseNode, type UABaseNodeOptions } from "./UABaseNode";
  3. import type { NamespaceTable } from "./NameSpaceTable";
  4. import type { IAddressSpace } from "./IAddressSpace";
  5. export class UAVariable extends UABaseNode {
  6. public parentNodeId?: string;
  7. public dataType!: string;
  8. public valueRank!: number;
  9. public arrayDimensions?: string;
  10. public accessLevel!: number;
  11. public userAccessLevel!: number;
  12. public minimumSamplingInterval!: number;
  13. public historizing!: Boolean;
  14. constructor(options: UAVariableNodeOptions) {
  15. super(options);
  16. Object.assign(this, options);
  17. this.nodeClass="UAVariable";
  18. }
  19. static fromXML(uaObject: any, addressSpace: IAddressSpace): UAVariable{
  20. const bn=super.fromXML(uaObject, addressSpace) as UAVariableNodeOptions
  21. bn.parentNodeId=uaObject['ParentNodeId'];
  22. bn.dataType=uaObject['@_DataType']||"i=24";
  23. bn.valueRank=Number(uaObject['@_ValueRank']||-1);
  24. bn.arrayDimensions=uaObject['@_ArrayDimensions'];
  25. bn.accessLevel=Number(uaObject['@_AccessLevel']||1);
  26. bn.userAccessLevel=Number(uaObject['@_UserAccessLevel']||1);
  27. bn.minimumSamplingInterval=Number(uaObject['@_MinimumSamplingInterval']||0);
  28. bn.historizing=Boolean(uaObject['@_Historizing']||false);
  29. return new UAVariable(bn as UABaseNodeOptions);
  30. }
  31. toXML(lnst:NamespaceTable, gnst:NamespaceTable): XMLElem {
  32. const elem=super.toXML(lnst, gnst);
  33. elem.name=this.nodeClass;
  34. elem.attr("ParentNodeId", this.parentNodeId);
  35. elem.attr("DataType", this.dataType);
  36. elem.attr("ValueRank", this.valueRank.toString());
  37. elem.attr("ArrayDimensions", this.arrayDimensions);
  38. elem.attr("AccessLevel", this.accessLevel.toString());
  39. elem.attr("UserAccessLevel", this.userAccessLevel.toString());
  40. elem.attr("MinimumSamplingInterval", this.minimumSamplingInterval.toString());
  41. elem.attr("Historizing", this.historizing.toString());
  42. return elem;
  43. }
  44. }
  45. export interface UAVariableNodeOptions extends UABaseNodeOptions{
  46. parentNodeId?: string;
  47. dataType?: string;
  48. valueRank?: number;
  49. arrayDimensions?: string;
  50. accessLevel?: number;
  51. userAccessLevel?: number;
  52. minimumSamplingInterval?: number;
  53. historizing?: Boolean;
  54. }