General MATLAB .NET Interfacing

In this chapter, a general functionality is elaborated, which is needed to interface with PMP.

Operations on objects

Methods

Use methods() to obtain the methods of an object or methods(<object>, '-full') to include the full arguments and return values. For example, obtain the methods of a controller TopController named topController:

>> methods(topController)

Methods for class Pmp.TopController:

ApplyModel                 Reboot
ApplyModelFromFile         ReserveAcquisition
CreateAxisControl          ReserveSnapshot
CreateAxisControlGroup     Run
CreateController           SaveConfiguration
CreateControllerFromFile   SaveConfigurationToFile
CreateMatrix               SetKeepAliveSettings
CreateProcessingBlock      Stop
CreateTemplate             SubscribeConnection
Dispose                    SubscribeConnectionLost
Equals                     SubscribeEvents
Force                      SubscribeResponses
GetHashcode                SubscribeStateChange
GetKeepAliveSettings       ToString
GetType                    TopController
LoadConfiguration          WaitState
LoadConfigurationFromFile

Methods of Pmp.TopController inherited from handle.

Note

The generic method has some limitations. See https://www.mathworks.com/help/matlab/matlab_external/display-net-generic-methods-using-reflection.html for further information.

Properties

The function properties() can be used to list all properties of an object, e.g. topController:

>> properties(topController)

Properties for class Pmp.TopController:

State
Time
Type
Actuators
Address
AxisControlGroups
AxisControls
Controllers
Filters
HardwareInterfaceProductNumber
HardwareProductNumber
HardwareSerialNumber
Id
IsBackupRunning
IsCompatible
IsConnected
IsRebootRequired
IsSimulated
Latches
LogBuffer
Matrices
Sensors
Signals
Updatables
ProcessingBlocks
Templates
Parent
DefaultName
Name
FullName
Children
Events
SystemList

Enumeration

To display enumeration members use enumeration(), for example, to show all available axis control states:

>> enumeration(Pmp.AxisControlState);

Enumeration members for class 'Pmp.AxisControlState':

NotReadyToSwitchOn
SwitchOnDisabled
ReadyToSwitchOn
SwitchedOn
OperationEnabled
QuickStopActive
FaultReactionActive
Fault

Dictionaries

If the key of a value in a dictionary is known, the value can be obtained via the method Item(). For example, to obtain the top-controller with the name Arcas 5EG-1 from the Controllers dictionary, use:

>> topController = system.Controllers.Item('Arcas 5EG-1');

The keys of a .NET dictionary are not directly visible in MATLAB. To see the complete content of a dictionary it can be converted to a MATLAB cell array. This can be done by iterating over all entries.

For example, obtaining the sub-controllers form the above Arcas 5EG-1 top-controller with the Controllers dictionary:

>> string(ToCell(topController.Controllers.Keys))

ans =

  1×1 string array

    "Arcas FPGA"

The ToCell() can be used to iterate over the dictionary key:

  • The iterator is obtained via GetEnumerator().

  • MoveNext() selects the next index and returns true if the next index exists.

  • If the key exists the value can be obtained by calling Current().

1
2
3
4
5
6
7
function outputCell = ToCell(enumerableObject)
outputCell = {};
enumerator = enumerableObject.GetEnumerator();

while enumerator.MoveNext()
  outputCell{end +1} = enumerator.Current;
end

List and Tuple

PMP requires lists or tuples as inputs for some methods. These generic .NET objects can be created via the function NET.createGeneric(). A List can be made from a MATLAB vector via the following function:

1
2
3
4
5
6
function list = CreateList( type, entries)
  list = NET.createGeneric('System.Collections.Generic.List', {type});
  for i=1:length(entries)
      list.Add(entries{i});
  end
end

Tuples, unlike lists, are immutable. A Tuple {entry1, entry2} of type {type1, type2} can be created via the following command:

1
2
3
function tuple = CreateTuple( type1, type2, entry1, entry2)
  tuple = NET.createGeneric('System.Tuple', {type1, type2}, entry1, entry2);
end