diff --git a/.copilot/settings.txt b/.copilot/settings.txt new file mode 100644 index 0000000..39a29db --- /dev/null +++ b/.copilot/settings.txt @@ -0,0 +1,98 @@ +// Settings for Copilot usage in this project + +// 1. Code Generation Guidelines: +// - Always generate code in IEC61131-3 Structured Text (ST) format. +// - All functions must include inline documentation in the following format: +// /// +// /// Input: +// /// Returns: +// Example: +// /// Converts a subset of a CHAR array to a string. +// /// Input: arr - Input CHAR array to convert. +// /// startIdx - Start index of the subset. +// /// endIdx - End index of the subset. +// /// Returns: A string representation of the specified subset of the CHAR array. +// FUNCTION ToString : STRING +// VAR_INPUT +// arr : ARRAY[*] OF CHAR; // Input CHAR array to convert +// startIdx : INT; // Start index of the subset +// endIdx : INT; // End index of the subset +// END_VAR +// ; +// END_FUNCTION + +// 2. Unit Test Guidelines: +// Test-Files shall be stored in the folder `test`. +// - Use AxUnit for unit testing. +// - Tests should follow the structure below: +// - {TestFixture} to define a test class. +// - {Test} for individual test methods. +// - Support parameterized tests using {Test(...)} annotations. +// Example: +// USING AxUnit.Assert; +// NAMESPACE AnyNamespace +// {TestFixture} +// CLASS TestClass +// VAR +// val : LINT; +// val2 : ULINT; +// res : BOOL; +// END_VAR +// +// {Test} +// METHOD PUBLIC Convert_STRING_0_TO_LINT_0 +// res := StringToAnyInt(str := '0', value => val); +// Equal(expected := 0, actual := val); +// Equal(expected := TRUE, actual := res); +// END_METHOD +// +// {Test(str := STRING#'18446744073709551746', value := ULINT#0, success := FALSE)} +// {Test(str := STRING#'18446744073709551800', value := ULINT#0, success := FALSE)} +// METHOD PUBLIC Convert_STRING_TO_ULINT +// VAR_INPUT +// str : STRING; +// value : ULINT; +// success : BOOL; +// END_VAR +// VAR_TEMP +// resVal : ULINT; +// END_VAR +// res := StringToULint(str := str, value => resVal); +// Equal(expected := value, actual := resVal); +// Equal(expected := success, actual := res); +// END_METHOD +// END_CLASS +// END_NAMESPACE + +// 3. Documentation Rules: +// - All types, functions, and methods must include inline documentation. +// - Use the following format for documentation: +// /// +// /// Input: +// /// Returns: +// - Ensure that all parameters and return values are clearly described. + +// 4. File Organization Rules: +// - Place all source files in the `src` folder. +// - Place all test files in the `test` folder. +// - Use descriptive filenames that reflect the functionality of the file. + +// 5. Naming Conventions: +// - Use PascalCase for function and type names (e.g., `ToString`, `SimotionDateTime`). + +// 6. Code Format Rules: +// - Always generate code in IEC61131-3 Structured Text (ST) format. + +// 7. Constant Declaration Rules: +// - Constants, except for `INT`, `BOOL` and `LREAL`, must always include explicit type annotations. +// Examples: +// - REAL#1.0 +// - ULINT#1 +// - SINT#23 + +// 8. Return Statement Rules: +// - `RETURN` cannot take a return value. +// - Return values must always be assigned to the function or method name before using `RETURN`. +// Example: +// FunctionName := ReturnValue; +// RETURN; diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..12de256 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "conventionalCommits.scopes": [ + "deps" + ] +} \ No newline at end of file diff --git a/src/TRUNC.st b/src/TRUNC.st index 699ca62..cce0240 100644 --- a/src/TRUNC.st +++ b/src/TRUNC.st @@ -1,5 +1,12 @@ NAMESPACE Simatic.Ax.Conversion + /// Truncates a 64-bit floating-point number (LREAL) to an integer. + /// + /// This function truncates the input LREAL value to the nearest integer toward zero. + /// It handles both positive and negative values. + /// + /// @param Value The LREAL value to truncate. + /// @return The truncated integer value. FUNCTION TRUNC : DINT VAR_INPUT Value : LREAL; @@ -16,6 +23,13 @@ NAMESPACE Simatic.Ax.Conversion END_IF; END_FUNCTION + /// Truncates a 32-bit floating-point number (REAL) to an integer. + /// + /// This function truncates the input REAL value to the nearest integer toward zero. + /// It handles both positive and negative values. + /// + /// @param Value The REAL value to truncate. + /// @return The truncated integer value. FUNCTION TRUNC : DINT VAR_INPUT Value : REAL; @@ -31,4 +45,5 @@ NAMESPACE Simatic.Ax.Conversion END_IF; END_IF; END_FUNCTION + END_NAMESPACE diff --git a/src/strings/AnyIntToString.st b/src/strings/AnyIntToString.st index 20e53a3..584a70a 100644 --- a/src/strings/AnyIntToString.st +++ b/src/strings/AnyIntToString.st @@ -2,6 +2,16 @@ USING System.Strings; USING System.Math; NAMESPACE Simatic.Ax.Conversion + + /// Converts a signed 64-bit integer (LINT) to its string representation. + /// + /// This function converts a signed 64-bit integer to a string, optionally adding a sign + /// based on the specified conversion mode. It handles negative values and ensures the + /// correct number of digits are included in the output. + /// + /// @param value The signed 64-bit integer to convert. + /// @param mode The conversion mode (e.g., force sign). + /// @return A string representation of the input integer. FUNCTION INTERNAL AnyIntToString : STRING VAR_INPUT value : LINT; @@ -42,6 +52,15 @@ NAMESPACE Simatic.Ax.Conversion END_FOR; END_FUNCTION + /// Converts an unsigned 64-bit integer (ULINT) to its string representation. + /// + /// This function converts an unsigned 64-bit integer to a string, optionally adding a sign + /// based on the specified conversion mode. It ensures the correct number of digits are + /// included in the output. + /// + /// @param value The unsigned 64-bit integer to convert. + /// @param mode The conversion mode (e.g., force sign). + /// @return A string representation of the input integer. FUNCTION INTERNAL ULintToString : STRING VAR_INPUT value : ULINT; @@ -80,4 +99,5 @@ NAMESPACE Simatic.Ax.Conversion ULintToString := Concat(ULintToString, s); END_FOR; END_FUNCTION + END_NAMESPACE \ No newline at end of file diff --git a/src/strings/ArrayToString.st b/src/strings/ArrayToString.st index 9650c77..9b85185 100644 --- a/src/strings/ArrayToString.st +++ b/src/strings/ArrayToString.st @@ -1,6 +1,18 @@ USING System.Strings; NAMESPACE Simatic.Ax.Conversion.Arrays + + /// Converts a subset of a character array to a string. + /// + /// This function takes a character array and converts a specified range of elements + /// (from `startIdx` to `endIdx`) into a string. If the range is invalid or exceeds + /// the array bounds, an empty string is returned. The maximum string length is limited + /// to `MAX_STR_LEN`. + /// + /// @param arr The input character array. + /// @param startIdx The starting index of the range to convert. + /// @param endIdx The ending index of the range to convert. + /// @return A string representation of the specified range of the array. FUNCTION ToString : STRING VAR_INPUT arr : ARRAY[*] OF CHAR; @@ -47,6 +59,14 @@ NAMESPACE Simatic.Ax.Conversion.Arrays END_FUNCTION + /// Converts an entire character array to a string. + /// + /// This function takes a character array and converts all its elements into a string. + /// If the array length exceeds `MAX_STR_LEN`, the resulting string is truncated to + /// the maximum allowed length. + /// + /// @param arr The input character array. + /// @return A string representation of the entire array. FUNCTION ToString : STRING VAR_INPUT arr : ARRAY[*] OF CHAR; @@ -74,4 +94,5 @@ NAMESPACE Simatic.Ax.Conversion.Arrays END_FOR; END_FUNCTION + END_NAMESPACE \ No newline at end of file diff --git a/src/strings/ConversionMode.st b/src/strings/ConversionMode.st index 46982e5..d012fb7 100644 --- a/src/strings/ConversionMode.st +++ b/src/strings/ConversionMode.st @@ -1,5 +1,12 @@ NAMESPACE Simatic.Ax.Conversion + + /// Represents the conversion mode for integer-to-string operations. + /// + /// This type defines the available modes for formatting integer-to-string conversions: + /// - `NONE`: No special formatting is applied. + /// - `FORCE_SIGN`: Forces the inclusion of a '+' sign for positive numbers. TYPE ConversionMode : WORD (NONE := WORD#16#0000, FORCE_SIGN := WORD#16#0001) := NONE; END_TYPE + END_NAMESPACE \ No newline at end of file diff --git a/src/strings/CountDigits.st b/src/strings/CountDigits.st index ad337a9..1478304 100644 --- a/src/strings/CountDigits.st +++ b/src/strings/CountDigits.st @@ -1,4 +1,13 @@ NAMESPACE Simatic.Ax.Conversion + + /// Counts the number of digits in a signed 64-bit integer (LINT). + /// + /// This function calculates the number of decimal digits in the given signed 64-bit integer. + /// It iteratively checks the range of the value against increasing powers of 10. + /// The maximum number of digits it can handle is defined by `MAX_DIGITS`. + /// + /// @param value The signed 64-bit integer whose digits are to be counted. + /// @return The number of decimal digits in the input value. FUNCTION CountDigits : INT VAR_INPUT value : LINT; @@ -21,6 +30,14 @@ NAMESPACE Simatic.Ax.Conversion CountDigits := 19; END_FUNCTION + /// Counts the number of digits in an unsigned 64-bit integer (ULINT). + /// + /// This function calculates the number of decimal digits in the given unsigned 64-bit integer. + /// It iteratively checks the range of the value against increasing powers of 10. + /// The maximum number of digits it can handle is defined by `MAX_DIGITS`. + /// + /// @param value The unsigned 64-bit integer whose digits are to be counted. + /// @return The number of decimal digits in the input value. FUNCTION CountDigits : INT VAR_INPUT value : ULINT; @@ -42,4 +59,5 @@ NAMESPACE Simatic.Ax.Conversion END_FOR; CountDigits := 20; END_FUNCTION + END_NAMESPACE \ No newline at end of file diff --git a/src/strings/HexToString.st b/src/strings/HexToString.st index bc54146..00169d6 100644 --- a/src/strings/HexToString.st +++ b/src/strings/HexToString.st @@ -2,7 +2,15 @@ USING System; USING System.Strings; NAMESPACE Simatic.Ax.Conversion - + + /// Converts a BYTE value to its hexadecimal string representation. + /// + /// This function takes a BYTE value and converts it into a two-character hexadecimal string. + /// It splits the BYTE into two nibbles, converts each nibble to its hexadecimal character, + /// and concatenates the results. + /// + /// @param b The BYTE value to convert. + /// @return A two-character string representing the hexadecimal value of the input BYTE. FUNCTION PUBLIC ByteToString : STRING VAR_INPUT b : BYTE; @@ -18,6 +26,13 @@ NAMESPACE Simatic.Ax.Conversion END_FUNCTION + /// Converts a nibble (4 bits) to its hexadecimal character representation. + /// + /// This function takes a nibble (a value between 0 and 15) and returns the corresponding + /// hexadecimal character (0-9, A-F) using a lookup table. + /// + /// @param nibble The nibble value to convert (0-15). + /// @return The hexadecimal character corresponding to the input nibble. FUNCTION INTERNAL LookUpHEX : CHAR VAR_INPUT nibble : BYTE; diff --git a/src/strings/IntToString.st b/src/strings/IntToString.st index 1d5516d..0b7ef11 100644 --- a/src/strings/IntToString.st +++ b/src/strings/IntToString.st @@ -1,5 +1,15 @@ USING System.Strings; + NAMESPACE Simatic.Ax.Conversion.Integer + + /// Converts a signed 8-bit integer (SINT) to a string. + /// + /// This function converts a signed 8-bit integer to its string representation. + /// The conversion supports an optional mode parameter to customize the output format. + /// + /// @param value The signed 8-bit integer to convert. + /// @param mode The conversion mode (e.g., force sign). + /// @return A string representation of the input integer. FUNCTION ToString : STRING[4] VAR_INPUT value : SINT; @@ -10,6 +20,14 @@ NAMESPACE Simatic.Ax.Conversion.Integer ToString := AnyIntToString(value := value, mode := mode); END_FUNCTION + /// Converts an unsigned 8-bit integer (USINT) to a string. + /// + /// This function converts an unsigned 8-bit integer to its string representation. + /// The conversion supports an optional mode parameter to customize the output format. + /// + /// @param value The unsigned 8-bit integer to convert. + /// @param mode The conversion mode (e.g., force sign). + /// @return A string representation of the input integer. FUNCTION ToString : STRING[4] VAR_INPUT value : USINT; @@ -20,6 +38,14 @@ NAMESPACE Simatic.Ax.Conversion.Integer ToString := AnyIntToString(value := value, mode := mode); END_FUNCTION + /// Converts a signed 16-bit integer (INT) to a string. + /// + /// This function converts a signed 16-bit integer to its string representation. + /// The conversion supports an optional mode parameter to customize the output format. + /// + /// @param value The signed 16-bit integer to convert. + /// @param mode The conversion mode (e.g., force sign). + /// @return A string representation of the input integer. FUNCTION ToString : STRING[6] VAR_INPUT value : INT; @@ -30,6 +56,14 @@ NAMESPACE Simatic.Ax.Conversion.Integer ToString := AnyIntToString(value := value, mode := mode); END_FUNCTION + /// Converts an unsigned 16-bit integer (UINT) to a string. + /// + /// This function converts an unsigned 16-bit integer to its string representation. + /// The conversion supports an optional mode parameter to customize the output format. + /// + /// @param value The unsigned 16-bit integer to convert. + /// @param mode The conversion mode (e.g., force sign). + /// @return A string representation of the input integer. FUNCTION ToString : STRING[6] VAR_INPUT value : UINT; @@ -41,6 +75,14 @@ NAMESPACE Simatic.Ax.Conversion.Integer END_FUNCTION + /// Converts a signed 32-bit integer (DINT) to a string. + /// + /// This function converts a signed 32-bit integer to its string representation. + /// The conversion supports an optional mode parameter to customize the output format. + /// + /// @param value The signed 32-bit integer to convert. + /// @param mode The conversion mode (e.g., force sign). + /// @return A string representation of the input integer. FUNCTION ToString : STRING[11] VAR_INPUT value : DINT; @@ -51,6 +93,14 @@ NAMESPACE Simatic.Ax.Conversion.Integer ToString := AnyIntToString(value := value, mode := mode); END_FUNCTION + /// Converts an unsigned 32-bit integer (UDINT) to a string. + /// + /// This function converts an unsigned 32-bit integer to its string representation. + /// The conversion supports an optional mode parameter to customize the output format. + /// + /// @param value The unsigned 32-bit integer to convert. + /// @param mode The conversion mode (e.g., force sign). + /// @return A string representation of the input integer. FUNCTION ToString : STRING[11] VAR_INPUT value : UDINT; @@ -61,6 +111,14 @@ NAMESPACE Simatic.Ax.Conversion.Integer ToString := AnyIntToString(value := value, mode := mode); END_FUNCTION + /// Converts a signed 64-bit integer (LINT) to a string. + /// + /// This function converts a signed 64-bit integer to its string representation. + /// The conversion supports an optional mode parameter to customize the output format. + /// + /// @param value The signed 64-bit integer to convert. + /// @param mode The conversion mode (e.g., force sign). + /// @return A string representation of the input integer. FUNCTION ToString : STRING[20] VAR_INPUT value : LINT; @@ -71,6 +129,14 @@ NAMESPACE Simatic.Ax.Conversion.Integer ToString := AnyIntToString(value := value, mode := mode); END_FUNCTION + /// Converts an unsigned 64-bit integer (ULINT) to a string. + /// + /// This function converts an unsigned 64-bit integer to its string representation. + /// The conversion supports an optional mode parameter to customize the output format. + /// + /// @param value The unsigned 64-bit integer to convert. + /// @param mode The conversion mode (e.g., force sign). + /// @return A string representation of the input integer. FUNCTION ToString : STRING[21] VAR_INPUT value : ULINT; @@ -80,4 +146,5 @@ NAMESPACE Simatic.Ax.Conversion.Integer END_VAR ToString := ULintToString(value := value, mode := mode); END_FUNCTION + END_NAMESPACE \ No newline at end of file diff --git a/src/strings/StringToAnyInt.st b/src/strings/StringToAnyInt.st index 1b27b15..00e9123 100644 --- a/src/strings/StringToAnyInt.st +++ b/src/strings/StringToAnyInt.st @@ -1,6 +1,15 @@ USING System.Strings; NAMESPACE Simatic.Ax.Conversion + + /// Converts a string to a signed 64-bit integer (LINT). + /// + /// This function parses a string and converts it to a signed 64-bit integer. It handles + /// optional '+' or '-' signs and checks for overflow. If the string is invalid, the + /// function returns FALSE and sets the output to 0. + /// + /// @param str The input string to convert. + /// @return TRUE if the conversion is successful, FALSE otherwise. FUNCTION StringToAnyInt : BOOL VAR_INPUT str : STRING; @@ -80,6 +89,14 @@ NAMESPACE Simatic.Ax.Conversion END_FUNCTION + /// Converts a string to an unsigned 64-bit integer (ULINT). + /// + /// This function parses a string and converts it to an unsigned 64-bit integer. It handles + /// optional '+' signs and checks for overflow. If the string is invalid, the function + /// returns FALSE and sets the output to 0. + /// + /// @param str The input string to convert. + /// @return TRUE if the conversion is successful, FALSE otherwise. FUNCTION INTERNAL StringToULint: BOOL VAR_INPUT str : STRING; diff --git a/src/strings/StringToArrayOfCharCount.st b/src/strings/StringToArrayOfCharCount.st index 0918960..d5571f2 100644 --- a/src/strings/StringToArrayOfCharCount.st +++ b/src/strings/StringToArrayOfCharCount.st @@ -1,6 +1,16 @@ USING System.Strings; NAMESPACE Simatic.Ax.Conversion.Strings.ToArray + + /// Converts a string to an array of CHAR values. + /// + /// This function copies characters from the input string into the provided array of CHAR. + /// It returns the number of characters copied. If the array is smaller than the string, + /// the output is truncated to fit the array size. + /// + /// @param str The input string to convert. + /// @param arr The output array to store the CHAR values. + /// @return The number of characters copied to the array. FUNCTION OfCharCount : DINT VAR_INPUT str : STRING; @@ -27,4 +37,5 @@ NAMESPACE Simatic.Ax.Conversion.Strings.ToArray END_FOR; OfCharCount := i; END_FUNCTION + END_NAMESPACE \ No newline at end of file diff --git a/src/strings/StringToArrayOfLint.st b/src/strings/StringToArrayOfLint.st index e0e5528..683db9a 100644 --- a/src/strings/StringToArrayOfLint.st +++ b/src/strings/StringToArrayOfLint.st @@ -3,6 +3,14 @@ USING System.Strings; NAMESPACE Simatic.Ax.Conversion.Strings.ToArray + /// Converts a string representation of an array of integers to an array of LINT values. + /// + /// This function parses a string containing integers (e.g., "[1, 2, 3]") and converts it + /// into an array of LINT values. If the string cannot be converted, the function returns FALSE. + /// + /// @param str The input string to parse. + /// @param arr The output array to store the converted LINT values. + /// @return TRUE if the conversion is successful, FALSE otherwise. FUNCTION INTERNAL OfLint : BOOL VAR_INPUT str: STRING; @@ -86,6 +94,14 @@ NAMESPACE Simatic.Ax.Conversion.Strings.ToArray END_FOR; END_FUNCTION + /// Extracts the bounds of an array from a string representation. + /// + /// This function identifies the positions of the opening and closing brackets + /// in a string representing an array (e.g., "[1, 2, 3]") and returns their indices. + /// + /// @param str The input string to analyze. + /// @param lower The index of the opening bracket. + /// @param upper The index of the closing bracket. FUNCTION GetArrayBounds VAR_INPUT str: STRING; diff --git a/src/strings/StringToArrayOfLintCount.st b/src/strings/StringToArrayOfLintCount.st index ea073e4..bf3817d 100644 --- a/src/strings/StringToArrayOfLintCount.st +++ b/src/strings/StringToArrayOfLintCount.st @@ -3,14 +3,15 @@ USING System.Strings; NAMESPACE Simatic.Ax.Conversion.Strings.ToArray - /// Convert a string with array of integers like [1, 2, 3] into an array of LINT - /// Returns the number of converted elements. - /// Returns 0, if the string can't be converted - /// If the destination array is smaller than the number of elements in the string, - /// the array will be filled it's maximum size. In this case the function returns - /// the number of the converted numbers (size of array) - /// If less elements in the string than the size of the array, the last elements - /// will not overwritten. + /// Converts a string representation of an array of integers to an array of LINT values. + /// + /// This function parses a string containing integers (e.g., "[1, 2, 3]") and converts it + /// into an array of LINT values. It returns the number of successfully converted elements. + /// If the string cannot be converted, the function returns 0. + /// + /// @param str The input string to parse. + /// @param arr The output array to store the converted LINT values. + /// @return The number of successfully converted elements. FUNCTION INTERNAL OfLintCount : DINT VAR_INPUT str: STRING; @@ -95,4 +96,5 @@ NAMESPACE Simatic.Ax.Conversion.Strings.ToArray END_IF; END_FOR; END_FUNCTION + END_NAMESPACE \ No newline at end of file diff --git a/src/strings/StringToBool.st b/src/strings/StringToBool.st index 95ae2e7..e1d72fb 100644 --- a/src/strings/StringToBool.st +++ b/src/strings/StringToBool.st @@ -3,6 +3,14 @@ USING System.Strings; NAMESPACE Simatic.Ax.Conversion + /// Converts a string to a boolean value. + /// + /// This function checks if the input string represents "TRUE" or "FALSE" (case-insensitive). + /// If the string matches "TRUE", the output is TRUE. If it matches "FALSE", the output is FALSE. + /// Otherwise, the function returns FALSE and sets the output to FALSE. + /// + /// @param str The input string to convert. + /// @return TRUE if the conversion is successful, FALSE otherwise. FUNCTION StringToBool : BOOL VAR_INPUT str: STRING; diff --git a/src/strings/ToHex/GetHexValueOfChar.st b/src/strings/ToHex/GetHexValueOfChar.st index db20e6e..a44dd3c 100644 --- a/src/strings/ToHex/GetHexValueOfChar.st +++ b/src/strings/ToHex/GetHexValueOfChar.st @@ -2,16 +2,19 @@ USING System.Strings; NAMESPACE Simatic.Ax.Conversion - // returns the hex value as byte of a hex character - // Example 'a' --> BYTE#16#a - // Valid characters: [A-Fa-f0-9] - // Return vlaue: character is valid + /// Converts a hexadecimal character to its byte value. + /// + /// This function takes a single hexadecimal character (0-9, A-F, a-f) and converts it + /// to its corresponding byte value. If the character is invalid, the function returns FALSE. + /// + /// @param c The input hexadecimal character. + /// @return TRUE if the conversion is successful, FALSE otherwise. FUNCTION INTERNAL GetHexValueOfChar : BOOL VAR_INPUT c : CHAR; END_VAR VAR_OUTPUT - result : BYTE; + result : BYTE; // The byte value of the hexadecimal character END_VAR GetHexValueOfChar := TRUE; CASE c OF diff --git a/src/strings/ToHex/StringToHex.st b/src/strings/ToHex/StringToHex.st index 7c76625..107154b 100644 --- a/src/strings/ToHex/StringToHex.st +++ b/src/strings/ToHex/StringToHex.st @@ -2,13 +2,18 @@ USING System.Strings; NAMESPACE Simatic.Ax.Conversion.Strings - /// This function convert a string containing a hex number into a hex number - /// Example 'a231' --> WORD#16#a231 - /// Return values: - /// WORD#16#0000 no error - /// WORD#16#0007 invalid character - /// WORD#16#8182 Input buffer is too small for data in the N parameter - /// WORD#16#8482 Output buffer is too small for data in the N parameter + /// Converts a string containing a hexadecimal number to a DWORD value. + /// + /// This function parses a string containing a hexadecimal number and converts it into + /// a DWORD value. It validates the input string and checks for buffer size constraints. + /// + /// @param str The input string containing the hexadecimal number. + /// @param n The number of characters to convert. + /// @return A WORD indicating the status of the conversion: + /// - WORD#16#0000: No error. + /// - WORD#16#0007: Invalid character. + /// - WORD#16#8182: Input buffer is too small. + /// - WORD#16#8482: Output buffer is too small. FUNCTION ToHex : WORD VAR_INPUT str : STRING; // Pointer to ASCII character string diff --git a/src/strings/ToInt.st b/src/strings/ToInt.st index 05c602d..477bf3f 100644 --- a/src/strings/ToInt.st +++ b/src/strings/ToInt.st @@ -1,6 +1,14 @@ USING System.Strings; NAMESPACE Simatic.Ax.Conversion.Strings + + /// Converts a string to a signed 8-bit integer (SINT). + /// + /// This function parses a string and converts it to a signed 8-bit integer. If the value + /// is out of range or invalid, the function returns FALSE and sets the output to 0. + /// + /// @param str The input string to convert. + /// @return TRUE if the conversion is successful, FALSE otherwise. FUNCTION ToInt : BOOL VAR_INPUT str : STRING; @@ -26,6 +34,13 @@ NAMESPACE Simatic.Ax.Conversion.Strings END_IF; END_FUNCTION + /// Converts a string to a signed 16-bit integer (INT). + /// + /// This function parses a string and converts it to a signed 16-bit integer. If the value + /// is out of range or invalid, the function returns FALSE and sets the output to 0. + /// + /// @param str The input string to convert. + /// @return TRUE if the conversion is successful, FALSE otherwise. FUNCTION ToInt : BOOL VAR_INPUT str : STRING; @@ -51,6 +66,13 @@ NAMESPACE Simatic.Ax.Conversion.Strings END_IF; END_FUNCTION + /// Converts a string to a signed 32-bit integer (DINT). + /// + /// This function parses a string and converts it to a signed 32-bit integer. If the value + /// is out of range or invalid, the function returns FALSE and sets the output to 0. + /// + /// @param str The input string to convert. + /// @return TRUE if the conversion is successful, FALSE otherwise. FUNCTION ToInt : BOOL VAR_INPUT str : STRING; @@ -76,6 +98,13 @@ NAMESPACE Simatic.Ax.Conversion.Strings END_IF; END_FUNCTION + /// Converts a string to a signed 64-bit integer (LINT). + /// + /// This function parses a string and converts it to a signed 64-bit integer. If the value + /// is out of range or invalid, the function returns FALSE and sets the output to 0. + /// + /// @param str The input string to convert. + /// @return TRUE if the conversion is successful, FALSE otherwise. FUNCTION ToInt : BOOL VAR_INPUT str : STRING; @@ -101,6 +130,13 @@ NAMESPACE Simatic.Ax.Conversion.Strings END_IF; END_FUNCTION + /// Converts a string to an unsigned 8-bit integer (USINT). + /// + /// This function parses a string and converts it to an unsigned 8-bit integer. If the value + /// is out of range or invalid, the function returns FALSE and sets the output to 0. + /// + /// @param str The input string to convert. + /// @return TRUE if the conversion is successful, FALSE otherwise. FUNCTION ToInt : BOOL VAR_INPUT str : STRING; @@ -126,6 +162,13 @@ NAMESPACE Simatic.Ax.Conversion.Strings END_IF; END_FUNCTION + /// Converts a string to an unsigned 16-bit integer (UINT). + /// + /// This function parses a string and converts it to an unsigned 16-bit integer. If the value + /// is out of range or invalid, the function returns FALSE and sets the output to 0. + /// + /// @param str The input string to convert. + /// @return TRUE if the conversion is successful, FALSE otherwise. FUNCTION ToInt : BOOL VAR_INPUT str : STRING; @@ -151,6 +194,13 @@ NAMESPACE Simatic.Ax.Conversion.Strings END_IF; END_FUNCTION + /// Converts a string to an unsigned 32-bit integer (UDINT). + /// + /// This function parses a string and converts it to an unsigned 32-bit integer. If the value + /// is out of range or invalid, the function returns FALSE and sets the output to 0. + /// + /// @param str The input string to convert. + /// @return TRUE if the conversion is successful, FALSE otherwise. FUNCTION ToInt : BOOL VAR_INPUT str : STRING; @@ -176,6 +226,13 @@ NAMESPACE Simatic.Ax.Conversion.Strings END_IF; END_FUNCTION + /// Converts a string to an unsigned 64-bit integer (ULINT). + /// + /// This function parses a string and converts it to an unsigned 64-bit integer. If the value + /// is out of range or invalid, the function returns FALSE and sets the output to 0. + /// + /// @param str The input string to convert. + /// @return TRUE if the conversion is successful, FALSE otherwise. FUNCTION ToInt : BOOL VAR_INPUT str : STRING; diff --git a/src/times/ToLDateAndTime.st b/src/times/ToLDateAndTime.st index 96b6ca4..8d96ccb 100644 --- a/src/times/ToLDateAndTime.st +++ b/src/times/ToLDateAndTime.st @@ -1,6 +1,15 @@ USING System.DateTime; + NAMESPACE Simatic.Ax.Conversion.Times + /// Converts a SimotionDateTime structure to an LDATE_AND_TIME value. + /// + /// This function converts a `SimotionDateTime` structure into a Simatic `LDATE_AND_TIME` value. + /// The date is calculated based on the number of days since 01.01.1992, and the time is derived + /// from the number of milliseconds since midnight. + /// + /// @param SimotionDateTime The input SimotionDateTime structure. + /// @return An LDATE_AND_TIME value representing the input date and time. FUNCTION ToLDateAndTime : LDATE_AND_TIME VAR_INPUT diff --git a/src/times/ToSimotionDateTime.st b/src/times/ToSimotionDateTime.st index ac3ca3b..f1aac13 100644 --- a/src/times/ToSimotionDateTime.st +++ b/src/times/ToSimotionDateTime.st @@ -1,5 +1,15 @@ USING System.DateTime; + NAMESPACE Simatic.Ax.Conversion.Times + + /// Converts an LDATE_AND_TIME value to a SimotionDateTime structure. + /// + /// This function converts a Simatic `LDATE_AND_TIME` value into a `SimotionDateTime` structure. + /// The date is represented as the number of days since 01.01.1992, and the time is represented + /// as the number of milliseconds since midnight. + /// + /// @param SimaticTime The input LDATE_AND_TIME value. + /// @return A SimotionDateTime structure representing the input date and time. FUNCTION ToSimotionDateTime : SimotionDateTime VAR_INPUT SimaticTime : LDATE_AND_TIME; diff --git a/src/times/types.st b/src/times/types.st index 0314e62..fddfcd0 100644 --- a/src/times/types.st +++ b/src/times/types.st @@ -1,9 +1,14 @@ NAMESPACE Simatic.Ax.Conversion.Times + /// Represents a date and time in the Simotion format. + /// + /// This structure contains two DWORD values: + /// - `SimotionDate`: The number of days since 01.01.1992. + /// - `SimotionTime`: The time of day in milliseconds. TYPE SimotionDateTime : STRUCT - SimotionDate : DWORD; - SimotionTime : DWORD; + SimotionDate : DWORD; // Days since 01.01.1992 + SimotionTime : DWORD; // Time of day in milliseconds END_STRUCT; END_TYPE