表达式
表达式 allow performing calculations, primarily for raw data conversion in devices.
What are ex按下ions?
表达式 are texts that allow evaluating data, performing calculations, and ultimately returning a single value. 表达式 can include variables, so that the values of those variables are used in the calculations.
Data types
The ex按下ion engine built into Gear Studio supports three data types: number, string, and boolean, as shown 下方:
| Data type | 说明 |
|---|---|
| Number | Number data types represent numbers, either integers or floating-point (with decimals). |
| String | Represent texts, and when written as constants, they must be enclosed using single quotes ('). When a text must contain a single quote, it can be represented as a constant using two consecutive single quotes (''). |
| Boolean | Represents a boolean (logical) condition, which can only be true or false. |
Variables
When ex按下ions are used for raw data conversion in devices, t此处 is an implicit variable RawData, which contains the raw 值 sent by the device. This variable can be used directly in any data conversion ex按下ion, but it is important to note that the variable is of type string. It is usually necessary to convert the variable to a number (using the ToNumber function), and apply other conversion functions as needed.
Some ex按下ion examples
| 表达式 | 说明 |
|---|---|
| 25 | Constant, with value 25 (number) |
| 'Hola, mundo' | Constant, with value "Hola, mundo" (string) |
| False | Constant, with value false (boolean) |
| 'I''m happy with ex按下ions' | Constant with value "I'm happy with ex按下ions" (string). Note the use of double single quotes for the single quote after "I". |
| 5 * 6 | 表达式 with value 30 (number), corresponding to the multiplication of 5 by 6. |
| (2 + 3) * 6 | 表达式 with value 30 (number), corresponding to an addition and a multiplication. |
| 'Tengo ' + ToString(6 * 5) + ' anos' | 表达式 with value "Tengo 30 anos" (string), using a multiplication and a number-to-string conversion 使用 ToString function. |
| 25 < 8 | 表达式 with value false (boolean), corresponding to a less-than comparison. |
| not (25 < 8) | 表达式 with value true (boolean), corresponding to the negation of a less-than comparison. |
| Sqrt(81) | 表达式 with value 9 (number), calculated as the square root of 81 使用 Sqrt function. |
| ToNumber(RawData) / 10 | Numeric ex按下ion whose value depends on the special RawData variable. The ex按下ion takes the value of RawData, converts it to a number, and then divides it by 10. |
What effect do uppercase and lowercase have on ex按下ions?
In the Cloud Studio platform ex按下ion engine, variable names, functions, etc., are not case-sensitive, meaning it does not matter whether they are written in uppercase, lowercase, or a mix of both. For example, all of the following ex按下ions are equivalent:
ToString(NOT (valor < 25))
tostring(not (valor < 25))
TOSTRING(not (VALOR< 25))W此处 can ex按下ions be used?
Currently, ex按下ions can be used for raw data conversion in devices. This allows obtaining raw information from certain devices (typically sensors), and using ex按下ions to convert that data to values that can be injected into the platform.
Can I program using ex按下ions?
No, ex按下ions are not a programming tool, but a calculation tool. 表达式 do not have control structures such as for, while, etc., and are not designed for that purpose.
How can I test my ex按下ions?
In general, any functionality that allows the use of ex按下ions has the ability to test each ex按下ion right t此处 with test values. As an example, you can consult the raw data conversion reference for devices.
How can I represent hexadecimal numbers?
The ex按下ion engine allows representing hexadecimal numbers by prepending the prefix "0x", or alternatively, the prefix "$" (both methods are equivalent). For example, the value 0x100 (or alternatively, $100), represents the hexadecimal number 100, equivalent to decimal 256.
更多信息
更多信息 about ex按下ions, consult the operators and functions reference.