You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I managed to implement Cli_GetPlcDateTime, Cli_SetPlcDateTime to a PLC S7-400 in my project and want to share.
Maybe someone with more experience can implement this into python-snap7 wrapper.
def get_plc_datetime(self):
"""
Get date and time from PLC.
(Wrapper for function Cli_GetPlcDateTime(), this is not yet implemented in main snap7/python project)
:return: date and time as DateTime
"""
type_ = ctypes.c_int32
buffer = (type_ * 9)()
result = self.library.Cli_GetPlcDateTime(self.pointer, ctypes.byref(buffer))
snap7.common.check_error(result, context="client")
return datetime.datetime(
year = buffer[5] + 1900,
month = buffer[4] + 1,
day = buffer[3],
hour = buffer[2],
minute = buffer[1],
second = buffer[0],
microsecond = 0
)
def set_plc_datetime(self, dt):
"""
Set date and time in PLC
(Wrapper for function Cli_SetPlcDateTime(), this is not yet implemented in main snap7/python project)
:param dt: Date and time as datetime object
:return:
"""
type_ = ctypes.c_int32
buffer = (type_ * 9)()
buffer[0] = dt.second
buffer[1] = dt.minute
buffer[2] = dt.hour
buffer[3] = dt.day
buffer[4] = dt.month - 1
buffer[5] = dt.year - 1900
code = self.library.Cli_SetPlcDateTime(self.pointer, ctypes.byref(buffer))
snap7.common.check_error(code, context="client")
return code
The text was updated successfully, but these errors were encountered:
Thanks! That looks already quite good already. If you want you can try to add it to the code yourself and issue a pull request. Do you know if the emulator supports these calls? If so we can also add it to the test suite.
I managed to implement Cli_GetPlcDateTime, Cli_SetPlcDateTime to a PLC S7-400 in my project and want to share.
Maybe someone with more experience can implement this into python-snap7 wrapper.
The text was updated successfully, but these errors were encountered: