FB_CMA_Source

This function block writes data from an external PLC data buffer into a MultiArray buffer.

It accumulates input data continuously, until the maximum size of the MultiArray is reached. Once the MultiArray is full, it is transferred to the target analysis ID.

An instance of FB_CMA_Source must not be used as target for any other analysis function block. It offers only source functionality.

A time series collection can be interrupted in the event of an error. Lost signal data can lead to an unexpected result of the analysis chain, depending on the configuration of the algorithms.

Inputs and outputs

The output buffers correspond to the following definition (Shape). The variable parameters are part of the function block input stInitPars.

MultiArray in the

Element type

Dimensions

Dimensional variables

output stream

eTypeCode

nDims

aDimSizes

VAR_INPUT
    stInitPars       : ST_MA_MultiArray_InitPars;       // init parameter
    nOwnID           : UDINT;                           // ID for this FB instance
    aDestIDs         : ARRAY[1..cCMA_MaxDest] OF UDINT; // IDs of destinations for output
    nResultBuffers   : UDINT := 4;                      // number of MultiArrays which should be initialized for results (0 for no initialization)
    tTransferTimeout : LTIME := LTIME#40US;             // timeout checking off during access to inter-task FIFOs
END_VAR

Input parameters

The input parameters of this function block represent initialization parameters and must already be assigned in the declaration of the FB instance! (Alternatively: Init() method). They may only be assigned once. A change at runtime is not possible.

Output parameters

VAR_OUTPUT
    bError         : BOOL;                           // TRUE if an error occurs. Reset by next method call.
    hrErrorCode    : HRESULT;                        // '< 0' = error; '> 0' = info; '0' = no error/info
    ipErrorMessage : I_TcMessage := fbErrorMessage;  // Shows detailed information about occurred errors, warnings and more.
    nCntResults    : ULINT;                          // Counts outgoing results (MultiArrays were calculated and sent to transfer tray).
END_VAR
  • bError: The output is TRUE if an error occurs.
  • hrErrorCode: If an error occurs, a corresponding error code of the type HRESULT is output. Possible values are described in the List of error codes.
  • ipErrorMessage: Contains more detailed information on the current return value. Refer here to the section Error description and information. This special interface pointer is internally secured so that it is always valid/assigned.

Properties

The following properties can optionally be used to specify the timestamp of the input values associated with the next input call. If the properties are not set, a current timestamp and a typical time difference between two input values are automatically determined internally.
At FB_CMA_Sink, the timespan and time stamp of the input values of the analysis chain are assigned to the result of the analysis.

Name

Type

Access

Description

nTimestamp

ULINT
[T_DCTIME64; 1ns steps since 1.1.2000]

Set

Specification of the timestamp associated with the oldest value, which is transferred with the next input call.
(example: StartTimeNextLatch -CycleTime)

tSamplePeriod

LTIME

Set

Specification of the time difference between two input values.
(example: CycleTime / cOversamples).
This specification is only necessary once, as it is a constant value.

Methods

Input1D():

Writes data from an external one-dimensional data buffer into a MultiArray. This method must be called whenever new input samples are available, usually cyclically.

  • Return value: If an error occurs, a corresponding error code of the type HRESULT is output. Possible values are described in the List of error codes.
METHOD Input1D : HRESULT
VAR_INPUT
    pDataIn       : POINTER TO BYTE;      // address of data buffer (e.g. oversampling data) as one-dimensional array
    nDataInSize   : UDINT;                // size of data buffer in bytes
    eElementType  : E_MA_ElementTypeCode;
    nWorkDim      : UDINT;                // It designates the dimension in the multi array being processed.
    pStartIndex   : POINTER TO UDINT;     (* optional: default:0->internally handled; It designates the index of the first MultiArray element to be copied.
                                             If allocated it must point to a onedimensional array of UDINT with so many elements as dimensions of the MultiArray.
                                             Upon successful completion of the copy, corresponding StartIndex is incremented by the number of copied elements. *)
    nOptionPars   : DWORD;                // option mask
END_VAR
VAR_OUTPUT
    bNewResult    : BOOL;                 // TRUE every time when outgoing MultiArray was calculated and sent to transfer tray.
    bError        : BOOL;                 // TRUE if an error occurs.
    hrErrorCode   : HRESULT;              // '< 0' = error; '> 0' = info; '0' = no error/info
