[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.
Solved! Go to Solution.
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;
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.
@kvacola 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?
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.
Discuss challenges in energy and automation with 30,000+ experts and peers.
Find answers in 10,000+ support articles to help solve your product and business challenges.
Find peer based solutions to your questions. Provide answers for fellow community members!