FB_CMA_Sink

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

It contains all the MultiArrays that are transferred to the specified analysis ID. Depending on the analysis chain the output results can contain NaN values.

Notice

Exception

Comparisons with NaN (Not a Number) can cause an exception that leads to an execution stop and may possibly cause machine damage. It is urgently recommended to check the result for NaN before it is processed. Or if NaNs are to be processed in the application, the floating point exception must be deactivated for this task.

Inputs and outputs

VAR_INPUT
    nOwnID           : UDINT;                // ID for this FB instance 
    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 provide information on the input values of the analysis chain associated with the last result output. See also the possible parameterization at FB_CMA_Source.

Name

Type

Access

Description

nSourceTimestampNewest

ULINT
[T_DCTIME64; 1ns steps since 1.1.2000]

Get

Associated with the last result output, this outputs the timestamp of the latest input value of the analysis chain.
This is the upper limit (exclusive) of the timespan.

nSourceTimestampOldest

ULINT
[T_DCTIME64; 1ns steps since 1.1.2000]

Get

Associated with the last result output, this outputs the timestamp of the oldest input value of the analysis chain.
This is the lower limit (inclusive) of the timespan.

nSourceValues

ULINT

Get

Associated with the last result output, this shows the number of input values (signal values) of the analysis chain.

tSourceTimespan

LTIME

Get

Associated with the last result output, this outputs the timespan of the input values (signal values) of the analysis chain.
tSourceTimespan := nSourceValues * tSamplePeriod;

Methods

Output1D():

Writes data from a MultiArray into an external one-dimensional data buffer. The function block waits for input data if the method indicates neither new results nor an error. This is a regular behavior in the process of the analysis chain.

  • 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 Output1D : HRESULT
VAR_INPUT
    pDataOut      : POINTER TO BYTE;      // address of data buffer
    nDataOutSize  : UDINT;                // size of data buffer in bytes
    eElementType  : E_MA_ElementTypeCode;
    nWorkDim      : UDINT:=0;             // It designates the dimension in the MultiArray being processed.
    nElements     : UDINT:=0;             // optional: default:0->full  copy; It designates the number of elements to be copied out of the MultiArray.
    pStartIndex   : POINTER TO UDINT;    (* optional: default:0->internally handled as [0,0,..]; 
                                          It designates the index of the first element to be copied out of the MultiArray.
                                          If allocated it must point to a onedimensional array of UDINT with so many elements as dimensions of the MultiArray. *)
    nOptionPars   : DWORD;                // option mask 
END_VAR
VAR_OUTPUT
    bNewResult    : BOOL;                 // TRUE every time when data was written from MultiArray to data buffer.
    bError        : BOOL;                 // TRUE if an error occurs.
    hrErrorCode   : HRESULT;              // '< 0' = error; '> 0' = info; '0' = no error/info
END_VAR
  • eElementType: This input is of the type E_MA_ElementTypeCode. The element type of the specified MultiArray buffer must correlate to the element type of the specified external data buffer.
  • nWorkDim: The dimension of the MultiArray to be processed. These data are copied into the specified external data buffer. In general the MultiArray is also one-dimensional and nWorkDim:=0, but the MultiArray can also have additional dimensions, which may not then be copied, however.
  • nElements: Specifies the number of elements to be copied from the MultiArray. nElements:=0 has to be set in order to copy everything. If you are only interested in a certain bandwidth of your result, however, then it is not necessary to copy the entire data quantity. This also reduces the necessary size of your specified external data buffer.
  • pStartIndex: This is an optional parameter that is useful if the MultiArray has more than one dimension or if not all elements are to be copied. Specifies the index of the first element that is to be copied from the MultiArray. If assigned, it must point to a one-dimensional array of UDINT that has as many elements as the MultiArray has dimensions.
  • bNewResult: This output is TRUE each time a new result has been successfully written into the 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.
    Tip: If a timeout occurs, the input data are not lost. They are processed on the next call.

Output1DStd():

