2021.1.1560.3 Logic Component
Overview
A Logic Component enables the user to connect a Monobehaviour to an external PLC using a Logic Simulator.
A Logic Component consists of both component specific settings and general settings. For details of component specific settings (Properties & PLC outputs), look at the documentation of that specific Logic Component.
General Settings
PLC Settings
In the PLC Settings panel you can manage the settings on how you wish your component to connect to a PLC.
Signal Naming Settings |
|
---|---|
Signal Naming Rule Overrides | Allows you to customize the names of your Input/Output signals based on component instance settings |
Size | The number of different communication channels you wish to use for this component |
$ALL |
|
Rule Target | Describes the subset of signals this rule applies to. $ALL $INPUT $OUTPUT $VARIABLE [CUSTOM] |
Sim Address Path Format | The formatting for the simulation address path. Variables wrapped in double curly brackets are replaced on component instantiation |
Plc Address Path Format | The formatting for the PLC address path. Variables wrapped in double curly brackets are replaced on component instantiation |
Sim Path Separator | The separator character used in the hierarchical path the simulation naming |
Plc Path Separator | The separator character used in the hierarchical path for PLC addressing |
Instance Name Rule | The pattern used to replace |
Tracking Signals
Your Signals are tracked in the Prelogic Component UI
Coding guide
You can create a PrelogicComponent by creating a new C# script and inheriting from PrelogicComponent.
Example PreLogicComponent
using System.Collections.Generic;
using u040.prespective.prelogic;
using u040.prespective.prelogic.component;
using u040.prespective.prelogic.signal;
using UnityEngine;
public class OPCTestComponent : PreLogicComponent
{
}
You are then forced to create an override for the SignalDefinitons
Basic Example Signal Definitons
using System.Collections.Generic;
using u040.prespective.prelogic;
using u040.prespective.prelogic.component;
using u040.prespective.prelogic.signal;
public class OPCTestComponent : PreLogicComponent
{
public override List<SignalDefinition> SignalDefinitions =>
new List<SignalDefinition>
{
new SignalDefinition("inputReal", PLCSignalDirection.INPUT, SupportedSignalType.REAL64,
_baseValue: (double) 100),
new SignalDefinition("outputUint32", PLCSignalDirection.OUTPUT, SupportedSignalType.UINT32)
};
}
Callback Example
To get callbacks once a signal changes you can include a delegate in the constructor of the signal definition.
using System;
using System.Collections.Generic;
using u040.prespective.prelogic;
using u040.prespective.prelogic.component;
using u040.prespective.prelogic.signal;
using UnityEngine;
public class OPCTestComponent : PreLogicComponent
{
public override List<SignalDefinition> SignalDefinitions =>
new List<SignalDefinition>
{
new SignalDefinition("inputReal", PLCSignalDirection.INPUT, SupportedSignalType.REAL64,
_baseValue: (double) 100),
new SignalDefinition("outputUint32", PLCSignalDirection.OUTPUT, SupportedSignalType.UINT32, _onValueChange: OnIOChange)
};
private void OnIOChange(SignalInstance __inst, object __newvalue, DateTime __newchangetime, object __oldvalue, DateTime __oldchangetime)
{
//this logs the name and value of outputUint32
Debug.Log(__inst.plcAddress);
Debug.Log(__newvalue);
}
}
Reading writing Signals
Prespective Documentation