11<?xml version =" 1.0" encoding =" utf-8" ?>
22<project xmlns =" http://www.plcopen.org/xml/tc6_0200" >
3- <fileHeader companyName =" Prosoft-Systems Ltd." productName =" Astra.IDE" productVersion =" Astra.IDE_V1.7.2.1" creationDateTime =" 2025-06-20T14:16:31.7776024 " />
4- <contentHeader name =" Anjlab Code Box" version =" 3.5.17.2 " modificationDateTime =" 2025-06-20T14:16:17.3483429 " organization =" Anjlab" author =" Sergey A Glukhov" >
3+ <fileHeader companyName =" Prosoft-Systems Ltd." productName =" Astra.IDE" productVersion =" Astra.IDE_V1.7.2.1" creationDateTime =" 2025-07-18T09:58:00.1972721 " />
4+ <contentHeader name =" Anjlab Code Box" version =" 3.5.17.3 " modificationDateTime =" 2025-07-18T09:54:53.7808919 " organization =" Anjlab" author =" Sergey A Glukhov" >
55 <Comment >Comprehensive PLC Utility Library for CoDeSys</Comment >
66 <coordinateInfo >
77 <fbd >
3232 <property name =" SourceCode" type =" string" >https://github.com/anjlab/codebox</property >
3333 <property name =" SourceLibrary" type =" boolean" >false</property >
3434 <property name =" Title" type =" string" >Anjlab Code Box</property >
35- <property name =" Version" type =" version" >3.5.17.2 </property >
35+ <property name =" Version" type =" version" >3.5.17.3 </property >
3636 <property name =" library-category-list" type =" library-category-list" />
3737 </ProjectInformation >
3838 </data >
@@ -379,7 +379,7 @@ IF NOT isInitialized OR reset THEN
379379 RETURN;
380380END_IF;
381381
382- IF counter > = bufferSize THEN
382+ IF counter > bufferSize THEN
383383 counter := 1;
384384ELSE
385385 counter := counter + 1;
@@ -862,12 +862,12 @@ pulseTimer(in := clock.output, PT := pulseWidth, Q => output);</xhtml>
862862 <xhtml xmlns =" http://www.w3.org/1999/xhtml" >midday := SunMidday(longitude, currentTime);
863863b := latitude * 0.0174532925199433;
864864dk := 0.40954 * SIN(0.0172 * (UINT_TO_REAL(DayOfYear(currentTime)) - 79.35));
865- sunDeclination := DegreesToRadians (DK);
865+ sunDeclination := RadiansToDegrees (DK);
866866IF sunDeclination > 180.0 THEN
867867 sunDeclination := sunDeclination - 360.0;
868868END_IF;
869869sunDeclination := 90.0 - latitude + sunDeclination;
870- delta := HourToTime(REAL_TO_INT(ACOS((SIN(RadiansToDegrees (h)) - SIN(b) * SIN(dk)) / (COS(b) * COS(dk))) * 3.819718632));
870+ delta := HourToTime(REAL_TO_INT(ACOS((SIN(DegreesToRadians (h)) - SIN(b) * SIN(dk)) / (COS(b) * COS(dk))) * 3.819718632));
871871sunRise := midday - delta;
872872sunSet := midday + delta;</xhtml >
873873 </ST >
@@ -1101,9 +1101,9 @@ END_IF;</xhtml>
11011101 <body >
11021102 <ST >
11031103 <xhtml xmlns =" http://www.w3.org/1999/xhtml" >IF ABS(input) < 2.0E9 THEN
1104- FRACT := input - DINT_TO_REAL(DTrunc(input));
1104+ Fract := ABS( input - DINT_TO_REAL(DTrunc(input) ));
11051105ELSE
1106- FRACT := 0.0;
1106+ Fract := 0.0;
11071107END_IF;</xhtml >
11081108 </ST >
11091109 </body >
@@ -1187,7 +1187,7 @@ END_IF;
11871187 </interface >
11881188 <body >
11891189 <ST >
1190- <xhtml xmlns =" http://www.w3.org/1999/xhtml" >Round := DWORD_TO_REAL(REAL_TO_DWORD (input * Exp10(precision))) / Exp10(precision);
1190+ <xhtml xmlns =" http://www.w3.org/1999/xhtml" >Round := DINT_TO_REAL(REAL_TO_DINT (input * Exp10(precision))) / Exp10(precision);
11911191</xhtml >
11921192 </ST >
11931193 </body >
@@ -1276,27 +1276,49 @@ END_IF;
12761276 <REAL />
12771277 </returnType >
12781278 <inputVars >
1279- <variable name =" radians " >
1279+ <variable name =" degrees " >
12801280 <type >
12811281 <REAL />
12821282 </type >
12831283 <documentation >
1284- <xhtml xmlns =" http://www.w3.org/1999/xhtml" > Input value in radians </xhtml >
1284+ <xhtml xmlns =" http://www.w3.org/1999/xhtml" > Input value in degrees </xhtml >
12851285 </documentation >
12861286 </variable >
12871287 </inputVars >
1288+ <localVars >
1289+ <variable name =" timeNow" >
1290+ <type >
1291+ <DWORD />
1292+ </type >
1293+ </variable >
1294+ <variable name =" timeCount" >
1295+ <type >
1296+ <INT />
1297+ </type >
1298+ </variable >
1299+ </localVars >
1300+ <localVars constant =" true" >
1301+ <variable name =" pi" >
1302+ <type >
1303+ <REAL />
1304+ </type >
1305+ <initialValue >
1306+ <simpleValue value =" 3.1415926535897931" />
1307+ </initialValue >
1308+ </variable >
1309+ </localVars >
12881310 <documentation >
1289- <xhtml xmlns =" http://www.w3.org/1999/xhtml" > Converts radians to degrees. </xhtml >
1311+ <xhtml xmlns =" http://www.w3.org/1999/xhtml" > Converts degrees to radians </xhtml >
12901312 </documentation >
12911313 </interface >
12921314 <body >
12931315 <ST >
1294- <xhtml xmlns =" http://www.w3.org/1999/xhtml" >DegreesToRadians := ModR(57.29577951308232 * radians, 360.0 );</xhtml >
1316+ <xhtml xmlns =" http://www.w3.org/1999/xhtml" >DegreesToRadians := ModR(0.0174532925199433 * degrees, pi*2 );</xhtml >
12951317 </ST >
12961318 </body >
12971319 <addData >
12981320 <data name =" http://www.3s-software.com/plcopenxml/objectid" handleUnknown =" discard" >
1299- <ObjectId >4981396d-e136-4432-9a71-2aaee415565e </ObjectId >
1321+ <ObjectId >ed9aeab3-29c3-4d5f-9dc8-19fc9c76a64e </ObjectId >
13001322 </data >
13011323 </addData >
13021324 </pou >
@@ -1439,49 +1461,27 @@ END_IF;
14391461 <REAL />
14401462 </returnType >
14411463 <inputVars >
1442- <variable name =" degrees " >
1464+ <variable name =" radians " >
14431465 <type >
14441466 <REAL />
14451467 </type >
14461468 <documentation >
1447- <xhtml xmlns =" http://www.w3.org/1999/xhtml" > Input value in degrees </xhtml >
1469+ <xhtml xmlns =" http://www.w3.org/1999/xhtml" > Input value in radians </xhtml >
14481470 </documentation >
14491471 </variable >
14501472 </inputVars >
1451- <localVars >
1452- <variable name =" timeNow" >
1453- <type >
1454- <DWORD />
1455- </type >
1456- </variable >
1457- <variable name =" timeCount" >
1458- <type >
1459- <INT />
1460- </type >
1461- </variable >
1462- </localVars >
1463- <localVars constant =" true" >
1464- <variable name =" pi" >
1465- <type >
1466- <REAL />
1467- </type >
1468- <initialValue >
1469- <simpleValue value =" 3.1415926535897931" />
1470- </initialValue >
1471- </variable >
1472- </localVars >
14731473 <documentation >
1474- <xhtml xmlns =" http://www.w3.org/1999/xhtml" > Converts degrees to radians </xhtml >
1474+ <xhtml xmlns =" http://www.w3.org/1999/xhtml" > Converts radians to degrees. </xhtml >
14751475 </documentation >
14761476 </interface >
14771477 <body >
14781478 <ST >
1479- <xhtml xmlns =" http://www.w3.org/1999/xhtml" >RadiansToDegrees := ModR(0.0174532925199433 * degrees, pi*2 );</xhtml >
1479+ <xhtml xmlns =" http://www.w3.org/1999/xhtml" >RadiansToDegrees := ModR(57.29577951308232 * radians, 360.0 );</xhtml >
14801480 </ST >
14811481 </body >
14821482 <addData >
14831483 <data name =" http://www.3s-software.com/plcopenxml/objectid" handleUnknown =" discard" >
1484- <ObjectId >ed9aeab3-29c3-4d5f-9dc8-19fc9c76a64e </ObjectId >
1484+ <ObjectId >4981396d-e136-4432-9a71-2aaee415565e </ObjectId >
14851485 </data >
14861486 </addData >
14871487 </pou >
@@ -2232,9 +2232,9 @@ END_IF;</xhtml>
22322232 <ST >
22332233 <xhtml xmlns =" http://www.w3.org/1999/xhtml" >// Get date as a string like 'D#2000-01-01'
22342234sTemp := DATE_TO_STRING(input);
2235- year := STRING_TO_UINT(MID(sTemp, 3, 4 ));
2236- month := STRING_TO_UINT(MID(sTemp, 8, 2 ));
2237- day := STRING_TO_UINT(MID(sTemp, 11, 2 ));
2235+ year := STRING_TO_UINT(MID(sTemp, 4, 3 ));
2236+ month := STRING_TO_UINT(MID(sTemp, 2, 8 ));
2237+ day := STRING_TO_UINT(MID(sTemp, 2, 11 ));
22382238
22392239DateToElements := true;</xhtml >
22402240 </ST >
@@ -2594,7 +2594,7 @@ DaysTillYear := year * 365 + ((year + 1) / 4) - ((year + 69) / 100) + ((year + 3
25942594 </interface >
25952595 <body >
25962596 <ST >
2597- <xhtml xmlns =" http://www.w3.org/1999/xhtml" >HourToTod := TOD#00:00:00 + T#1h * hours;</xhtml >
2597+ <xhtml xmlns =" http://www.w3.org/1999/xhtml" >HourToTod := TOD#00:00:00 + T#1h * ( hours MOD 24) ;</xhtml >
25982598 </ST >
25992599 </body >
26002600 <addData >
@@ -2735,11 +2735,12 @@ SunMidday := HourToTod(REAL_TO_INT(12.0 - offset - longitude * 0.0666666666666))
27352735 </interface >
27362736 <body >
27372737 <ST >
2738- <xhtml xmlns =" http://www.w3.org/1999/xhtml" >// Now the time is a string like 'TOD#12:12:59'
2738+ <xhtml xmlns =" http://www.w3.org/1999/xhtml" >// Now the time is a string like 'TOD#12:12:59.001 '
27392739sTemp := TOD_TO_STRING(TIME_TO_TOD(input));
2740- h := STRING_TO_UINT(MID(sTemp, 5, 2));
2741- m := STRING_TO_UINT(MID(sTemp, 8, 2));
2742- sec := STRING_TO_UINT(MID(sTemp, 11, 2));
2740+ h := STRING_TO_UINT(MID(sTemp, 2, 5));
2741+ m := STRING_TO_UINT(MID(sTemp, 2, 8));
2742+ sec := STRING_TO_UINT(MID(sTemp, 2, 11));
2743+ ms := STRING_TO_UINT(MID(sTemp, 3, 14));
27432744TimeToElements := TRUE;</xhtml >
27442745 </ST >
27452746 </body >
@@ -2755,23 +2756,23 @@ TimeToElements := TRUE;</xhtml>
27552756 <BOOL />
27562757 </returnType >
27572758 <inputVars >
2758- <variable name =" CurrTime " >
2759+ <variable name =" currentTOD " >
27592760 <type >
27602761 <TOD />
27612762 </type >
27622763 <documentation >
27632764 <xhtml xmlns =" http://www.w3.org/1999/xhtml" > Current time </xhtml >
27642765 </documentation >
27652766 </variable >
2766- <variable name =" FromTime " >
2767+ <variable name =" fromTOD " >
27672768 <type >
27682769 <TOD />
27692770 </type >
27702771 <documentation >
27712772 <xhtml xmlns =" http://www.w3.org/1999/xhtml" > Lower bound </xhtml >
27722773 </documentation >
27732774 </variable >
2774- <variable name =" ToTime " >
2775+ <variable name =" toTOD " >
27752776 <type >
27762777 <TOD />
27772778 </type >
@@ -2787,8 +2788,8 @@ TimeToElements := TRUE;</xhtml>
27872788 <body >
27882789 <ST >
27892790 <xhtml xmlns =" http://www.w3.org/1999/xhtml" >TodBetween := (
2790- FromTime > ToTime AND (CurrTime > FromTime OR CurrTime < ToTime )
2791- ) OR (FromTime < ToTime AND (CurrTime < ToTime AND CurrTime > FromTime )
2791+ fromTOD > toTOD AND (currentTOD > fromTOD OR currentTOD < toTOD )
2792+ ) OR (fromTOD < toTOD AND (currentTOD < toTOD AND currentTOD > fromTOD )
27922793);
27932794</xhtml >
27942795 </ST >
@@ -2805,15 +2806,15 @@ TimeToElements := TRUE;</xhtml>
28052806 <TIME />
28062807 </returnType >
28072808 <inputVars >
2808- <variable name =" FromTime " >
2809+ <variable name =" fromTOD " >
28092810 <type >
28102811 <TOD />
28112812 </type >
28122813 <documentation >
28132814 <xhtml xmlns =" http://www.w3.org/1999/xhtml" > Lower bound </xhtml >
28142815 </documentation >
28152816 </variable >
2816- <variable name =" ToTime " >
2817+ <variable name =" toTOD " >
28172818 <type >
28182819 <TOD />
28192820 </type >
@@ -2823,15 +2824,15 @@ TimeToElements := TRUE;</xhtml>
28232824 </variable >
28242825 </inputVars >
28252826 <documentation >
2826- <xhtml xmlns =" http://www.w3.org/1999/xhtml" > Calculate the difference between timestamps </xhtml >
2827+ <xhtml xmlns =" http://www.w3.org/1999/xhtml" > Calculate the difference between TODs in TIME </xhtml >
28272828 </documentation >
28282829 </interface >
28292830 <body >
28302831 <ST >
2831- <xhtml xmlns =" http://www.w3.org/1999/xhtml" >IF ToTime < FromTime THEN
2832- TodDiff := T#24H - TOD_TO_TIME(FromTime ) + TOD_TO_TIME(ToTime );
2832+ <xhtml xmlns =" http://www.w3.org/1999/xhtml" >IF toTOD < fromTOD THEN
2833+ TodDiff := T#24H - TOD_TO_TIME(fromTOD ) + TOD_TO_TIME(toTOD );
28332834ELSE
2834- TodDiff := ToTime - FromTime ;
2835+ TodDiff := toTOD - fromTOD ;
28352836END_IF</xhtml >
28362837 </ST >
28372838 </body >
@@ -2862,7 +2863,7 @@ END_IF</xhtml>
28622863 </interface >
28632864 <body >
28642865 <ST >
2865- <xhtml xmlns =" http://www.w3.org/1999/xhtml" >WeekOfYear := (( DayOfYear(currentDate) + 6) / 7) ;
2866+ <xhtml xmlns =" http://www.w3.org/1999/xhtml" >WeekOfYear := (DayOfYear(currentDate) + 6) / 7;
28662867IF DayOfWeek(currentDate) < DayOfWeek(YearStarts(currentDate)) THEN
28672868 WeekOfYear := WeekOfYear + 1;
28682869END_IF;</xhtml >
@@ -2906,7 +2907,7 @@ END_IF;</xhtml>
29062907 <body >
29072908 <ST >
29082909 <xhtml xmlns =" http://www.w3.org/1999/xhtml" >str := DATE_TO_STRING(currentDate);
2909- YearStarts := STRING_TO_DATE(CONCAT(CONCAT('D#', MID(str, 3, 4 )), '-01-01'));</xhtml >
2910+ YearStarts := STRING_TO_DATE(CONCAT(CONCAT('D#', MID(str, 4, 3 )), '-01-01'));</xhtml >
29102911 </ST >
29112912 </body >
29122913 <addData >
@@ -2915,7 +2916,7 @@ YearStarts := STRING_TO_DATE(CONCAT(CONCAT('D#', MID(str, 3, 4)), '-01-01'));</x
29152916 </data >
29162917 </addData >
29172918 </pou >
2918- <pou name =" YmdhmsTodt " pouType =" function" >
2919+ <pou name =" YmdhmsToDt " pouType =" function" >
29192920 <interface >
29202921 <returnType >
29212922 <DT />
@@ -2998,11 +2999,11 @@ sTemp := CONCAT(sTemp, '-');
29982999sTemp := CONCAT(sTemp, UINT_TO_STRING(d));
29993000sTemp := CONCAT(sTemp, '-');
30003001sTemp := CONCAT(sTemp, UINT_TO_STRING(h));
3001- sTemp := CONCAT(sTemp, '- ');
3002+ sTemp := CONCAT(sTemp, ': ');
30023003sTemp := CONCAT(sTemp, UINT_TO_STRING(m));
3003- sTemp := CONCAT(sTemp, '- ');
3004+ sTemp := CONCAT(sTemp, ': ');
30043005sTemp := CONCAT(sTemp, UINT_TO_STRING(sec));
3005- sTemp := CONCAT(sTemp, '- ');
3006+ sTemp := CONCAT(sTemp, '. ');
30063007sTemp := CONCAT(sTemp, UINT_TO_STRING(ms));
30073008YmdhmsTodt := STRING_TO_DT(sTemp);</xhtml >
30083009 </ST >
@@ -3134,7 +3135,7 @@ END_WHILE;</xhtml>
31343135 <INT />
31353136 </type >
31363137 <documentation >
3137- <xhtml xmlns =" http://www.w3.org/1999/xhtml" > Which bit number </xhtml >
3138+ <xhtml xmlns =" http://www.w3.org/1999/xhtml" > Which bit number (zero-padded) </xhtml >
31383139 </documentation >
31393140 </variable >
31403141 </inputVars >
@@ -3150,7 +3151,7 @@ END_WHILE;</xhtml>
31503151 </localVars >
31513152 <documentation >
31523153 <xhtml xmlns =" http://www.w3.org/1999/xhtml" > Loads one bit value into a byte.
3153- bit_load_b(2#0000_0000, 1, 2 ) = 2#0000_0010 </xhtml >
3154+ bit_load_b(2#0000_0000, 1, 3 ) = 2#0000_1000 </xhtml >
31543155 </documentation >
31553156 </interface >
31563157 <body >
@@ -3547,14 +3548,14 @@ Random := FRACT(DWORD_TO_REAL(tn) / 10000000.0 *
35473548 </Folder >
35483549 <Folder Name =" Functions" >
35493550 <Folder Name =" Physics" >
3550- <Object Name =" DegreesToRadians " ObjectId =" 4981396d-e136-4432-9a71-2aaee415565e" />
3551+ <Object Name =" RadiansToDegrees " ObjectId =" 4981396d-e136-4432-9a71-2aaee415565e" />
35513552 <Object Name =" CelciusToFarenheit" ObjectId =" 7f5d796b-74a9-421e-bd0e-9267c5a44f76" />
35523553 <Object Name =" CelciusToKelvin" ObjectId =" 0b238ef8-5d8d-4a08-8ea0-8b0731782a91" />
35533554 <Object Name =" FarenheitToCelcius" ObjectId =" e90ecedc-3b3d-421c-9673-f59db8c05ffd" />
35543555 <Object Name =" KmhToMs" ObjectId =" b26a4465-6ef2-4dc8-b751-aebd4e2f2f56" />
35553556 <Object Name =" KelvinToCelcius" ObjectId =" e1affddf-5581-4627-8d61-7f2a7f2ca0fa" />
35563557 <Object Name =" MsToKmh" ObjectId =" 21dd1116-5d67-493d-8c77-5b380095d556" />
3557- <Object Name =" RadiansToDegrees " ObjectId =" ed9aeab3-29c3-4d5f-9dc8-19fc9c76a64e" />
3558+ <Object Name =" DegreesToRadians " ObjectId =" ed9aeab3-29c3-4d5f-9dc8-19fc9c76a64e" />
35583559 </Folder >
35593560 <Folder Name =" Time" >
35603561 <Object Name =" DaysTillMonth" ObjectId =" 67d1a212-1ccc-457e-b16d-c7e461443b5b" />
@@ -3564,7 +3565,7 @@ Random := FRACT(DWORD_TO_REAL(tn) / 10000000.0 *
35643565 <Object Name =" TodDiff" ObjectId =" 50bec7af-ee3d-4afd-9afc-57186a003144" />
35653566 <Object Name =" WeekOfYear" ObjectId =" 67cc401c-9be4-42bc-a783-173878e795d0" />
35663567 <Object Name =" YearStarts" ObjectId =" f574b5de-a869-4215-82cd-296f58bbc331" />
3567- <Object Name =" YmdhmsTodt " ObjectId =" e464deaa-a738-4c18-a017-c8f42f407d70" />
3568+ <Object Name =" YmdhmsToDt " ObjectId =" e464deaa-a738-4c18-a017-c8f42f407d70" />
35683569 <Object Name =" HmsToTime" ObjectId =" 49706012-99ad-4259-bff9-b7c36e2caa74" />
35693570 <Object Name =" HourToTime" ObjectId =" 93ab5816-722a-4fe0-b453-14d79d5f96e7" />
35703571 <Object Name =" HourToTod" ObjectId =" ddb9ff52-023f-4749-8919-0e0538454a46" />
0 commit comments