#ifndef _DRIVEENCODERMEMORY_H
#define _DRIVEENCODERMEMORY_H
// NewInst Command Range 0x8550-0x855F

#define DRIVEENCMEM_CMD_FETCHENCODERDATA        0x8550
#define DRIVEENCMEM_CMD_CHECKFETCHENCODERDATA   0x8551
#define DRIVEENCMEM_CMD_GETERRORCODE            0x8552
#define DRIVEENCMEM_CMD_GETENCODERDATASIZE      0x8553
#define DRIVEENCMEM_CMD_GETENCODERDATA          0x8554

//+++++++++++++++++++++++++++++++++++++
//#define DRIVEENCMEM_CMD_FETCHENCODERDATA        0x8550
// Sets a request to fetch the encoder memory to the HW class. 
// The data is fetched asynchronously from the drive over a period of time. 
// The status of the readout process can be read out via "DRIVEENCMEM_CMD_CHECKFETCHENCODERDATA" command. 
// After the data has been read out, it can be fetched with the command "DRIVEENCMEM_CMD_GETENCODERDATA".

      // aPara[0] = version of command
      // Parameter of Version 1:
      // aPara[1]$UDINT          : Offset from which the memory is to be read out in bytes.
      // aPara[2]$UDINT          : Number of bytes that are read from the memory.
        
      // result of version 1
      // uiLng := 8;
      // aData[0]$DINT   : return code. Reason command Failed. 0 Ok, Else ErrorCode
      // aData[4]$DINT   : version

//+++++++++++++++++++++++++++++++++++++
//#define DRIVEENCMEM_CMD_CHECKFETCHENCODERDATA   0x8551
// Returns the status of the encoder memory readout.

      // aPara[0] = version of command
      // Parameter of Version 1:
      // aPara[1]$^UDINT         :  If a vaild pointer is passed, the progress of the encoder memory upload in percentage 0-1000 [0-100.0%] is safed to this pointer.

      // result of version 1
      // uiLng := 8;
      // aData[0]$DINT   : return code. Reason command Failed. 0 Ok, Else ErrorCode
      // aData[4]$DINT   : version
      
//+++++++++++++++++++++++++++++++++++++
//#define DRIVEENCMEM_CMD_GETERRORCODE            0x8552
// Returns the last error code that occurred.

      // aPara[0] = version of command
      // Parameter of Version 1:

      // result of version 1
      // uiLng := 8;
      // aData[0]$DINT   : last error code that occurred
      // aData[4]$DINT   : version
      
//+++++++++++++++++++++++++++++++++++++
//#define DRIVEENCMEM_CMD_GETENCODERDATASIZE      0x8553
// Returns the size of the encoder memory from the drive.

      // aPara[0] = version of command
      // Parameter of Version 1:
      // aPara[1]$^UDINT         : The size of the encoder memory is written to this pointer when the retcode = READY.
      
      // result of version 1
      // uiLng := 8;
      // aData[0]$DINT   : last error code that occurred
      // aData[4]$DINT   : version

//+++++++++++++++++++++++++++++++++++++
//#define DRIVEENCMEM_CMD_GETENCODERDATA          0x8554
// Returns a pointer to the previously read encoder data. 
// See method "FetchEncoderData". 
// Attention: The validity of the data expires if "FetchEncoderData" is called again!

      // aPara[0] = version of command
      // Parameter of Version 1:
      // aPara[1]$^UDINT         : Optional. The size of the read encoder memory is written to this memory if the pointer <> NIL. 
      
      // result of version 1
      // uiLng := 12;
      // aData[0]$DINT   : last error code that occurred
      // aData[4]$DINT   : version
      // aData[8]$pVoid  : <> NIL ...  Pointer to the encoder data, Error See last error code

// Return Code definition
#define DRIVEENCMEM_RETOK    0
#define DRIVEENCMEM_RETBUSY 11 

#define DRIVEENCMEM_RETERR  -1

#define DRIVEENCMEM_RETERR_CREATEBUFFER_FAILED       -2
#define DRIVEENCMEM_RETERR_CLASSNOTCONNECTED         -3
#define DRIVEENCMEM_RETERR_AXISNOTONLINE             -4

#define DRIVEENCMEM_RETERR_CMD_NOT_SUPPORTED        -10
#define DRIVEENCMEM_RETERR_CMD_VERSION              -11
#define DRIVEENCMEM_RETERR_CMD_PARAMETER_NIL        -12

#define DRIVEENCMEM_RETERR_GETENCODERMEMSIZE_ASYWR  -20
#define DRIVEENCMEM_RETERR_GETENCODERMEMSIZE_ASYRD  -21
#define DRIVEENCMEM_RETERR_NO_ENCODER_MEM           -22
#define DRIVEENCMEM_RETERR_ENCODER_MEM_NOTREAD      -23

#define DRIVEENCMEM_RETERR_ENCODERMEMSIZE_SIZE_INVALID  -30
#define DRIVEENCMEM_RETERR_OFFSET_SIZE_OUTOFRANGE       -31
#define DRIVEENCMEM_RETERR_OFFSET_SIZE_OUTOFBUFFERRANGE -32
#define DRIVEENCMEM_RETERR_GETENCODERMEMASYNC_LOCK      -33
#define DRIVEENCMEM_RETERR_SELECT_BLOCK                 -34
#define DRIVEENCMEM_RETERR_SELECT_BLOCK_IDX             -35
#define DRIVEENCMEM_RETERR_READ_BLOCK                   -36
#define DRIVEENCMEM_RETERR_RELEASEENCODERMEMASYNC_LOCK  -37
#define DRIVEENCMEM_RETERR_CHECK_START_FILEREAD         -38
#define DRIVEENCMEM_RETERR_CHECK_START_FILEREAD_RETVAL  -39
#define DRIVEENCMEM_RETERR_START_FILEREAD               -40
#define DRIVEENCMEM_RETERR_FILEREAD                     -41

#endif