Writes data from a MultiArray into an external one-dimensional data buffer. The function block waits for input data if the method indicates neither new results nor an error. This is a regular behavior in the process of the analysis chain.

This method uses default values for the parameters nWorkDim:=0, nElements:=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 Output1DStd : HRESULT
VAR_INPUT
    pDataOut      : POINTER TO BYTE;      // address of data buffer
    nDataOutSize  : 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 data was written from MultiArray to data buffer.
    bError        : BOOL;                 // TRUE if an error occurs.
    hrErrorCode   : HRESULT;              // '< 0' = error; '> 0' = info; '0' = no error/info
END_VAR
  • eElementType: This input is of the type E_MA_ElementTypeCode. The element type of the specified MultiArray buffer must correlate to the element type of the specified external data buffer.
  • bNewResult: This output is TRUE each time a new result has been successfully written into the 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.
    Tip: If a timeout occurs, the input data are not lost. They are processed on the next call.

Output2D():

Writes data from a MultiArray into an external two-dimensional data buffer. If the method is returned with neither an indication of a new result nor with an error, then the object waits for input data. This is a regular behavior in the analysis chain.

  • 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 Output2D : HRESULT
VAR_INPUT
    pDataOut      : POINTER TO BYTE;  // address of data buffer
    nDataOutSize  : UDINT;            // size of data buffer in bytes
    eElementType  : E_MA_ElementTypeCode;
    nWorkDim0     : UDINT:=0;         // It designates the first dimension in the MultiArray being processed.
    nWorkDim1     : UDINT:=1;         // It designates the second dimension in the MultiArray being processed.
    nElementsDim0 : UDINT:=0;         // optional: default:0->full copy; It designates the number of elements to be copied out of WorkDim0 of the MultiArray.
    nElementsDim1 : UDINT:=0;         // optional: default:0->full copy; It designates the number of elements to be copied out of WorkDim1 of the MultiArray.
    pStartIndex   : POINTER TO UDINT; (* optional: default:0->internally handled as [0,0,..]; 
                                      It designates the index of the first element to be copied out of the MultiArray.
                                      If allocated it must point to a onedimensional array of UDINT with so many elements as dimensions of the MultiArray. *)
    nOptionPars   : DWORD;           // option mask
END_VAR
VAR_OUTPUT
    bNewResult    : BOOL;            // TRUE every time when data was written from MultiArray to data buffer.
    bError        : BOOL;            // TRUE if an error occurs.
    hrErrorCode   : HRESULT;         // '< 0' = error; '> 0' = info; '0' = no error/info
END_VAR
  • pDataOut: Address of the external two-dimensional data buffer.
  • eElementType: This input is of the type E_MA_ElementTypeCode. The element type of the specified MultiArray buffer must correlate to the element type of the specified external data buffer.
  • nWorkDim0: Specifies the first dimension of the MultiArray to be processed. These data are copied into the first dimension of the specified external data buffer. In general the MultiArray is also two-dimensional and nWorkDim0:=0, but the MultiArray can also have additional dimensions, which may not then be copied, however.
    E.g.: If the second dimension is to be copied into the first index of the target data buffer, then set nWorkDim0:=1.
  • nWorkDim1: Specifies the second dimension of the MultiArray to be processed. These data are copied into the second dimension of the specified external data buffer. In general the MultiArray is also two-dimensional and nWorkDim1:=1, but the MultiArray can also have additional dimensions, which may not then be copied, however.
    E.g.: If the first dimension is to be copied into the second index of the target data buffer, then set nWorkDim1:=0.
  • nElementsDim0: Specifies the number of elements to be copied from nWorkDim0 of the MultiArray. nElementsDim0:=0 has to be set in order to copy everything. If you are only interested in a certain bandwidth of your result, however, then it is not necessary to copy the entire data quantity. This also reduces the necessary size of your specified external data buffer.
  • nElementsDim1: Specifies the number of elements to be copied from nWorkDim0 of the MultiArray. nElementsDim1:=0 has to be set in order to copy everything. If you are only interested in a certain bandwidth of your result, however, then it is not necessary to copy the entire data quantity. This also reduces the necessary size of your specified external data buffer.
  • pStartIndex: This is an optional parameter that is useful if the MultiArray has more than two dimensions or if not all elements are to be copied. Specifies the index of the first element that is to be copied from the MultiArray. If assigned, it must point to a one-dimensional array of UDINT that has as many elements as the MultiArray has dimensions.
  • bNewResult: This output is TRUE each time a new result has been successfully written into the 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.
    Tip: If a timeout occurs, the input data are not lost. They are processed on the next call.

