0

For the last couple of hours, I am facing problems with changing system date and time by structured-text programming. I have used function block FB_LocalSystemTime where I can read the system time. But I could not find any function or function block to write new system time. I have checked NT_SetLocalTime, that also did not work. Do you have any idea how can I do that?

For further information: I have included the sample code like:


    /**
    Declaration Part
    **/
     fbLocalSystemTime:FB_localSystemTime;
     fbSetLocalTime:NT_SetLocalTime;
     newTime:TIMESTRUCT:=(wHour:=5);



    /**
    DEFINITION PART
    **/

    fbLocalSystemTime(); /*This gives system time */
    fbSetLocalTime.TIMESTR:=newTimne; /* New time to set */
    fbSetLocalTime.START:=TRUE;
    fbSetLocalTime();  /** This does NOT set the system time which I guess should set **/

krishna
  • 123
  • 1
  • 1
  • 12
  • Unclear, I checked http://stackoverflow.com/questions/tagged/controller and http://stackoverflow.com/questions/tagged/plc but I don't really see how its related. And whats "Beckhoff" ? Could you please give some more context so we know what you are talking about ? See http://stackoverflow.com/help/how-to-ask – kebs Jul 09 '15 at 10:50
  • Hi Kebs, I have modified my question, I guess it is more clear now. – krishna Jul 10 '15 at 05:55

4 Answers4

0

I understand the question, but unfortunately I don't have much experience with beckhoff plcs. Have you tried calling their support line? This should be a non application specific question that should be easy for them to help you with.

tkezy
  • 162
  • 7
0

You may consider using FB_LocalSystemTime in the way indicated below. This will synchronize the local PLC time with the system with the given AMS ID passed to the parameter sNetID. If you do not pass sNetID parameter local OS system will be used as reference for setting the local PLC time. The time will be synchronized on rising edge of the signal bEnable and then in the interval given by the parameter dwCycle

VAR
  {attribute 'hide'}
  LocalSysTime : FB_LocalSystemTime;
  SynchNodeAmsId : STRING := '10.10.10.1.1.1';
END_VAR

LocalSysTime(
    sNetID:= SynchNodeAmsId,  
    bEnable:= TRUE, 
    dwCycle:= 60, 
    dwOpt:= , 
    tTimeout:= , 
    bValid=> , 
    systemTime=> , 
    tzID=> );
pedro
  • 21
  • 3
0

You are correct. You should be using NT_SetLocalTime.

If you open the function block fbSetLocalTime(), you will realize your function block returns an error with error ID 1862.

The definition of the errors can be found here: https://infosys.beckhoff.com/english.php?content=../content/1033/tcplclib_tc2_utilities/18014398544490635.html&id=

1862 means error in win32 system.

This is because TIMESTRUCT consists of Year, Month, Week, etc, but you only initialize the Hour as 5. This means that other things will become 0. The Year needs to be between 1970 and 2106, and there are many things to follow, shown below:

enter image description here

After you use a valid TIMESTRUCT variable, your code should be able to execute without problem and your computer system will be changed.

Stucky
  • 583
  • 3
  • 11
0

Had a similiar problem, using TwinCat3. Sometimes it works to change local system time, sometimes not. I use a small state machine to solve that (also there could be a more advanced solution) - just write 3 times the new time....

Here is an code example:

VAR
nState          : BYTE := 0;    //local state machine
ntSetLocalTime  : Tc2_Utilities.NT_SetLocalTime;
tTimestructSet  : Tc2_Utilities.TIMESTRUCT; // time to set
nErrId          : UDINT;
nRetryCnt       : BYTE := 0;        

and the state machine:

CASE nState OF

0:  //wait for change
    bBusy := FALSE;
    nRetryCnt := 0;
1:  //trigger change
    bBusy := TRUE;
    ntSetLocalTime(
                NETID:= '', 
                TIMESTR:= tTimestructSet, 
                START:= TRUE, 
                TMOUT:= , 
                BUSY=> , 
                ERR=> , 
                ERRID=> );

    nState := 2; //wait for writing

2:  //wait till written
    ntSetLocalTime(
                START:= FALSE,
                ERRID => nErrId);

    IF NOT ntSetLocalTime.BUSY THEN
        nState := 3;
    END_IF

3:  //retry and after some retries go back to init
    nRetryCnt := nRetryCnt + 1;
    IF nRetryCnt >=3 THEN
        nState := 0;
    ELSE
        nState := 1;

    END_IF

END_CASE

Otherwise you could call Beckhoff hotline, in most cases they have a really good support.

Arndt
  • 98
  • 5