You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old March 13th, 2018, 04:25 AM   #1
JohanM
Member
Slovakia

JohanM is offline
 
Join Date: Sep 2015
Location: Terchová
Posts: 48
TIA Portal YYYYMMDD to Date or DTL

Hi guys

I am crossing internet two days, but I can not find something really helpful for me..

I have this problem:

I have to read expiration date from EKS key and compare it with actual PLC date. That date in EKS is coded to 8 bytes character by character YYYYMMDD..I can read that bytes, I can convert it from ASCII, but I dont know, how to convert it to Date format or DTL.. Can someone help me with this?

Last edited by JohanM; March 13th, 2018 at 04:53 AM.
  Reply With Quote
Old March 13th, 2018, 05:47 AM   #2
CommissioningMan
Member
Denmark

CommissioningMan is offline
 
Join Date: Sep 2017
Location: Denmark
Posts: 60
There are many ways to do this, but you could convert the parts of the input string to internal DTL formats and convert again to date-format in order to compare YYYYMMDD.

String conversion can be a bit troublesome, but it's doable.
I have a working solution, but try it yourself first.

Here's a hint:
(*Convert string to UINT (.Year datatype). Input the 4 Chars (L) starting from char 1 (P)*)
#TestDTL.YEAR := STRING_TO_UINT(IN := MID(IN := #InputDate, L := 4, P := 1));
__________________
All things Siemens and Beckhoff. Please let it be Beckhoff.

Last edited by CommissioningMan; March 13th, 2018 at 05:50 AM.
  Reply With Quote
Old March 13th, 2018, 08:03 AM   #3
CommissioningMan
Member
Denmark

CommissioningMan is offline
 
Join Date: Sep 2017
Location: Denmark
Posts: 60
Since you have the bytes char by char, you probably have an Array[0..7] of CHAR that you can convert with CHARS_TO_STRG. Either to one complete string[8] or 3 separate strings for year, month, and day. After that you can convert to UINT/USINT.

Since you'll (probably) read the system time with RD_SYS_T or RD_LOC_T you'll have your current date in DTL format. Convert it to DATE with DTL_TO_DATE before you compare, otherwise you'll also compare the time of day, when you are only interested in the date.

You could also compare your CurrentDTL.Year with your TestDTL.Year and so on with .Month and .Day. You'll save a few conversions that way, but will do several comparisons instead.

OR you could also convert your CurrentDTL to strings and compare the other way around, but then you'll have to do padding with leading zeros for the month and day.

As you see, there are many ways to do it
__________________
All things Siemens and Beckhoff. Please let it be Beckhoff.
  Reply With Quote
Old March 13th, 2018, 01:10 PM   #4
JohanM
Member
Slovakia

JohanM is offline
 
Join Date: Sep 2015
Location: Terchová
Posts: 48
Quote:
Originally Posted by CommissioningMan View Post
Since you have the bytes char by char, you probably have an Array[0..7] of CHAR that you can convert with CHARS_TO_STRG. Either to one complete string[8] or 3 separate strings for year, month, and day. After that you can convert to UINT/USINT.

Since you'll (probably) read the system time with RD_SYS_T or RD_LOC_T you'll have your current date in DTL format. Convert it to DATE with DTL_TO_DATE before you compare, otherwise you'll also compare the time of day, when you are only interested in the date.

You could also compare your CurrentDTL.Year with your TestDTL.Year and so on with .Month and .Day. You'll save a few conversions that way, but will do several comparisons instead.

OR you could also convert your CurrentDTL to strings and compare the other way around, but then you'll have to do padding with leading zeros for the month and day.

As you see, there are many ways to do it
Thank you my friend!
I got solution from huggy_1 from Siemens forum. It is basicly what you suggested to me. Many thanks to you guys!

"
FUNCTION "EKS_DateToDTL" : Void
TITLE = EKS Date to DTL
{ S7_Optimized_Access := 'TRUE' }
AUTHOR : huggy_d1
FAMILY : EKS
NAME : FORUMS
VERSION : 0.1
//Accept EKS Date char array [YYYYMMDD] as input
//Output EKS Date as DTL tag
VAR_INPUT
EKS_Date : Array[0..7] of Char;
END_VAR
VAR_OUTPUT
EKS_DTL {OriginalPartName := 'DTL'; LibVersion := '1.0'} : DTL;
END_VAR
VAR_TEMP
EKS_String : String[8];
yyyy_string : String[4];
mm_string : String[2];
dd_string : String[2];
END_VAR

BEGIN
// convert YYYMMDD ASCII char array into a string
Chars_TO_Strg(Chars:=#EKS_Date,
pChars:=0,
Cnt:=8,
Strg=>#EKS_String);

// parse EKS_string to obtain YYYY, MM, DD as strings
#yyyy_string := LEFT(IN := #EKS_String, L := 4);
#mm_string := MID(IN := #EKS_String, L := 2, P := 5);
#dd_string := RIGHT(IN := #EKS_String, L := 2);
#EKS_DTL.YEAR := STRING_TO_UINT(IN:=#yyyy_string);
#EKS_DTL.MONTH := STRING_TO_USINT(IN:=#mm_string);
#EKS_DTL.DAY := STRING_TO_USINT(IN:=#dd_string);

END_FUNCTION


"


  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
TIA Portal v15 - does it overwrite v14 / v13? uptown47 LIVE PLC Questions And Answers 18 January 15th, 2018 11:28 AM
run Step 7 without TIA Portal dmned64 LIVE PLC Questions And Answers 4 June 7th, 2017 06:39 AM
License for TIA Portal ( from S7 to TIA ) Oliver Micka LIVE PLC Questions And Answers 2 November 29th, 2016 07:40 AM
Structured text For/IF DTL - Siemens Tia Portal V11 BartPeters88 LIVE PLC Questions And Answers 2 March 13th, 2015 08:05 AM
Siemens OP77B Trouble in TIA Portal Tim James LIVE PLC Questions And Answers 4 December 24th, 2012 03:27 PM


All times are GMT -5. The time now is 07:56 AM.


.