Output2DStd():

Writes data from a MultiArray into an external two-dimensional data buffer. If the method is returned with neither an indication of a new result nor with an error, then the object waits for input data. This is a regular behavior in the analysis chain.

This method uses default values for the parameters nWorkDim0:=0, nWorkDim1:=1, nElementsDim0:=0, nElementsDim1:=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 Output2DStd : HRESULT
VAR_INPUT
    pDataOut      : POINTER TO BYTE;  // address of data buffer
    nDataOutSize  : 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 data was written from MultiArray to data buffer.
    bError        : BOOL;            // TRUE if an error occurs.
    hrErrorCode   : HRESULT;         // '< 0' = error; '> 0' = info; '0' = no error/info
END_VAR
  • pDataOut: Address of the external two-dimensional data buffer.
  • eElementType: This input is of the type E_MA_ElementTypeCode. The element type of the specified MultiArray buffer must correlate to the element type of the specified external data buffer.
  • bNewResult: This output is TRUE each time a new result has been successfully written into the 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.
    Tip: If a timeout occurs, the input data are not lost. They are processed on the next call.

Output3D():

Writes data from a MultiArray into an external three-dimensional data buffer. If the method is returned with neither an indication of a new result nor with an error, then the object waits for input data. This is a regular behavior in the analysis chain.

  • 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 Output3D : HRESULT
VAR_INPUT
    pDataOut      : POINTER TO BYTE;  // address of data buffer
    nDataOutSize  : UDINT;            // size of data buffer in bytes
    eElementType  : E_MA_ElementTypeCode;
    nWorkDim0     : UDINT:=0;         // It designates the first dimension in the MultiArray being processed.
    nWorkDim1     : UDINT:=1;         // It designates the second dimension in the MultiArray being processed.
    nWorkDim2     : UDINT:=1;         // It designates the third dimension in the MultiArray being processed.
    nElementsDim0 : UDINT:=0;         // optional: default:0->full copy; It designates the number of elements to be copied out of WorkDim0 of the MultiArray.
    nElementsDim1 : UDINT:=0;         // optional: default:0->full copy; It designates the number of elements to be copied out of WorkDim1 of the MultiArray.
    nElementsDim2 : UDINT:=0;         // optional: default:0->full copy; It designates the number of elements to be copied out of WorkDim2 of the MultiArray.
    pStartIndex   : POINTER TO UDINT; (* optional: default:0->internally handled as [0,0,..]; 
                                      It designates the index of the first element to be copied out of the MultiArray.
                                      If allocated it must point to a onedimensional array of UDINT with so many elements as dimensions of the MultiArray. *)
    nOptionPars   : DWORD;           // option mask
END_VAR
VAR_OUTPUT
    bNewResult    : BOOL;            // TRUE every time when data was written from MultiArray to data buffer.
    bError        : BOOL;            // TRUE if an error occurs.
    hrErrorCode   : HRESULT;         // '< 0' = error; '> 0' = info; '0' = no error/info
