Hello Davide,
found some problems when using SetDateTimeAt()/GetDateTimeAt() in in LabVIEW\snap7.cpp. The year value calculation seems to be incorrect. Please see source code fragments below:
void SetDateTimeAt( void *Buffer, int Pos, tm Value ) { #ifdef _ORIGINAL_SNAP7 pbyte p = pbyte(Buffer)+Pos; word Year = Value.tm_year; if (Year>99) Year-=100; *p=WordToBCD(Year); *(p+1)=WordToBCD(Value.tm_mon+1); *(p+2)=WordToBCD(Value.tm_mday); *(p+3)=WordToBCD(Value.tm_hour); *(p+4)=WordToBCD(Value.tm_min); *(p+5)=WordToBCD(Value.tm_sec); *(p+6)=0; *(p+7)=Value.tm_wday+1; #else //@wgr pbyte p = pbyte( Buffer ) + Pos; word Year = Value.tm_year; Year -= Year > 1999 ? 2000 : 1900; *p = WordToBCD( Year ); *( p + 1 ) = WordToBCD( Value.tm_mon + 1 ); *( p + 2 ) = WordToBCD( Value.tm_mday ); *( p + 3 ) = WordToBCD( Value.tm_hour ); *( p + 4 ) = WordToBCD( Value.tm_min ); *( p + 5 ) = WordToBCD( Value.tm_sec ); *( p + 6 ) = 0; *( p + 7 ) = Value.tm_wday + 1; #endif } struct tm GetDateTimeAt( void *Buffer, int Pos ) { #ifdef _ORIGINAL_SNAP7 struct tm DateTime; pbyte p = pbyte( Buffer ) + Pos; word Year = BCDtoByte( *p ); if ( Year < 90 ) Year += 100; DateTime.tm_year = Year; DateTime.tm_mon = BCDtoByte( *( p + 1 ) ) - 1; DateTime.tm_mday = BCDtoByte( *( p + 2 ) ); DateTime.tm_hour = BCDtoByte( *( p + 3 ) ); DateTime.tm_min = BCDtoByte( *( p + 4 ) ); DateTime.tm_sec = BCDtoByte( *( p + 5 ) ); DateTime.tm_wday = ( *( p + 7 ) & 0x0F ) - 1; return DateTime; #else //@wgr struct tm DateTime; pbyte p = pbyte( Buffer ) + Pos; word Year = BCDtoByte( *p ); Year += Year < 90 ? 2000 : 1900; DateTime.tm_year = Year; DateTime.tm_mon = BCDtoByte( *( p + 1 ) ) - 1; DateTime.tm_mday = BCDtoByte( *( p + 2 ) ); DateTime.tm_hour = BCDtoByte( *( p + 3 ) ); DateTime.tm_min = BCDtoByte( *( p + 4 ) ); DateTime.tm_sec = BCDtoByte( *( p + 5 ) ); DateTime.tm_wday = ( *( p + 7 ) & 0x0F ) - 1; return DateTime; #endif }
Greetings -- Werner
Log in to post a comment.
Hello Davide,
found some problems when using SetDateTimeAt()/GetDateTimeAt() in in LabVIEW\snap7.cpp.
The year value calculation seems to be incorrect. Please see source code fragments below:
Greetings
-- Werner
Last edit: wergro 2015-08-07