END_VAR
  • pDataIn: The data buffer must contain the data from all channels.
  • eElementType: This input is of the type E_MA_ElementTypeCode. The element type of the specified MultiArray buffer (initialization parameters) must match the element type of the specified external data buffer.
  • nWorkDim: Defines the dimension in which the data are accumulated. In general the MultiArray is also one-dimensional and nWorkDim := 0, but the MultiArray can also have additional dimensions, which may not then be processed, however.
  • pStartIndex: This is an optional parameter, which can be useful if the MultiArray has more than one dimension. Specifies the index of the first MultiArray element to be copied. If assigned, it must point to a one-dimensional array of UDINT that has as many elements as the MultiArray has dimensions. After a successful copy process, the corresponding Start Index is incremented by the number of copied elements.
  • bError: This output is TRUE if an error occurs.
  • hrErrorCode: If an error occurs, then a descriptive error code of the type HRESULT is displayed. Possible values are described in the List of error codes. This output is identical to the return value of the method.

Input1DStd():

Writes data from an external one-dimensional data buffer into a MultiArray. This method must be called whenever new input samples are available, usually cyclically.

This method uses default values for the parameters nWorkDim := 0 and pStartIndex := 0.

  • Return value: If an error occurs, a corresponding error code of the type HRESULT is output. Possible values are described in the List of error codes.
METHOD Input1DStd : HRESULT
VAR_INPUT
    pDataIn       : POINTER TO BYTE;      // address of data buffer (e.g. oversampling data) as one-dimensional array
    nDataInSize   : UDINT;                // size of data buffer in bytes
    eElementType  : E_MA_ElementTypeCode;
    nOptionPars   : DWORD;                // option mask
END_VAR
VAR_OUTPUT
    bNewResult    : BOOL;                 // TRUE every time when outgoing MultiArray was calculated and sent to transfer tray.
    bError        : BOOL;                 // TRUE if an error occurs.
    hrErrorCode   : HRESULT;              // '< 0' = error; '> 0' = info; '0' = no error/info
END_VAR
  • pDataIn: The data buffer must contain the data from all channels.
  • eElementType: This input is of the type E_MA_ElementTypeCode. The element type of the specified MultiArray buffer (initialization parameters) must match the element type of the specified external data buffer.
  • bError: This output is TRUE if an error occurs.
  • hrErrorCode: If an error occurs, then a descriptive error code of the type HRESULT is displayed. Possible values are described in the List of error codes. This output is identical to the return value of the method.

Input2D():

Writes data from an external two-dimensional data buffer into a MultiArray. This method must be called whenever new input samples are available, usually cyclically.

  • Return value: If an error occurs, a corresponding error code of the type HRESULT is output. Possible values are described in the List of error codes.
METHOD Input2D : HRESULT
VAR_INPUT
    pDataIn       : POINTER TO BYTE;      // address of data buffer (e.g. oversampling data) as twodimensional array (e.g.[1..channels,1..oversamples] )
    nDataInSize   : UDINT;                // size of data buffer in bytes
    eElementType  : E_MA_ElementTypeCode;
    nWorkDim0     : UDINT:=0;             // It designates the first dimension in the MultiArray being processed. (e.g. 1..channels)
    nWorkDim1     : UDINT:=1;             // It designates the second dimension in the MultiArray being processed.
    pStartIndex   : POINTER TO UDINT;     (* optional: default:0-> internally handled; It designates the index of the first MultiArray element to be copied.
                                             If allocated it must point to a onedimensional array of UDINT with so many elements as dimensions of the MultiArray.
                                             Upon successful completion of the copy, corresponding StartIndex is incremented by the number of copied elements. *)
    nOptionPars   : DWORD;                // option mask
END_VAR
VAR_OUTPUT
    bNewResult    : BOOL;                 // TRUE every time when outgoing MultiArray was calculated and sent to transfer tray.
    bError        : BOOL;                 // TRUE if an error occurs.
    hrErrorCode   : HRESULT;              // '< 0' = error; '> 0' = info; '0' = no error/info
END_VAR
  • pDataIn: The data buffer must contain the data from all channels.
  • eElementType: This input is of the type E_MA_ElementTypeCode. The element type of the specified MultiArray buffer (initialization parameters) must match the element type of the specified external data buffer.
  • nWorkDim0: Defines the dimension that matches the number of channels. In general the MultiArray is also two-dimensional and nWorkDim0 := 0, but the MultiArray can also have additional dimensions, which may not then be processed, however.
    E.g.: If the first index of the specified data buffer stands for the channels, while the second dimension of the MultiArray counts the channels, then set nWorkDim0:=1.
  • nWorkDim1: Defines the dimension in which the data are accumulated. In general the MultiArray is also two-dimensional and nWorkDim1 := 1, but the MultiArray can also have additional dimensions, which may not then be processed, however.
    E.g.: If the second index of the specified data buffer stands for the accumulated data, while the first dimension of the MultiArray collects the data, then set nWorkDim1 := 0.
  • pStartIndex: This is an optional parameter, which can be useful if the MultiArray has more than two dimensions. Specifies the index of the first MultiArray element to be copied. If assigned, it must point to a one-dimensional array of UDINT that has as many elements as the MultiArray has dimensions. After a successful copy process, the corresponding Start Index is incremented by the number of copied elements.
  • bError: This output is TRUE if an error occurs.
  • hrErrorCode: If an error occurs, then a descriptive error code of the type HRESULT is displayed. Possible values are described in the List of error codes. This output is identical to the return value of the method.

