User Tools

Site Tools

한국어

comfilehmi:hmieditor_function:index

System Functions

The functions listed here can be used in expressions in the ComfileHMI editor.

Math Functions

  • asin(value) : Arc-Sine
  • acos(value) : Arc-Cosine
  • atan(value) : Arc-Tangent
  • avg(x,y,z,…) : Returns the average of all values in the argument list
  • ceil(value) : Rounds number up to the nearest integer value.
  • cos(value) : Cosine
  • cosh(value) : Hyperbolic Cosine
  • exp(value) : e raised to a given exponent
  • fabs(value) : absolute value
  • fmod(x,y) : the remainder of x divided by y.
  • floor(value) : Rounds number down to the nearest integer value.
  • log(value) : Natural Logarithm
  • log10(value) : Log base 10
  • max(x,y,z,…) : Returns the largest value from the argument list
  • min(x,y,z,…) : Returns the smallest value from the argument list
  • max_index(x,y,z,…) : Returns the index of the largest value in the argument list
  • min_index(x,y,z,…) : Returns the index of the smallest value in the argument list
  • pow(x,y) : x raised to the power y
  • sin(value) : Sine
  • sinh(value) : Hyperbolic Sine
  • sqrt(value) : square root
  • stdev(x,y,z,…) : Returns the standard deviation of all values in the argument list
  • tan(value) : Tangent
  • tanh(value) : Hyperbolic Tangent

Bit Manipulation Functions

  • bit(“variable”, bitIndex) : Return the value of the bit at bitIndex in variable. variable is a variable name that must be enclosed in double quotes. bitIndex can be an integer from 0 through 31.
    bitValue = bit("a", 3)
  • set_bit(“variable”, bitIndex, value = 1) : Sets the value of the bit at bitIndex in variable to value. variable is a variable name that must be enclosed in double quotes. bitIndex can be an integer from 0 through 31. value is optional and defaults to 1.
    set_bit("a", 3, 1)
  • toggle_bit(“variable”, bitIndex, value) : Toggles the value of the bit at bitIndex in variable. variable is a variable name that must be enclosed in double quotes. bitIndex can be an integer from 0 through 31.
    toggle_bit("a", 3)

String Functions

  • find_text(string_to_search, string_to_find) : Returns the character index of string_to_find in string_to_search. Returns -1 if not found.
  • num_to_text_int(number) : Prints a number as a base 10 integer character string.
  • num_to_text_int(number, digits) : Prints a number as a base 10 integer character string with leading 0's. Ex: num_to_text_int(3.14, 4) prints “0003”.
  • num_to_text_hex(number) : Prints a number as a base 16 integer character string.
  • num_to_text_hex(number, digits) : Prints a number as a base 16 integer character string with leading 0's
  • text_hex_to_num(hexadecimal_string) : Returns the binary number corresponding to hexadecimal_string. For example, if hexadecimal_string is “FF”, 255 will be returned.
  • num_to_text_dec(number, fractional digits) : Prints a number as a base 10 character string with a given number of fractional digits. Ex: num_to_text_dec(3.14159, 4) = “3.1416”
  • text_starts_with(target_string, prefix, ignore_case): Returns 1 if target_string begins with prefix. Returns 0 otherwise. If ignore_case is non-zero it will do a case-insensitive search. ignore_case defaults to 0.
    text_starts_with("BREAKFAST", "break")    // Returns 0
    text_starts_with("BREAKFAST", "BREAK")    // Returns 1
    text_starts_with("BREAKFAST", "break", 1) // Returns 1
    text_starts_with("BREAKFAST", "break", 0) // Returns 0
  • text_ends_with(target_string, suffice, ignore_case): Returns 1 if target_string ends with suffix. Returns 0 otherwise. If ignore_case is non-zero it will do a case-insensitive search. ignore_case defaults to 0.
    text_ends_with("BREAKFAST", "fast")    // Returns 0
    text_ends_with("BREAKFAST", "FAST")    // Returns 1
    text_ends_with("BREAKFAST", "fast", 1) // Returns 1
    text_ends_with("BREAKFAST", "fast", 0) // Returns 0
  • text_to_num(string) : Parses a character string in base 10.
  • replace_text(string_to_search, string_to_find, replacement) : Replaces any occurrence of string_to_find in string_to_search with replacement. String variable names must be enclosed in double quotes with the $ prefix omitted. Example $var = "I ate lunch."; Replace_text("var", "lunch", "dinner")

