Hi,
X2 Extreme 12 panel. Using SetSystemTime to synchronize time with a single board computer via tags. I find that the HH:MM:SS time update varies and generally not the same as what is set in the tags by the single board computer. Year, month, day are fine.
Have configured Time Zone as UTC (coordinated universal time).
Is there an issue with SetSystemTime?
Ken
SetSystemTime
Re: SetSystemTime
Hi,
More information:
SetSystemTime returns error 0x57, invalid parameters.
Single Board Computer:
A single board computer synchronizes time with an NTP server.
The single board computer does the following to pass time, date information to the X2 Extreme panel:
time(&tt); /* calendar time in seconds */
/* convert to struct tm format, use re-entrant version of gmtime */
gmtime_r(&tt, &tmBuffer);
Write the information to tags via modbus RTU:
Are the following settings for SYSTEMTIME parameters correct?
WrHMIHoldingReg(MODBUS_YEAR, pTime->tm_year);
WrHMIHoldingReg(MODBUS_MONTH, pTime->tm_mon+1);
WrHMIHoldingReg(MODBUS_DAY, pTime->tm_mday);
WrHMIHoldingReg(MODBUS_HOUR, pTime->tm_hour);
WrHMIHoldingReg(MODBUS_MINUTES, pTime->tm_min);
WrHMIHoldingReg(MODBUS_SECONDS, pTime->tm_sec);
/* set the set time request bit to the HMI */
WrHMIDO(MODBUS_SBC_SETTIME_BIT, TRUE);
X2 Extreme panel:
SYSTEMTIME st = new SYSTEMTIME();
st.wYear = Globals.Tags.TagYear.Value.UShort;
st.wMonth = Globals.Tags.TagMonth.Value.UShort;
st.wDay = Globals.Tags.TagDay.Value.UShort;
st.wHour = Globals.Tags.TagHour.Value.UShort;
st.wMinute = Globals.Tags.TagMinute.Value.UShort;
st.wSecond = Globals.Tags.TagSecond.Value.UShort;
st.wMilliseconds = (ushort)0;
uint result = SetSystemTime(ref st);
if (0 == result)
{
uint error = GetLastError();
MessageBox.Show(String.Format("SetSystemTime failed: {0:X8}", error));
}
The documentation regarding SYSTEMTIME parameter settings is confusing. Anyone successfully used SetSystemTime on the X2 Extreme 12 panel?
Regards,
Ken
More information:
SetSystemTime returns error 0x57, invalid parameters.
Single Board Computer:
A single board computer synchronizes time with an NTP server.
The single board computer does the following to pass time, date information to the X2 Extreme panel:
time(&tt); /* calendar time in seconds */
/* convert to struct tm format, use re-entrant version of gmtime */
gmtime_r(&tt, &tmBuffer);
Write the information to tags via modbus RTU:
Are the following settings for SYSTEMTIME parameters correct?
WrHMIHoldingReg(MODBUS_YEAR, pTime->tm_year);
WrHMIHoldingReg(MODBUS_MONTH, pTime->tm_mon+1);
WrHMIHoldingReg(MODBUS_DAY, pTime->tm_mday);
WrHMIHoldingReg(MODBUS_HOUR, pTime->tm_hour);
WrHMIHoldingReg(MODBUS_MINUTES, pTime->tm_min);
WrHMIHoldingReg(MODBUS_SECONDS, pTime->tm_sec);
/* set the set time request bit to the HMI */
WrHMIDO(MODBUS_SBC_SETTIME_BIT, TRUE);
X2 Extreme panel:
SYSTEMTIME st = new SYSTEMTIME();
st.wYear = Globals.Tags.TagYear.Value.UShort;
st.wMonth = Globals.Tags.TagMonth.Value.UShort;
st.wDay = Globals.Tags.TagDay.Value.UShort;
st.wHour = Globals.Tags.TagHour.Value.UShort;
st.wMinute = Globals.Tags.TagMinute.Value.UShort;
st.wSecond = Globals.Tags.TagSecond.Value.UShort;
st.wMilliseconds = (ushort)0;
uint result = SetSystemTime(ref st);
if (0 == result)
{
uint error = GetLastError();
MessageBox.Show(String.Format("SetSystemTime failed: {0:X8}", error));
}
The documentation regarding SYSTEMTIME parameter settings is confusing. Anyone successfully used SetSystemTime on the X2 Extreme 12 panel?
Regards,
Ken
-
- Posts: 137
- Joined: Mon Jun 11, 2012 2:10 pm
Re: SetSystemTime
Ken,
Don't know if this helps, but I have successfully set the system time on my X2 display using the following class. To set system time, I use SystemCtrl.Time = New DateTime(year, month, day, hour, minute, second);
Don't know if this helps, but I have successfully set the system time on my X2 display using the following class. To set system time, I use SystemCtrl.Time = New DateTime(year, month, day, hour, minute, second);
Code: Select all
public class SystemCtrl
{
private const uint POWER_STATE_RESET = 0x00800000;
private struct SystemTime
{
public ushort Year;
public ushort Month;
public ushort DayOfWeek;
public ushort Day;
public ushort Hour;
public ushort Minute;
public ushort Second;
public ushort Millisecond;
};
// Reboots system
[DllImport("coredll.dll", EntryPoint = "SetSystemPowerState", SetLastError = true)]
private static extern uint SetSystemPowerState(IntPtr psState, uint StateFlags, uint Options);
// Get's local time
[DllImport("coredll.dll", EntryPoint="GetLocalTime", SetLastError = true)]
private static extern bool GetLocalTime(ref SystemTime st);
// Set's local time
[DllImport("coredll.dll", EntryPoint="SetLocalTime", SetLastError = true)]
private static extern bool SetLocalTime(ref SystemTime st);
public static void Reboot()
{
SetSystemPowerState(IntPtr.Zero, POWER_STATE_RESET, 0);
}
public static DateTime Time
{
get
{
SystemTime st = new SystemTime();
GetLocalTime(ref st);
return new DateTime((int)(st.Year), (int)(st.Month), (int)(st.Day), (int)(st.Hour), (int)(st.Minute), (int)(st.Second), (int)(st.Millisecond));
}
set
{
SystemTime st = new SystemTime();
DateTime dt = (DateTime)value;
st.Year = (ushort)(dt.Year);
st.Month = (ushort)(dt.Month);
st.DayOfWeek = (ushort)(dt.DayOfWeek);
st.Day = (ushort)(dt.Day);
st.Hour = (ushort)(dt.Hour);
st.Minute = (ushort)(dt.Minute);
st.Second = (ushort)(dt.Second);
st.Millisecond = (ushort)(dt.Millisecond);
SetLocalTime(ref st);
}
}
}
Adam M.
Controls Engineer
FlexEnergy
Controls Engineer
FlexEnergy
Re: SetSystemTime
Hi Adam,
Thanks, will try out your suggestion.
Regards,
Ken
Thanks, will try out your suggestion.
Regards,
Ken