CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Tue Dec 10, 2019 6:49 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Fri Jun 26, 2015 12:31 am 
Offline

Joined: Wed Feb 11, 2015 4:47 pm
Posts: 10
Is there a more direct method to extract the current PC's system date and time in Structured Language for a CoDeSys application?

I have tried the two methods implemented in the DateTimeUtilities example but I honestly believe that there should be an easier way to interrogate the system to obtain the present date and time without the need to have the program to invest time in calculating dates and times from 1970 and expecting a parameter for the timezone. The System's date and time is already available in the PC.

I have also attempted the RTC function, but this method requires the timezone parameter also.

In contrast, in the visualization the direct exhibition of a text like %t[ddd MMM.dd.yyyy HH:mm:ss] in a text field will display Thu Jun.25.2015 18:22:14 at running time - easy, clear and direct.

Luis Mendez


Top
   
PostPosted: Mon Jun 29, 2015 4:55 pm 
Offline

Joined: Wed Feb 11, 2015 4:47 pm
Posts: 10
Perhaps I shall add that I am writing a CoDeSys application to run through Win SL that is expected to go in a product that could be in any timezone. (It actually might travel through several timezones)

This is the reason why I would like to understand if there is a method to obtain the computer's system time by just by requesting it.

Thanks


Top
   
PostPosted: Mon Jun 29, 2015 8:13 pm 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3564
Hi,
you are right i agree ... we will change either this Date and Time example (add an simple fb)
or we need to add an FB to a library which bring a simple (visu like) result.
BR
Edwin


Top
   
PostPosted: Mon Jun 29, 2015 11:31 pm 
Offline
User avatar

Joined: Tue Aug 30, 2011 1:21 am
Posts: 96
Try the following POU

Attachment:
PLC_TIME_V2.png


You do not have the required permissions to view the files attached to this post.

_________________
The Original SoMachine Ninja


Top
   
PostPosted: Tue Jul 07, 2015 4:45 pm 
Offline

Joined: Wed Feb 11, 2015 4:47 pm
Posts: 10
Thanks Edwin and jzhvymetal for your prompt feedback,

I have decided to go with the following set of instructions,

VAR
Date_and_time_in_seconds : UDINT;
Local_date_time_seconds : UDINT;
Date_and_Time_result : UDINT;
Local_date_time_from_secs : SYSTIMEDATE;
Date_and_time_format : DATE_AND_TIME;
Date_and_time_string : STRING;

END_VAR

// Get time in seconds since 1970 :
Date_and_time_in_seconds := SysTimeRtcGet(Date_and_Time_result);
IF Date_and_Time_result <> 0 THEN
RETURN;
END_IF

// Convert UTC seconds to local time seconds, regarding Timezone and Summer time :
Date_and_Time_result := SysTimeRtcConvertUtcToLocal(Date_and_time_in_seconds, Local_date_time_seconds);
IF Date_and_Time_result <> 0 THEN
RETURN;
END_IF

// Convert the UTC seconds to a DATE_AND_TIME variable dt#yyyy-mm-dd-hh:mm:ss :
Date_and_time_format := UDINT_TO_DT(Local_date_time_seconds);

// Convert DATE_AND_TIME to a String :
Date_and_time_string := DT_TO_STRING(Date_and_time_format);


Top
   
PostPosted: Sat Feb 18, 2017 3:17 pm 
Offline

Joined: Thu Feb 16, 2017 1:46 am
Posts: 14
hi, I'm new user of Codesys and when I import the POU for time, this POU doesnt appear to be a fonction block, does someone can help me?


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 6 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited