Adding elements

All hierarchical elements that can be found in the TwinCAT Scope in the Solution Explorer can also be added in the code during the integration. A hierarchical element is structured in such a way that it possesses a "SubMember" list, through which it is possible to iterate. Further objects can be added with "AddMember".

If the new object is not added to an object located directly above it, then everything is re-created by the adding object until the object to be added can be integrated into the hierarchy. However, care must be taken that a YT chart is always created as the standard chart type.

The fundamental hierarchy in the scope looks like this:

ScopeProject

╚╦ DataPool

║╚ Acquisition

╠╦ Chart

║╚╦ AxisGroup

║   ╠╦ MarkerContainer

║   ║╚ Marker

║   ╠╦ Axes

║   ╚╦ Channels

║      ╚ AcquisitionInterpreter

… further charts

Charts:

The chart is the environment, in which the graph with the coordinate system appears. The chart thus represents the base frame and must be created first.

private void btnAddChart_Click(object sender, EventArgs e)
{
  YTChart chart = new YTChart();
  scopeProjectPanel.ScopeProject.AddMember(chart);
  chart.SubMember.OfType<ChartStyle>().First().ToolTipEnabled = true;
}

Axes:

The AxisGroup contains firstly the axes, which ensure the correct scaling of the values, and secondly the channels that are displayed in the chart.

If the AxisGroup is now added to the chart, the axis objects are created automatically.

private void btnAddAxis_Click(object sender, EventArgs e)
{
  if (scopeProjectPanel.ScopeProject.SubMember.OfType<Chart>().Count() == 0)
  {
    MessageBox.Show(this, "Please create a chart first!", "No chart connected!",
      MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  }
  else
  {
    scopeProjectPanel.ScopeProject.SubMember.OfType<Chart>().First().AddMember(new AxisGroup());
  }
}

Channels:

The channel contains all the information on the data that are recorded in the Scope and is attached under the axis group in which these values are to be shown.

private void btnAddChannel_Click(object sender, EventArgs e)
{
  Channel channel = new Channel();
  if (scopeProjectPanel.ScopeProject.SubMember.OfType<Chart>().Count() == 0)
  {
    MessageBox.Show(this, "Please create a chart first!", "No chart connected!",
      MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  }
  else if (scopeProjectPanel.ScopeProject.SubMember.OfType<Chart>().First().SubMember.OfType<AxisGroup>().Count() == 0)
  {
    MessageBox.Show(this, "Please create a axis first!", "No axis connected!",
      MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  }
  else
  {
    scopeProjectPanel.ScopeProject.SubMember.OfType<Chart>().First().SubMember.OfType<AxisGroup>().First().AddMember(channel);
    ChangeChannelSettings(channel);
    SetAcquisitions(channel);
  }
}