Click or drag to resize

AutoAttribute Class

Specifies the Auto attribute for a tag (primitive value type), or a struct or class instance.
Inheritance Hierarchy
SystemObject
  SystemAttribute
    Demo3D.PLC.Rockwell.Emulator.ModuleEmulatorsAutoAttribute

Namespace:  Demo3D.PLC.Rockwell.Emulator.ModuleEmulators
Assembly:  PLC (in PLC.dll) Version: 18.03.00
Syntax
C#
public sealed class AutoAttribute : Attribute

The AutoAttribute type exposes the following members.

Constructors
  NameDescription
Public methodAutoAttribute
Initializes a new instance of the AutoAttribute class
Top
Remarks

Properties or fields with this attribute are candidates for automatic binding.

If the type of the field is ModuleEmulator then the field is assigned a reference to the ModuleEmulator.
If the type is the user script module emulator type (that was passed in to the ModuleEmulator.Install method) then a reference to the user module emulator object is assigned to the field.

class MyDigitalModule {
    class Channel {
        [Auto] MyDigitalModule myModule;           // assigned the instance of this MyDigitalModule
    }

    [Auto] ModuleEmulator moduleEmulator;          // assigned the associated ModuleEmulator instance
    [Auto] Channel        Ch00;                    // automatically instantiated
}

Other fields (other than module emulator references) marked with [Auto] will be auto-instatiated if they contain a null reference after their class constructor has returned. In the example above Ch00 is not assigned a value by the MyDigitalModule constructor, and therefore [Auto] will automatically instantiate a Channel and assign the reference to Ch00.

When a field is auto-instantiated, a suitable constructor is searched for. Constructor parameters can include

public Channel(ModuleEmulator moduleEmulator,  // the associated ModuleEmulator instance
               MyDigitalModule myModule,       // the instance of this MyDigitalModule
               int channelId) {                // the index of this channel in a channel array
}
The constructor can have any (or none) of these parameters, and in any order. The 'int' parameter is only valid if the outer class is being [Auto] instantiated as an array. Eg:
[Auto, TagName(ArrayWidth = 16, Name = "Ch{i:00}")]
protected readonly Channel[] channels = new Channel[16];
If there's more than one constructor, then the first acceptable constructor is used.

Order of instantiation of fields in the module emulator is well defined. Instantiation is performed strictly in the order in which [Auto] fields are encountered. If a field is itself an [Auto] class field, then its sub-properties are traversed before continuing to the next field. (Ie depth-first.) Instances of SomeLogic (in the example below) are auto-instantiated. Their order of instantiation is indicated in the example.

class MyDigitalModule {
    class SomeLogic { }

    class ChannelBaseClass {
        [Auto] SomeLogic logic1;                   // instantiated in the order they appear in the script
        [Auto] SomeLogic logic2;
    }

    class Channel : ChannelBaseClass {             // ChannelBaseClass fields instantiated first
        [Auto] SomeLogic logic3;
        [Auto] SomeLogic logic4;
    }

    [Auto] Channel Ch00;
}

By default, the order of execution of events (ComputeInputs, ProcessOutputs, etc) follows the same order as the order of instantiation. This can be overridden using the ExecutionOrderAttribute.

See Also