Communication Functions

The following functions can be used to detect communication problems between the ComfileHMI and the PLC.

  • timeout_result() : Returns 1 if the last communication resulted in a timeout waiting for a response. Return 0 if no timeout occurred.
  • timeout_count() : Returns the total number of times a communication timeout occurred since the project was executed.
  • reset_timeout_count() : Resets the timeout count returned from timeout_count() to 0.

Internal Memory Functions

The following functions are used to read from and write to internal memory.

  • set_mem(index, value) : Writes value to internal memory at index.
  • mem(index) : Reads the value current stored in internal memory at index.
  • set_mem(index, value1, value2, …, valueN)

File Functions

  • file_exists(file_path): Returns 1 if file_path exists, 0 if not. e.g. file_exists(“storage card\myfile.txt”) == 1
  • file_to_text(file_path): Returns the contents of file_path as a string. If the file's contents have the byte-order mark FF FE, the contents of the file will be Unicode encoded. e.g. $content = file_to_text(“storage card\myfile.txt”)
  • text_to_file(string, file_path): Stores string variable string to the file file_path. e.g. text_to_file($content, “storage card\myfile.txt”)
  • file_size(file_path): Returns the size of the given file in bytes.

Remote Script Functions

  • write_byte(value): Writes a single byte of binary data to the response of a remote script. Returns 1 on success and 0 on failure.
  • write_word(value): Writes 2 bytes of binary data in little endian to the response of a remote script. Returns 1 on success and 0 on failure.
  • write_dword(value): Writes 4 bytes of binary data in little endian to the response of a remote script. Returns 1 on success and 0 on failure.
  • write_text(string): Writes a UTF-8 string to the response of a remote script. Returns 1 on success and 0 on failure.
  • write_file_contents(file path): Writes at most 1MB of binary data from a file to the response of a remote script. Returns 1 on success and 0 on failure.

Trend Graph Functions

  • trendgraph_restart(trendgraph_alias) : Clears the trend graph identified by trendgraph_alias and begins sampling.
    trendgraph_start("my_graph")
  • trendgraph_stop(trendgraph_alias, clear = 0) : Stops the trend graph identified by trendgraph_alias and optionally clears the trend graph according to the clear flag (default 0).
    trendgraph_stop("my_graph")
    trendgraph_stop("my_graph", 1)

Type Conversion Functions

Functions to convert between data types.

  • bytes_to_float(“variable1”, “variable2”, “variable3”, “variable4”) : Assembles a floating point value from the provided byte variables. variable1 is the least significant byte and variable4 is the most significant byte. variables are case-sensitive and must be enclosed in double quotes. Example: float_to_bytes(3.14, “a”, “b”, “c”, “d”);result = bytes_to_float(“a”, “b”, “c”, “d”)result will contain the value 3.14.
  • float_to_bytes(floatValue, “variable1”, “variable2”, “variable3”, “variable4”) : Decomposes a floating point value into its composed bytes. Afterward the bytes can be manipulated in various ways to, for example, change the byte order and store the values in addressable internal memory. variable1 is the least significant byte and variable4 is the most significant byte. variables are case-sensitive and must be enclosed in double quotes.

System Functions

