Set date & time

Hi everybody,
is there a smart way to set date + time of the CPU via mappview? in my beloved visual components it was so easy, just set system time directly with a component.
Now there are 2 widgets, datetime input and output but I don’t understand why they are there if they can’t set the system time directly.

I just would like a widget where I set the current date+time and then it shows the new value, as any component of that type.

From what I understand, the only way to do it would be via code: when the value of datetime picker changes, set the system time via DTsetTime and then continuously call DTgetTime to show it. But it does not seem so efficient.

Is there a better way?
thanks

1 Like

I would expect that PLC where mappView server runs has a same system time like a client (synchronized to NTP server e.g.) and then it is enough if you just show in visualization system time of client. So you do not need to read cyclically PLC time. You are right that if you would like to change system time on PLC side, you have to bind DateTime variable and call respective function to change the time. It is not done automatically.

1 Like

Hi Valerio,

what we did in our project is a DateTimeInput which updates time in HMI until users sets it from HMI. Then time of PLC will be set.

  1. Create DateTimeInput DISystemTime
  2. Bind value to PLC var DesiredTime (DATE_AND_TIME) twoWay
  3. Events on DISystemTime:
    1. Click event → set PLC var UpdateDesiredTime to false
    2. ValueChanged event → set PLC var SetTime to true
  4. Following PLC code
CASE SetTimeState OF
	
	0:					// check for changes
		IF NOT UpdateDesiredTime THEN					// prepare setting time
			
			IF SetTime THEN
				DTSetTime_0.enable := TRUE;
				DTSetTime_0.DT1 := DesiredTime;
				
				SetTimeState := 10;
			END_IF
		ELSE
			SetTimeState := 5;
		END_IF
		
		
	5:				// Update desired value in visu				
		
		DesiredTime := current.DateTime.DateTime;	
	
		SetTimeState := 0;
		
			
	10:				// set time and wait
		
		IF DTSetTime_0.status = ERR_OK THEN
			SetTimeState := 20;
							
		ELSIF DTSetTime_0.status <> ERR_FUB_BUSY THEN
			SetTimeState := 99;
		END_IF
		
	
	20:					// deativate FUB
		DTSetTime_0.enable := FALSE;
		
		SetTime := FALSE;
		UpdateDesiredTime := TRUE;
		
		SetTimeState := 5;		
	
	99:					// Error
		
		SetTimeState := 5;	//edge alarm with ack req
	
END_CASE

DTSetTime_0();

Maybe this is helpful for you.

Sincerly Simon :slight_smile:

1 Like

thank you for your reply.
That’s interesting! so if I set the CPU to act as a NTP server

the NTP client (display connected via ethernet) will automatically sync with that time?

This would be perfect, I’d just need to set the PLC time once.

But I don’t see how to show the system time of the client via mapp view directly without using code, the only available value is
image
which does not look like the current system time…

thank you for adding your code.
this is more or less what I’m doing right now, but I thought there would be a quicker way directly from mappview.

I find really frustrating that B&R upgraded the HMI design by moving to mappview and still make things so much complicated than with visual components. Setting/viewing system time was just 1 click!

1 Like

It is very easy. Local time of the client is shown automatically, you do not need to bind anything.

1 Like

ah I see!!!
perfect so that’s it.
thank you very much Jaroslav

1 Like