How to: Get status of terminal connection


Topic:

Get status of terminal connection


Class hierarchy:

IPCsApplication IPCsDocument IPCsDrawing IPCsPage IPCsSymbol


Description:

A connectionpoint can have one of 3 different states, that are of type psIOStatusMainType .


Sourcecode:
[+] Delphi
uses DPSCAD_TLB;

Type
  TTermDataType = (td_ExtComp, td_ExtWireNo, td_ExtCable, td_ExtSignal, td_OutConn, td_InConn, td_InSignal, td_InCable, td_InWireNo, td_InComp, td_JumperLink);
var
  ListOfTerminals : IPCsList;
  i, p : integer;
  TermName : IPCsSymbol;
  ASymbols : IPCsSymbols;
  EmptyStr, TempStr : string;
begin
  {check if we're connected to Automation}
  if CheckConnection() then    // (See function here)
    begin
      {example #1 : using IPCsList}
      {create a IPCsList of all terminals in correct active project}
      ListOfTerminals := PCsApplication.ActiveDocument.Drawing.Lists.CreateTerminalList(EmptyStr);
      {runningt through each terminal}
      for i := 0 to ListOfTerminals.Count - 1 do
        begin
          {get symbol from IPCsList and put it in variable TermName (IPCsSymbol)
           by using an IPCsList-items GetDataSymbol-method}
          ListOfTerminals.Item[i].GetDataSymbol(integer(td_InConn),0,TermName,IndexTerm);
          {valid terminal and terminal have connections...}
          if ((TermName <> nil) and (TermName.Connections.Count > 0)) then
            begin
              TempStr := 'Terminalname=' + TermName.FullName + ' Connection=';
              for p := 0 to TermName.Connections.Count -1 do
                case TermName.Connections[p].IOStatus.MainType of
                  mt_None : ShowMessage(TempStr + IntToStr(p) + ' is ' +'None');
                  mt_Output : ShowMessage(TempStr + IntToStr(p) + ' is ' +'Output');
                  mt_Input : ShowMessage(TempStr + IntToStr(p) + ' is ' +'Input');
                end;
            end;
        end;
      {example #1 : end}


      {example #2 : using Symbols.Count}
      ASymbols := PCsApplication.ActiveDocument.ActivePage.Symbols;
      for i := 0 to ASymbols.Count -1 do
        begin
          TermName := ASymbols.Item[i];
          {valid terminal and terminal have connections...}
          if ((TermName <> nil) and (TermName.Connections.Count > 0)) then
            begin
              TempStr := 'Terminalname=' + TermName.FullName + ' Connection=';
              for p := 0 to TermName.Connections.Count -1 do
                case TermName.Connections[p].IOStatus.MainType of
                  mt_None : ShowMessage(TempStr + IntToStr(p) + ' is ' +'None');
                  mt_Output : ShowMessage(TempStr + IntToStr(p) + ' is ' +'Output');
                  mt_Input : ShowMessage(TempStr + IntToStr(p) + ' is ' +'Input');
                end;
            end;
        end;
      {example #2 : end}
    end;
end;

[+] Visual Basic
Dim ListOfTerminals As Dpscad.PCsList
Dim TermName As Dpscad.PCsSymbo
l Dim ASymbols As Dpscad.PCsSymbols
Const td_ExtComp As Integer = 0, td_ExtWireNo As Integer = 1, td_ExtCable As Integer = 2, td_ExtSignal As Integer = 3, td_OutConn As Integer = 4, td_InConn As Integer = 5, td_InSignal As Integer = 6
Const td_InCable As Integer = 7, td_InWireNo As Integer = 8, td_InComp As Integer = 9, td_JumperLink As Integer = 10
Dim IndexTerm As Integer
Dim EmptyStr As String = "", TempStr As String = ""

'check if we're connected to Automation
If CheckConnection() Then   // (See function here)
  'example #1 : using IPCsList

  'create a IPCsList of all terminals in correct active project
  ListOfTerminals = PCsApplication.ActiveDocument.Drawing.Lists.CreateTerminalList(EmptyStr)
  'running through each terminal
  For i As Integer = 0 To ListOfTerminals.Count - 1
    'get symbol from IPCsList and put it in variable TermName (IPCsSymbol)by using an IPCsList-items GetDataSymbol-method
    ListOfTerminals(i).GetDataSymbol(td_InComp, 0, TermName, IndexTerm)
    'valid terminal and terminal have connections...
    If TermName IsNot Nothing AndAlso TermName.Connections.Count > 0 Then
      TempStr = "Terminalname=" & TermName.FullName & " Connection="
      For p As Integer = 0 To TermName.Connections.Count - 1
        Select Case TermName.Connections(p).IOStatus.MainType
          Case Dpscad.psIOStatusMainType.mt_None
            MessageBox.Show(TempStr & p & " is None")
            Exit Select
          Case Dpscad.psIOStatusMainType.mt_Output
            MessageBox.Show(TempStr & p & " is Output")
            Exit Select
          Case Dpscad.psIOStatusMainType.mt_Input
            MessageBox.Show(TempStr & p & " is Input")
            Exit Select
          Case Else
            Exit Select
        End Select
      Next
    End If
  Next
  'example #1 : end

  'example #2 : using Symbols.Count
  ASymbols = PCsApplication.ActiveDocument.ActivePage.Symbols
  For i As Integer = 0 To ASymbols.Count - 1
    TermName = ASymbols(i)
    'valid terminal and terminal have connections...
    If TermName IsNot Nothing AndAlso TermName.Connections.Count > 0 Then
      TempStr = "Terminalname=" & TermName.FullName & " Connection="
      For p As Integer = 0 To TermName.Connections.Count - 1
        Select Case TermName.Connections(p).IOStatus.MainType
          Case Dpscad.psIOStatusMainType.mt_None
            MessageBox.Show(TempStr & p & " is None")
            Exit Select
          Case Dpscad.psIOStatusMainType.mt_Output
            MessageBox.Show(TempStr & p & " is Output")
            Exit Select
          Case Dpscad.psIOStatusMainType.mt_Input
            MessageBox.Show(TempStr & p & " is Input")
            Exit Select
          Case Else
            Exit Select
        End Select
      Next
    End If
    'example #2 : end
  Next
End If

[+] C#
Dpscad.PCsList ListOfTerminals;
Dpscad.PCsSymbol TermName;
Dpscad.PCsSymbols ASymbols;
const int td_ExtComp = 0, td_ExtWireNo = 1, td_ExtCable = 2, td_ExtSignal = 3, td_OutConn = 4, td_InConn = 5, td_InSignal = 6;
const int td_InCable = 7, td_InWireNo = 8, td_InComp = 9, td_JumperLink = 10;
int IndexTerm;
string EmptyStr = "", TempStr = "";

/*check if we're connected to Automation*/
if (CheckConnection())   // (See function here)
{
  /*example #1 : using IPCsList*/
  /*create a IPCsList of all terminals in correct active project*/
  ListOfTerminals = PCsApplication.ActiveDocument.Drawing.Lists.CreateTerminalList(EmptyStr);
  /*running through each terminal*/
  for (int i = 0; i < ListOfTerminals.Count; i++)
  {
    /*get symbol from IPCsList and put it in variable TermName (IPCsSymbol)by using an IPCsList-items GetDataSymbol-method*/
    ListOfTerminals[i].GetDataSymbol(td_InComp, 0, out TermName, out IndexTerm);
    /*valid terminal and terminal have connections...*/
    if (TermName != null && TermName.Connections.Count > 0)
    {
      TempStr = "Terminalname=" + TermName.FullName + " Connection=";
      for (int p = 0; p < TermName.Connections.Count; p++)
      {
        switch (TermName.Connections[p].IOStatus.MainType)
        {
          case Dpscad.psIOStatusMainType.mt_None:
            MessageBox.Show(TempStr + p + " is None");
            break;
          case Dpscad.psIOStatusMainType.mt_Output:
            MessageBox.Show(TempStr + p + " is Output");
            break;
          case Dpscad.psIOStatusMainType.mt_Input:
            MessageBox.Show(TempStr + p + " is Input");
            break;
          default:
            break;
        }
      }
    }

  }
  /*example #1 : end*/

  /*example #2 : using Symbols.Count*/
  ASymbols = PCsApplication.ActiveDocument.ActivePage.Symbols;
  for (int i = 0; i < ASymbols.Count; i++)
  {
    TermName = ASymbols[i];
    /*valid terminal and terminal have connections...*/
    if (TermName != null && TermName.Connections.Count > 0)
    {
      TempStr = "Terminalname=" + TermName.FullName + " Connection=";
      for (int p = 0; p < TermName.Connections.Count; p++)
      {
        switch (TermName.Connections[p].IOStatus.MainType)
        {
          case Dpscad.psIOStatusMainType.mt_None:
            MessageBox.Show(TempStr + p + " is None");
            break;
          case Dpscad.psIOStatusMainType.mt_Output:
            MessageBox.Show(TempStr + p + " is Output");
            break;
          case Dpscad.psIOStatusMainType.mt_Input:
            MessageBox.Show(TempStr + p + " is Input");
            break;
          default:
            break;
        }
      }
    }
  }
  /*example #2 : end*/
}