✨ 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 ({}))})
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]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
ArrayofStructsi et seulement si la structure est défini dans la première itération. - Un
ArrayofUdtest possible.
- Un
Arrayne peut contenir un autreArray.
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 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 = numberIndex 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})
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.