Stephan Berger - 2023-11-23

Hi,

I just tried to get the DateTime of the PLC - I used the GetPlcDateTime function from Sharp7 as a template.

My function looks like this:

int S7Client::GetPlcDateTime(tm *DT)
{
    uint16_t Length;
    LastError = 0;
    // Setup the telegram
    memcpy(&PDU.H, S7_GET_DT, sizeof(S7_GET_DT));
    if (TCPClient->write(&PDU.H[0], sizeof(S7_GET_DT)) == sizeof(S7_GET_DT))
    {
        RecvISOPacket(&Length);
        if (LastError == 0)
        {
            if (Length > 30) // the minimum expected
            {
                if ((PDU.H[27] != 0x00))
                {
                    *DT = S7.GetDateTimeAt(&PDU.DATA, 35);
                }
                else
                    LastError = errS7Function;
            }
            else
                LastError = errS7InvalidPDU;
        }
    }
    else
        LastError = errTCPDataSend;

    return LastError;
}

S7_GET_DT is also from Sharp7

        // Get Date/Time request
        byte[] S7_GET_DT = {
            0x03, 0x00, 0x00, 0x1d,
            0x02, 0xf0, 0x80, 0x32,
            0x07, 0x00, 0x00, 0x38,
            0x00, 0x00, 0x08, 0x00,
            0x04, 0x00, 0x01, 0x12,
            0x04, 0x11, 0x47, 0x01,
            0x00, 0x0a, 0x00, 0x00,
            0x00
        };

I'm using **PDU.H[27] != 0x00 ** to query the result for errors - but I'm not sure if it is correct in this case?
The result I get is not 0x00

So could help me please
1. if the byte structure S7_GET_DT is ok?
2. if this call is correct:

memcpy(&PDU.H, S7_GET_DT, sizeof(S7_GET_DT));
    if (TCPClient->write(&PDU.H[0], sizeof(S7_GET_DT)) == sizeof(S7_GET_DT))

Thank You very much!
Stephan