How Can We Help?

Print

How to set and synchronize the ACE PLC clock with the HMI using a macro

In this post, we will show you how to synchronize the HMI clock with the ACE PLC clock.

As the HMI has a saved clock, we use it to update the ACE PLC clock.

With vBuilder

First of all, it is necessary to define in the Modbus register these UI8 tags that will be written by the HMI. Address 4×900 to 4×905.

Don’t forget to set them to “Writable” : “Y” You will get the clock of the HMI in your ACE PC.

With HMI-Tool

In the Macro Editor, add a new macro and copy it. You don’t have to use all the tags, if you need, for example, only the hours and minutes.

#include "MacroInit.h" 

int Convert (int input)
{
int iFirst = input &0x000F;
int iSecond = (input/16) &0x000F;
int iThird = (input/256) &0x000F;
int iFourth = (input/4096) &0x000F;
return iFirst + iSecond*10 + iThird*100 + iFourth*1000;
}

void Macro_main(IN *p)
{
MarcoInit
//ToDo
LocalWord[900] = Convert (BCDSec);
LocalWord[901] = Convert (BCDMin);
LocalWord[902] = Convert (BCDHou);
LocalWord[903] = Convert (BCDDay);
LocalWord[904] = Convert (BCDMon);
LocalWord[905] = Convert (BCDYea)-2000;

}

And create the list of these tags. BDCSec, BCDMin,.. come from the HMI clock. Sec, Min,.. are for the ACE PLC.

The Script editor:

Below the window script, the varaiables settings:

Example of variable seeting:

Compile the program The program must move to the “Success” branch  

Add the macro in “global Macro” list And set its frequency of execution to 1000 ms for update the clock every seconds.   You can download here the HMI and ACE project if you wish to test it.

 

The script converts the HMI clock data from BCD format to decimal format.

After this, the HMI clock variables are present in decimal format in registers LW900 to LW905.

In “Data forward” > “Word address”, add the right word address forward for copy the LW900 to LW905 to the right network link and PLC id.