Matlab Simulink/LQ_Target_1500S_V4_0_grt_Output/LQ_ODK/src_odk_helpers/ODK_CpuReadData.cpp
bool CODK_CpuReadData::ReadS7STRING(const long  byteOffset,   // Buffer index to the data
                                    ODK_UINT8   readMax,      // Maximum characters to read including the string terminating zero
                                    ODK_CHAR*   string) const // Buffer to receive the string characters
{
    ODK_UINT8  curLen  = 0; // Current length of the string
    ODK_UINT8  maxLen  = 0; // Maximum length of the string
    ODK_UINT8  stop    = 0; // Maximum bytes to read
    ODK_UINT16 strData = static_cast<ODK_UINT16>(byteOffset + ODK_SIZEBIT16); // Offset to the string data (characters)

    // must receive a valid buffer for the string  AND  must have space for 1 character and the string terminator
    if (0 == string  ||  readMax < 2)
    {
        return false;
    }

    // Get the current string length
    if (! ReadS7STRING_LEN(byteOffset, maxLen, curLen))
    {
        return false;
    }

    // Verify offset not out of bounds
    if ((byteOffset < 0) || (byteOffset + static_cast<long>(maxLen) + ODK_SIZEBIT16 > m_nBytes))
    {
        return false;
    }

    // Get the value to read to
    if (curLen < readMax)
    {
        stop = curLen;
    }
    else
    {
        stop = static_cast<ODK_UINT8>(readMax - 1);
    }

    // Read the value
    memcpy(string, &(m_data[strData]), stop);
    string[stop] = '\0';  // terminate the string

    return true;
}
//
// ReadS7STRING : Reads an S7 string from the data area, and returns it as a C++ character string
//                Truncate destination string, when source string is too long.
//
ReadS7STRING : Reads an S7 string from the data area, and returns it as a C++ character string
Truncate destination string, when source string is too long.
ReadS7STRING : Reads an S7 string from the data area and returns it as a C ++ character string Truncate destination string when source string is too long .
bool CODK_CpuReadData::ReadS7STRING(const long  byteOffset,   
                                    ODK_UINT8   readMax,      
                                    ODK_CHAR*   string) const 
{
    ODK_UINT8  curLen  = 0; 
    ODK_UINT8  maxLen  = 0; 
    ODK_UINT8  stop    = 0; 
    ODK_UINT16 strData = static_cast<ODK_UINT16>(byteOffset + ODK_SIZEBIT16); 
    if (0 == string  ||  readMax < 2)
    {
        return false;
    }
    if (! ReadS7STRING_LEN(byteOffset, maxLen, curLen))
    {
        return false;
    }
    if ((byteOffset < 0) || (byteOffset + static_cast<long>(maxLen) + ODK_SIZEBIT16 > m_nBytes))
    {
        return false;
    }
    if (curLen < readMax)
    {
        stop = curLen;
    }
    else
    {
        stop = static_cast<ODK_UINT8>(readMax - 1);
    }
    memcpy(string, &(m_data[strData]), stop);
    string[stop] = '\0';  
    return true;
}
bool CODK_CpuReadData :: ReadS7STRING ( const long byteOffset , ODK_UINT8 readMax , ODK_CHAR * string ) const { ODK_UINT8 curLen = 0 ; ODK_UINT8 maxLen = 0 ; ODK_UINT8 stop = 0 ; ODK_UINT16 strData = static_cast < ODK_UINT16 > ( byteOffset + ODK_SIZEBIT16 ) ; if ( 0 == string || readMax < 2 ) { return false ; } if ( ! ReadS7STRING_LEN ( byteOffset , maxLen , curLen ) ) { return false ; } if ( ( byteOffset < 0 ) || ( byteOffset + static_cast < long > ( maxLen ) + ODK_SIZEBIT16 > m_nBytes ) ) { return false ; } if ( curLen < readMax ) { stop = curLen ; } else { stop = static_cast < ODK_UINT8 > ( readMax - 1 ) ; } memcpy ( string , & ( m_data [ strData ] ) , stop ) ; string [ stop ] = ' \0 ' ; return true ; }
ReadS7STRING : Reads an S7 string from the data area, and returns it as a C++ character string
Truncate destination string, when source string is too long.
ReadS7STRING : Reads an S7 string from the data area and returns it as a C ++ character string Truncate destination string when source string is too long .
// Buffer index to the data // Maximum characters to read including the string terminating zero // Buffer to receive the string characters // Current length of the string // Maximum length of the string // Maximum bytes to read // Offset to the string data (characters) // must receive a valid buffer for the string  AND  must have space for 1 character and the string terminator // Get the current string length // Verify offset not out of bounds // Get the value to read to // Read the value // terminate the string