/******************************************************************************************* SIMPL+ Module Information *******************************************************************************************/ /* Dealer Name: System Name: System Number: Programmer: O. Zechmeister Comments: v1.0 */ #SYMBOL_NAME "Time Server Client" #CATEGORY "16" // Time/Date #DEFAULT_VOLATILE /* #HELP_BEGIN Connect this module to a server that supports the "daytime" time format on Port 13. This module was tested with 192.43.244.18 Port 13. #HELP_END */ /******************************************************************************************* DIGITAL, ANALOG and SERIAL INPUTS and OUTPUTS *******************************************************************************************/ DIGITAL_INPUT _SKIP_, fb_Server_Connected, Sync_NOW, in_dst; STRING_INPUT Server_Rx$[100]; DIGITAL_OUTPUT _SKIP_, Connect_to_Server; /******************************************************************************************* Parameters *******************************************************************************************/ SIGNED_INTEGER_PARAMETER GMT_Offset; /******************************************************************************************* Parameter Properties *******************************************************************************************/ #BEGIN_PARAMETER_PROPERTIES GMT_Offset propValidUnits = unitDecimal; propDefaultUnit = unitDecimal; propBounds = -12d, 12d; propDefaultValue = 1d; #END_PARAMETER_PROPERTIES /******************************************************************************************* Global Variables *******************************************************************************************/ INTEGER waitForDst, RxYEAR, RxMONTH, RxDAY, RxHOUR, RxMIN, RxSEC; STRING RxTIME[100]; /******************************************************************************************* Event Handlers *******************************************************************************************/ PUSH Sync_NOW { Connect_to_Server = 0; Connect_to_Server = 1; } RELEASE fb_Server_Connected { Connect_to_Server = 0; } CHANGE Server_Rx$ { RxTIME = ""; WHILE(LEN(RxTIME) < 23) { RxTIME = GATHER("\x0A", Server_Rx$); } RxYEAR = ATOI(MID(RxTIME, 7, 2)) + 2000; RxMONTH = ATOI(MID(RxTIME, 10, 2)); RxDAY = ATOI(MID(RxTIME, 13, 2)); RxHOUR = ATOI(MID(RxTIME, 16, 2)); RxHOUR = RxHOUR + GMT_Offset; IF(in_dst) { RxHOUR = RxHOUR + 1; } RxMIN = ATOI(MID(RxTIME, 19, 2)); RxSEC = ATOI(MID(RxTIME, 22, 2)); SetDate(RxMONTH, RxDAY, RxYEAR); SetClock(RxHOUR, RxMIN, RxSEC); waitForDST = 1; WAIT(1000, DST_WAIT) { waitForDST = 0; } } CHANGE in_dst { IF(waitForDST) { CANCELWAIT(DST_WAIT); RxHOUR = GetHourNum(); RxMIN = GetMinutesNum(); RxSEC = GetSecondsNum(); IF(in_dst) { RxHOUR = RxHOUR + 1; } ELSE { RxHOUR = RxHOUR - 1; } SetClock(RxHOUR, RxMIN, RxSEC); } } /******************************************************************************************* Main() *******************************************************************************************/ Function Main() { waitForDST = 0; }