Transformation

Transformations describe the relationship between the hardware object and the representation in WinCC OA. A separate transformation should be implemented for each data type in the periphery, describing how the incoming data should be interpreted (as integer, or real, or bitwise), and to perform conversion in the send direction (e.g. set different bits in the data buffer based on its subindex).

All transformations are derived from the class Transformation of the general driver. The following virtual methods should be implemented in every case:

  • toPeriph(PVSSchar *dataPtr, PVSSushort len, const Variable &var, const PVSSushort subix) const is used for converting data in the command direction. The data of maximum length len is written to the buffer to which dataPtr points. The variable var contains the WinCC OA data element to be sent; if the transformation relates to fields, subix gives the subindex of this variable in the field. This function is called separately (in a loop of the general driver) for each field element (i.e. each subindex); the entire field is then compacted in the buffer in the form expected by the periphery. If the transformation can be successfully performed, the function should return PVSS_TRUE, otherwise PVSS_FALSE.

  • toPeriph(PVSSchar *dataPtr, PVSSushort len, const Variable &var, const PVSSushort subix) const RecVar &status) const corresponds to the above function. In addition, the last parameter contains the information for which the driver has registered with the event manager, such as the source time or any status bits.

  • toVar( const PVSSchar *dataPtr, const PVSSushort len, const PVSSushort subix) const is used for converting the data in alert direction. The field element with the subix from the buffer to which dataPtr points (the length len should be used to check whether the data buffer possess the required length) is converted into a WinCC OA variable, and supplied as return value from this function. In the event of an error, 0 is returned.

  • isA() returns the transformation type.

Example of a transformation that assigns a bit pattern (with 4 bits, 0 to 3) from the periphery to the individual bits of a WinCC OA bit structure (the relevant error handling is omitted here):

#include <BitVar.hxx>
#include <Variable.hxx>
PVSSboolean MyTransformation::toPeriph(PVSSchar *dataPtr, PVSSushort len, const Variable 
&var, const PVSSushort subindex) const
{
  if ((len != 1) || (subindex > 3) || (var.isA() != BIT_VAR))
  return PVSS_FALSE;
  if ( ((const BitVar &)var).getValue() )
  *dataPtr |= (1<<subindex);
  // set corresponding bit in buffer
  return PVSS_TRUE;
}
VariablePtr MyTransformation::toVar(const PVSSchar *dataPtr, const PVSSushort len,
const
PVSSushort subindex) const
{
  if ((len != 1) || (subindex > 3))
  return PVSS_FALSE;
  return new BitVar( (*dataPtr & (1<<subindex)) ?
  PVSS_TRUE : PVSS_FALSE );
}