END_VAR
  • pDataOut: Address of the external two-dimensional data buffer.
  • eElementType: This input is of the type E_MA_ElementTypeCode. The element type of the specified MultiArray buffer must correlate to the element type of the specified external data buffer.
  • nWorkDim0: Specifies the first dimension of the MultiArray to be processed. These data are copied into the first dimension of the specified external data buffer. In general the MultiArray is also two-dimensional and nWorkDim0:=0, but the MultiArray can also have additional dimensions, which may not then be copied, however.
    E.g.: If the second dimension is to be copied into the first index of the target data buffer, then set nWorkDim0:=1.
  • nWorkDim1: Specifies the second dimension of the MultiArray to be processed. These data are copied into the second dimension of the specified external data buffer. In general the MultiArray is also two-dimensional and nWorkDim1:=1, but the MultiArray can also have additional dimensions, which may not then be copied, however.
    E.g.: If the first dimension is to be copied into the second index of the target data buffer, then set nWorkDim1:=0.
  • nWorkDim2: Specifies the third dimension of the MultiArray to be processed. These data are copied into the third dimension of the specified external data buffer. In general the MultiArray is also three-dimensional and nWorkDim2:=2, but the MultiArray can also have additional dimensions, which may not then be copied, however.
    E.g.: If the first dimension is to be copied into the second index of the target data buffer, then set nWorkDim2:=0.
  • nElementsDim0: Specifies the number of elements to be copied from nWorkDim0 of the MultiArray. nElementsDim0:=0 has to be set in order to copy everything. If you are only interested in a certain bandwidth of your result, however, then it is not necessary to copy the entire data quantity. This also reduces the necessary size of your specified external data buffer.
  • nElementsDim1: Specifies the number of elements to be copied from nWorkDim1 of the MultiArray. nElementsDim1:=0 has to be set in order to copy everything. If you are only interested in a certain bandwidth of your result, however, then it is not necessary to copy the entire data quantity. This also reduces the necessary size of your specified external data buffer.
  • nElementsDim2: Specifies the number of elements to be copied from nWorkDim2 of the MultiArray. nElementsDim2:=0 has to be set in order to copy everything. If you are only interested in a certain bandwidth of your result, however, then it is not necessary to copy the entire data quantity. This also reduces the necessary size of your specified external data buffer.
  • pStartIndex: This is an optional parameter that is useful if the MultiArray has more than two dimensions or if not all elements are to be copied. Specifies the index of the first element that is to be copied from the MultiArray. If assigned, it must point to a one-dimensional array of UDINT that has as many elements as the MultiArray has dimensions.
  • bNewResult: This output is TRUE each time a new result has been successfully written into the 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.
    Tip: If a timeout occurs, the input data are not lost. They are processed on the next call.

Output3DStd():

Writes data from a MultiArray into an external three-dimensional data buffer. If the method is returned with neither an indication of a new result nor with an error, then the object waits for input data. This is a regular behavior in the analysis chain.

This method uses default values for the parameters nWorkDim0:=0, nWorkDim1:=1, nWorkDim2:=2, nElementsDim0:=0, nElementsDim1:=0, nElementsDim2:=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 Output3DStd : HRESULT
VAR_INPUT
    pDataOut      : POINTER TO BYTE;  // address of data buffer
    nDataOutSize  : 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 data was written from MultiArray to data buffer.
    bError        : BOOL;            // TRUE if an error occurs.
    hrErrorCode   : HRESULT;         // '< 0' = error; '> 0' = info; '0' = no error/info
END_VAR
  • pDataOut: Address of the external two-dimensional data buffer.
  • eElementType: This input is of the type E_MA_ElementTypeCode. The element type of the specified MultiArray buffer must correlate to the element type of the specified external data buffer.
  • bNewResult: This output is TRUE each time a new result has been successfully written into the 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.
    Tip: If a timeout occurs, the input data are not lost. They are processed on the next call.
METHOD Init : HRESULT
VAR_INPUT
    nOwnID: UDINT; // ID for this FB instance 
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.

PassInputs():

As long as an FB_CMA_Source instance is called and signal data are thus transferred to a target block, all further function blocks of the analysis chain have to be called cyclically as explained in the API PLC Reference.
Sometimes it is useful not to execute an algorithm for a certain time. For example, some algorithms should be executed only after prior training or configuration. The function block must be called cyclically, but it is sufficient for the data arriving at the function block to be forwarded in the communication ring. This is done using the PassInputs() method in place of the Call() method. The algorithm itself is not called here, and accordingly no result is calculated and no output buffer generated.

  • 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 PassInputs : 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