Input2DStd():

Writes data from an external two-dimensional data buffer into a MultiArray. This method must be called whenever new input samples are available, usually cyclically.

This method uses default values for the parameters nWorkDim0 := 0, nWorkDim1 := 1 and pStartIndex := 0.

  • Return value: If an error occurs, a corresponding error code of the type HRESULT is output. Possible values are described in the List of error codes.
METHOD Input2DStd : HRESULT
VAR_INPUT
    pDataIn       : POINTER TO BYTE;      // address of data buffer (e.g. oversampling data) as twodimensional array (e.g.[1..channels,1..oversamples] )
    nDataInSize   : UDINT;                // size of data buffer in bytes
    eElementType  : E_MA_ElementTypeCode;
    nOptionPars   : DWORD;                // option mask
END_VAR
VAR_OUTPUT
    bNewResult    : BOOL;                 // TRUE every time when outgoing MultiArray was calculated and sent to transfer tray.
    bError        : BOOL;                 // TRUE if an error occurs.
    hrErrorCode   : HRESULT;              // '< 0' = error; '> 0' = info; '0' = no error/info
END_VAR
  • pDataIn: The data buffer must contain the data from all channels.
  • eElementType: This input is of the type E_MA_ElementTypeCode. The element type of the specified MultiArray buffer (initialization parameters) must match the element type of the specified external data buffer.
  • bError: This output is TRUE if an error occurs.
  • hrErrorCode: If an error occurs, then a descriptive error code of the type HRESULT is displayed. Possible values are described in the List of error codes. This output is identical to the return value of the method.

Input3D():

Writes data from an external three-dimensional data buffer into a MultiArray. This method must be called whenever new input samples are available, usually cyclically.

  • Return value: If an error occurs, a corresponding error code of the type HRESULT is output. Possible values are described in the List of error codes.
METHOD Input2D : HRESULT
VAR_INPUT
    pDataIn       : POINTER TO BYTE;      // address of data buffer (e.g. oversampling data) as twodimensional array (e.g.[1..channels,1..oversamples] )
    nDataInSize   : UDINT;                // size of data buffer in bytes
    eElementType  : E_MA_ElementTypeCode;
    nWorkDim0     : UDINT:=0;             // It designates the first dimension in the MultiArray being processed. (e.g. 1..channels)
    nWorkDim1     : UDINT:=1;             // It designates the second dimension in the MultiArray being processed.
    nWorkDim2     : UDINT:=2;             // It designates the third dimension in the MultiArray being processed.
    pStartIndex   : POINTER TO UDINT;     (* optional: default:0-> internally handled; It designates the index of the first MultiArray element to be copied.
                                             If allocated it must point to a onedimensional array of UDINT with so many elements as dimensions of the MultiArray.
                                             Upon successful completion of the copy, corresponding StartIndex is incremented by the number of copied elements. *)
    nOptionPars   : DWORD;                // option mask
END_VAR
VAR_OUTPUT
    bNewResult    : BOOL;                 // TRUE every time when outgoing MultiArray was calculated and sent to transfer tray.
    bError        : BOOL;                 // TRUE if an error occurs.
    hrErrorCode   : HRESULT;              // '< 0' = error; '> 0' = info; '0' = no error/info
END_VAR
  • pDataIn: The data buffer must contain the data from all channels.
  • eElementType: This input is of the type E_MA_ElementTypeCode. The element type of the specified MultiArray buffer (initialization parameters) must match the element type of the specified external data buffer.
  • nWorkDim0: Defines the dimension that matches the number of channels. In general the MultiArray is also two-dimensional and nWorkDim0 := 0, but the MultiArray can also have additional dimensions, which may not then be processed, however.
    E.g.: If the first index of the specified data buffer stands for the channels, while the second dimension of the MultiArray counts the channels, then set nWorkDim0 := 1.
  • nWorkDim1: Defines the dimension that corresponds to the number of subchannels. In general, the MultiArray is also three-dimensional and nWorkDim0 := 0 and nWorkDim1 := 1, but the MultiArray may also have additional dimensions, which may not then be processed, however.
    E.g.: If the second index of the specified data buffer stands for the subchannels, while the third dimension of the MultiArray counts the subchannels, then set nWorkDim1 := 2.
  • nWorkDim2: Defines the dimension in which the data are accumulated. In general the MultiArray is also two-dimensional and nWorkDim1 := 1, but the MultiArray can also have additional dimensions, which may not then be processed, however.
    E.g.: If the second index of the specified data buffer stands for the accumulated data, while the first dimension of the MultiArray collects the data, then set nWorkDim1 := 0.
  • pStartIndex: This is an optional parameter, which can be useful if the MultiArray has more than two dimensions. Specifies the index of the first MultiArray element to be copied. If assigned, it must point to a one-dimensional array of UDINT that has as many elements as the MultiArray has dimensions. After a successful copy process, the corresponding Start Index is incremented by the number of copied elements.
  • bError: This output is TRUE if an error occurs.