Functions associated with the system.

  • action_group_repeat_index() : Retrieves the number of times a user event was executed.
  • backlight_state(): Returns whether or not the LCD backlight is on. 1 for on, 0 for off.
  • beep(): Causes the panel PC to emit an audible beep sound.
  • bitwise_not(value): Returns the binary complement of value.
  • change_screen(screen_number): Transitions to the screen identified by screen_number.
  • cpu_usage() : Returns the current CPU utilization as a percentage.
  • exit_project(): Causes the current project to exit. This is the same effect as touching the upper right corner of the screen 5 times in quick succession.
  • enable_status_monitoring(enable = 1): Enables status monitoring messages to appear overlaid on the panel PC's screen. The enable argument is optional and defaults to 1.
  • free_memory_bytes(): Returns the amount of free system memory in bytes.
  • firmware_version() : Retrieves the firmware version running on the panel PC. For example 273 corresponds to v2.73.
  • idle_seconds() : Returns the number of seconds since the screen was last touched.
  • idle_minutes() : Returns the number of minutes since the screen was last touched.
  • is_status_monitoring_enabled(): Returns 1 if status monitoring is enabled or 0 if it is not enabled.
  • keypad_state(): Returns whether the current keypad is opened. 1 if opened, 0 if not.
  • keypad_value(): Returns the most recently entered keypad value.
  • prev_screen_id() : Returns the id of the screen that the current screen navigated from.
  • reboot_system() : Reboots the panel PC
  • scale(input, minimum input, maximum input, minimum output, maximum output) : Scales input proportionally to (maximum input - minimum input) / (maximum output - minimum output).
  • screen_id() : Returns the id of the current screen.
  • select_if(Conditional Expression, Value1, Value2): Returns Value1 if conditional_expression is true, or Value2 if conditional_expression is false.
  • set_backlight_state(value): Sets the state of the LCD backlight on or off. If value is 1 the LCD backlight turns on, if value is 0 the LCD backlight is turns off.
  • set_data_processing_period(value) : This function can be used to throttle CPU usage. If the CPU usage for a project is too high, the data processing period can be increased to throttle back the amount of resources that the HMI software dedicates to processing data. value is in units of milliseconds; default is 1 ms.
  • set_modbus_word_write_always_multi(active_status_flag = 1): When active_status_flag is `1` or omitted, this function causes all Modbus register (16-bit word) writes to use function code 16 (Write Multiple Registers) even when the number of registers to write is 1.
  • start_action_group(action_group_name): Executes the action group identified by action_group_name.
  • status_monitoring_message(): Returns the current status monitoring message.
  • tick_count() : The number of milliseconds since the system was powered on.
  • touch_duration() : The number of milliseconds since the last time the screen was touched. If the screen has never been touched -1 is returned.
  • verify_developer_key(value) : Using the ComfileHMI panel PC's runtime configuration screen, a unique key can be assigned to a individual device or group of devices. verify_developer_key can then be used at runtime within a project to test which device a project is running on and dynamically offer a different experience. The developer key cannot be read; one can only check if value matches the developer key assigned to the device. This function returns 1 if the value matches the developer key assigned to the device or 0 if it does not.

In the Add Action –> Run Action Group properties, in the Advanced Options is the ability to pass a primary and secondary parameter to the actions (Add Action Parameter and Add Secondary Action Parameter respectively) .

The parameters can then be read from within the executing action using the following functions.

  • action_param : Retrieves the primary parameter passed to an action.
  • sub_action_param : Retrieves the secondary parameter passed to an action group.

RTC Functions

Functions with no argument.

  • year() : The current year
  • month() : The current month (1~12)
  • day() : The day of the month
  • day_of_week() : The day of the week (0~6), 0 = Sunday
  • hour() : The hour of the day (0~23)
  • minute() : The minute component of the current hour (0~59)
  • second() : The second component of the current minute (0~59)
  • rand() : returns a random number in the range of 0~32767 (0x7FFF)
  • last_day_of_month(year, month) : returns the last day of the given month for the given year

Functions that take 1 argument but return no value.

  • set_year(value) : Sets the current year
  • set_month(value) : Sets the current month (1~12)
  • set_day(value) : Sets the day of the month
  • set_hour(value) : Sets the hour of the day (0~23)
  • set_minute(value) : Sets the minute component of the current hour (0~59)
  • set_second(value) : Sets the second component of the current minute (0~59)
  • srand(seed) : Sets the seed value for generating random numbers with the rand() function.

It is recommended to call srand(tick_count()) to seed the random number generator before using rand().

Back to ComfileHMI

comfilehmi/hmieditor_function/index.txt · Last modified: 2021/02/16 16:42 by COMFILE Technology