Getting Started With C#
Add Terminals to the Station
In this example, a Beckhoff IO system consisting of a CX8190(PLC), EL1809(digital inputs terminal) and EL3024(current inputs terminal) is added to a station. From each terminal one input is added to the station. The current input is added a sensor to scale the current (4..20mA) to a pressure in bar.
internal class StationModule : InitializableCompositeModule
{
private void AddBeckhoffIOSystem()
{
var master = new EthercatAdsIOMasterModule("AdsMaster");
// First, add a plc terminal (e. g. EK1200 for a CX8090 plc) or a bus coupler (e. g. EK1100)
// and then the terminals in the same order as in your TwinCat 3 project.
master.AddTerminal(new EK1200(), "+S1-30K12_1");
var digitalInputTerminal = master.AddTerminal(new EL1809(), "+S1-30K12_2");
var currentInputTerminal = master.AddTerminal(new EL3024(), "+S1-30K12_3");
// Select inputs of the digital input terminal
// and set a LisRT module name.
var di = digitalInputTerminal.Inputs[0]; // index 0 = channel 1
di.Name = "Din";
var ci = currentInputTerminal.Inputs[0];
ci.Name = "Ain";
// Setting up an sensor changes the scaling of the analog input.
// Not required but the common use.
ci.Sensor = new PressureSensor();
SubModules.Add(master);
SubModules.Add(di);
SubModules.Add(ci);
}
}
internal class PressureSensor : ISensor
{
public string Unit { get; set; } = "bar";
public Range Range { get; set; } = new Range(0, 10);
public double Scale(double input) => (input - 4.0) * 10.0 / 16.0;
}
Tip
The AnalogInputs (e. g. of EL3064 or EL3204) can be adjusted with a multi-point adjustment in their service window.