hrErrorCode: If an error occurs, then a descriptive error code of the type HRESULT is displayed. Possible values are described in the List of error codes. This output is identical to the return value of the method.

Input3DStd():

Writes data from an external three-dimensional data buffer into a MultiArray. This method must be called whenever new input samples are available, usually cyclically.

This method uses default values for the parameters nWorkDim0 := 0, nWorkDim1 := 1, nWorkDim2 := 2 and pStartIndex := 0.

  • Return value: If an error occurs, a corresponding error code of the type HRESULT is output. Possible values are described in the List of error codes.
METHOD Input2DStd : HRESULT
VAR_INPUT
    pDataIn       : POINTER TO BYTE;      // address of data buffer (e.g. oversampling data) as twodimensional array (e.g.[1..channels,1..oversamples] )
    nDataInSize   : UDINT;                // size of data buffer in bytes
    eElementType  : E_MA_ElementTypeCode;
    nOptionPars   : DWORD;                // option mask
END_VAR
VAR_OUTPUT
    bNewResult    : BOOL;                 // TRUE every time when outgoing MultiArray was calculated and sent to transfer tray.
    bError        : BOOL;                      // TRUE if an error occurs.
    hrErrorCode   : HRESULT;              // '< 0' = error; '> 0' = info; '0' = no error/info
END_VAR
  • pDataIn: The data buffer must contain the data from all channels and subchannels.
  • eElementType: This input is of the type E_MA_ElementTypeCode. The element type of the specified MultiArray buffer (initialization parameters) must match the element type of the specified external data buffer.
  • bError: This output is TRUE if an error occurs.

hrErrorCode: If an error occurs, then a descriptive error code of the type HRESULT is displayed. Possible values are described in the List of error codes. This output is identical to the return value of the method.

METHOD Init : HRESULT
VAR_INPUT
    stInitPars     : ST_MA_MultiArray_InitPars;       // init parameter
    nOwnID         : UDINT;                           // ID for this FB instance
    aDestIDs       : ARRAY[1..cCMA_MaxDest] OF UDINT; // IDs of destinations for output
    nResultBuffers : UDINT := 4;                      // number of MultiArrays which should be initialized for results (0 for no initialization)
END_VAR

Init():

This method is not usually necessary in a Condition Monitoring application. It offers an alternative to the function block initialization. The Init() method may only be called during the initialization phase of the PLC. It cannot be used at runtime. You are referred to the use of an FB_init method or the attribute 'call_after_init' (see TwinCAT PLC reference). In addition, this facilitates the function block encapsulation.

The input parameters of the function block instance may not be assigned in the declaration if the initialization is to take place using the Init() method.

  • Return value: If an error occurs, a corresponding error code of the type HRESULT is output. Possible values are described in the List of error codes.

ResetData():

The method deletes all data sets that have already been added so that the current output buffer (MultiArray) can be filled from the start again. If external indices are to be used when filling (pStartIndex parameter), they must be explicitly reset.

  • Return value: If an error occurs, a corresponding error code of the type HRESULT is output. Possible values are described in the list of error codes.
METHOD ResetData : HRESULT
VAR_INPUT
END_VAR

ResetAnalysisChain():

Calling this method causes an automatic reset of all algorithms in the full analysis chain. Internally, a ResetData() is carried out each time before accepting the new data set. Consequently, this also implies a ResetData() on FB_CMA_Source.

If the analysis chain is only to be active for a certain period, this method offers the option to reset all algorithms before the next execution.

Errors can occur when calling an input method and cause interruptions in the time series collection. If the following algorithms in the analysis chain calculate spectra, then the ResetAnalysisChain() method can be called in the case of an error when calling an input method. Because it is not possible to calculate correct spectra on the basis of fragmented time series.

  • Return value: If an error occurs, a corresponding error code of the type HRESULT is output. Possible values are described in the list of error codes.
METHOD ResetAnalysisChain : HRESULT
VAR_INPUT
END_VAR

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.4022.25

PC or CX (x86, x64)

Tc3_CM, Tc3_CM_Base, Tc3_MultiArray