EcoStruxure Geo SCADA Expert Forum
Schneider Electric support forum about installation, configuration, integration and troubleshooting of EcoStruxure Geo SCADA Expert (ClearSCADA, ViewX, WebX).
Posted: 2020-03-03 10:57 AM . Last Modified: 2023-05-03 12:16 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2020-03-03 10:57 AM . Last Modified: 2023-05-03 12:16 AM
[Using ClearSCADA 2017 R3]
I have a structured text program that is calculating a date and time from 2 FloBoss integers. INT1 is the Date (without year) and is a 4-digit value (e.g. 0226). INT2 is the 4-digit Time in 24h format (e.g. 1442). I've successfully gotten to the point in my ST program where I have the date. Unfortunately for dates that straddle the year for this device, I need to be able to subtract 1 year from the date. I use the current date and time to extract 'YEAR' and do a couple of concatenations to get the time:
dtDate := MAKE_DATE(YEAR, STRING_TO_SINT(strMonth), STRING_TO_SINT(strDay));
dtTime := MAKE_TIME_OF_DAY(STRING_TO_SINT(strHour), STRING_TO_SINT(strMins), 0, 0);
DATETIME := CONCAT_D_TOD(dtDate, dtTime);
But the final function that compares the current time to the calculated time is giving me the error 'Program Error: Invalid conversion'
IF DATETIME > dtCurrentTime THEN
DATETIME := SUB_DT_TIME(DATETIME, STRING_TO_TIME('D#1y'));
END_IF;
The program compiles just fine, I only get the error when I execute the program.
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2020-03-03 11:23 PM
Might have been able to get away with:
DATETIME := SUB_DT_TIME(DATETIME, T#365d);
Although would need to take leap years into account.
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2020-03-03 12:08 PM . Last Modified: 2020-03-03 12:09 PM
If these are all INTs... why are you doing anything with STRINGs?
CURR_INT1 := EXTRACT_DT_MONTH(NOW()) * 100 + EXTRACT_DT_DAY(NOW());
CURR_INT2 := EXTRACT_DT_HOUR(NOW()) *100 + EXTRACT_DT_MINUTE(NOW());
IF( CURR_INT1 > INT1 OR (CURR_INT1 = INT1 AND CURR_INT2 >= INT2)) THEN
(* Our datetime event was this year.. *)
(* We don't care about Seconds / Milliseconds, so set these to zero *)
(* INT1 = MMDD, INT2 = HHMM *)
DATETIME := MAKE_DATE_AND_TIME( YEAR, DIV( INT1, 100), MOD(INT1,100), DIV(INT2,100), MOD(INT2,100), 0, 0 );
ELSE
(* our datetime event was last year *)
(* We don't care about Seconds / Milliseconds, so set these to zero *)
(* INT1 = MMDD, INT2 = HHMM *)
DATETIME := MAKE_DATE_AND_TIME( YEAR - 1, DIV( INT1, 100), MOD(INT1,100), DIV(INT2,100), MOD(INT2,100), 0, 0 );
END_IF;
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2020-03-03 12:57 PM
That did the trick! Thanks so much. I though I'd have to convert to strings to parse off the month/day and hour/min.
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2020-03-03 11:23 PM
Might have been able to get away with:
DATETIME := SUB_DT_TIME(DATETIME, T#365d);
Although would need to take leap years into account.
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2020-03-03 11:37 PM
@Anonymous user How did you get somewhat good syntax colouring on your ST Logic text? Did you have to colour it yourself?
@AdamWoodland It is a little frustrating that the logic engine (and many parts of ClearSCADA) can't do subtraction of things like months / years etc (conceptual time periods). I was a bit afraid that 1year in days would overflow the holding of the 'Time' datatype. What is the extent of what it can hold?
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2020-03-04 02:21 AM
That was 'C' language colouring. Colours function names red but is unaware of (* *) comments.
Time and its text representations support, for example, a century's worth of seconds in Adam's example.
Link copied. Please paste this link to share this article on your social media post.
Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.