✨ Array

Array permet la création de tableaux.

      

import {Array_, Byte} from "@adclz/plcdatabuilder/types"
const MyArray = new Array_({InitialContent: Array.from({length: 1}, () => new Byte({}))})
const MyArray: Array_<Byte>
 

Array_ possède un tiret _ afin de ne pas écraser l'objet Array de javascript.
Faites attention lors que vous utilisez les 2 objets dans un programme.

🏗️ Constructeur

Array_.prototype.constructor = <T extends ArrayProperty>(Params: ArrayParameters<T>) => Array_

Params

Paramètres initiaux de construction d'un tableau.

interface ArrayParameters<T extends ArrayProperty> extends BaseTypeParameters {
    InitialContent: T[]
    Index1?: number
}

InitialContent

Type: Content

ArrayParameters.InitialContent = [ArrayProperty]
Un tableau a toujours besoin d'un contenu initial.
Même un tableau avec pour index Array[0..0] of Bool contient au moins un booléen.

InitialContent est le contenu initial qui va définir le type du tableau.
Les élèments que vous allez rajouter doivent respecter ce type.

  • Un Array of Struct si et seulement si la structure est défini dans la première itération.
  • Un Array of Udt est possible.

  • Un Array ne peut contenir un autre Array.
InitialContent définit le type du tableau.
      

import {Array_, Bool, Byte} from "@adclz/plcdatabuilder/types"
 
const MyArray = new Array_({InitialContent: Array.from({length: 1}, () => new Bool({}))})
const MyArray: Array_<Bool>
 
// ✔️
const MyBool = new Bool({})
MyArray.Content.push(MyBool)
 
// ️️❌
const MyByte = new Byte({})
MyArray.Content.push(MyByte)
Argument of type 'Byte' is not assignable to parameter of type 'Bool'. Types of property 'Type' are incompatible. Type 'PrimitivePlcTypes.Byte' is not assignable to type 'PrimitivePlcTypes.Bool'.2345Argument of type 'Byte' is not assignable to parameter of type 'Bool'. Types of property 'Type' are incompatible. Type 'PrimitivePlcTypes.Byte' is not assignable to type 'PrimitivePlcTypes.Bool'.
 

Index1

ArrayParameters.Index1 = number

Index de départ du tableau.
Par défaut ce paramètre est égal à 0.

      

import {Array_, Bool} from "@adclz/plcdatabuilder/types"
 
const MyArray = new Array_({InitialContent: Array.from({length: 1}, () => new Bool({})), Index1: 3})
const MyArray: Array_<Bool>
 

Ici la mise à 3 du paramètre Index1 retournera Array[3..4] of Bool;.

📜 Champs

Content

Array_.prototype.Content = [ArrayProperty]
type ArrayProperty = PrimitivePlcClass | UDTImplementation<StructProperties, string, number>| Struct<StructProperties>

Content vous permet de rajouter du contenu à votre tableau.

Le type de ce champ est défini depuis le constructeur via le paramètre InitialContent.

      

import {Array_, Bool} from "@adclz/plcdatabuilder/types"
 
const MyArray = new Array_({InitialContent: Array.from({length: 1}, () => new Bool({}))})
 
MyArray.Content.push(new Bool({}))
 

🧪 Méthodes

OverrideArrayName est utilisé en interne par DataBlock afin de générer le nom de la structure.

GetOffsets

Array_.prototype.GetOffsets = (OverrideArrayName?: string) => Map<string, number>

Position des champs du tableau en mémoire.

StringifyHeader

Array_.prototype.StringifyHeader = (OverrideArrayName?: string) => string[]

En-tête de la structure.

StringifyBody

Array_.prototype.StringifyBody = (OverrideArrayName?: string) => string[]

Corps de la structure avec les valeurs par défauts (si définies).

✨ Exemple

L'exemple suivant montre un bloc de données contenant un tableau avec 2 booléens.