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 |
|
|
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.
stInitPars
: Function-block-specific structure of the initialization parameters of the type ST_MA_MultiArray_InitPars. MultiArray buffers are specified for the result buffers. These parameters must correlate to the above definition of the output buffers.nOwnID
: Identifies the function block instance with a unique ID. This must always be greater than zero. A proven approach is to define an enumeration for this purpose.aDestIDs
: Defines the destinations to which the results are to be forwarded by specifying the IDs of the destinations. The definition of the output buffer (as described above) must correlate to the definition of the input buffer of each selected destination.nResultBuffers
: The function block initializes a Transfer Tray Stream with the specified number of MultiArray buffers. The default value is four.tTransferTimeout
: Setting of the synchronous timeout for internal MultiArray forwardings. See section Parallel processing.
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 isTRUE
if an error occurs. -
hrErrorCode
: If an error occurs, a corresponding error code of the typeHRESULT
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 | Set | Specification of the timestamp associated with the oldest value, which is transferred with the next input call. |
tSamplePeriod | LTIME | Set | Specification of the time difference between two input values. |
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 andnWorkDim := 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 ofUDINT
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 isTRUE
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 isTRUE
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 andnWorkDim0 := 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 setnWorkDim0:=1
.nWorkDim1
: Defines the dimension in which the data are accumulated. In general the MultiArray is also two-dimensional andnWorkDim1 := 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 setnWorkDim1 := 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 ofUDINT
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 isTRUE
if an error occurs.hrErrorCode
: If an error occurs, then a descriptive error code of the typeHRESULT
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 isTRUE
if an error occurs.hrErrorCode
: If an error occurs, then a descriptive error code of the typeHRESULT
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 andnWorkDim0 := 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 setnWorkDim0 := 1
.nWorkDim1
: Defines the dimension that corresponds to the number of subchannels. In general, the MultiArray is also three-dimensional andnWorkDim0 := 0
andnWorkDim1 := 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 setnWorkDim1 := 2
.nWorkDim2
: Defines the dimension in which the data are accumulated. In general the MultiArray is also two-dimensional andnWorkDim1 := 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 setnWorkDim1 := 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 ofUDINT
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 isTRUE
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 isTRUE
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.
stInitPars
: Function-block-specific structure of the initialization parameters of the type ST_MA_MultiArray_InitPars. MultiArray buffers are specified for the result buffers. These parameters must correlate to the above definition of the output buffers.nOwnID
: Identifies the function block instance with a unique ID. This must always be greater than zero. A proven approach is to define an enumeration for this purpose.aDestIDs
: Defines the destinations to which the results are to be forwarded by specifying the IDs of the destinations. The definition of the output buffer (as described above) must correlate to the definition of the input buffer of each selected destination.nResultBuffers
: The function block initializes a Transfer Tray Stream with the specified number of MultiArray buffers. The default value is four.
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 |