The text of a manual · part 13 of 18
Qlarity-Based Terminal Programmer's Reference Manual: Chapter 4 Qlarity API Function Reference, pages 83 to 91
Pages 83 to 91 of 134, from Qlarity-Based Terminal Programmer's Reference Manual
The original document is the PDF (1.5 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
Filed in the catalog under the QSI Corp QTERM-G70
Page 83
QSI Qlarity-based Terminal Programmer’s Reference after the "{start}" character are not searched. -1 starts at the emd. {len} The number of elements before "{start}" to search in "{match}," or -1 to indicate all elements from "{start}" to the beginning of "{match}.". {pattern} The pattern of data elements to search for in "{match}."
71
Description: This function searches for "{pattern}" in "{match}" and replaces up to "{count}" occurrences with "{newdata}." The returned value indicates how many replacements actually occurred.
4.10 Conversion Functions 4.10.1 Str Syntax:
Description: This function searches for "{pattern}" in "{match}." If "{pattern}" is found, then the index of the first element of "{pattern}" in "{match}" is returned. If "{pattern}" is not found in "{match}," -1 is returned.
str(value as reference? to anytype) -> returns string
Parameters:
4.9.14 Replace
{value} The value to convert to a string.
Syntax:
Description:
replace (match[] as reference to -> sametype!, start as integer, len as -> integer, pattern[] as reference? to -> sametype!, newdata[] as reference? to -> sametype!, count as integer) returns integer
This function converts “{value}” to a string representing the value. The system software uses heuristic rules to determine how to convert different types of values. Integers and floating point numbers are converted to text representations of the passed value (with sign, if negative, and decimal point, if floating point). Bytes and unibytes are treated as unsigned integers. Booleans convert to the strings “true” or “false.” Objrefs convert to a string containing the referenced object's name. Arrays convert to a comma-separated list of converted values enclosed in brackets. User-defined data types such as enumerations are treated as integers.
Parameters: {match} An array of any type to examine. {start} The location in "{match}" to begin the search; characters before the "{start}" character are not searched. 0 starts at the beginning.
4.10.2 Val Syntax:
{len} The number of elements after "{start}" to search in "{match}," or -1 to indicate all elements from "{start}" to the end of "{match}." {pattern} The pattern of data elements to search for in "{match}." {newdata} What to replace an occurrence of "{pattern}" with in "{match}." {count} The maximum number of times "{pattern}" should be replaced by "{newdata}" in "{match}," or -1 to replace all occurrences of "{pattern}" by "{match}." val(value as reference to anytype, text[] -> as reference? to byte)
Parameters: {value} A variable (of any type) to receive the converted value. {text} An array of bytes (or a string) to be converted. Description: This function converts the text in “{text}” to a variable of “{value}'s” type and stores the result in “value.” The conversions follow a similar heuristic to the Str() API function. Enumerations cannot be assigned a value with Val().
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770
Page 84
72
QSI Qlarity-based Terminal Programmer’s Reference
If “{value}” is an array, then “{text}” should be a list of values separated by commas and enclosed within brackets ([]). Alternatively, if “{value}” is an array of bytes, unibytes, or integers, “{text}” may contain text enclosed in double quotes. Each character in the quoted string is converted and assigned to a corresponding array member.
4.10.4 GetBytes Syntax: getbytes(tobreak as anytype, bigendian as -> boolean) returns byte[]
Parameters: 4.10.3 FromBytes
{tobreak} The variable (see description below) containing the desired binary data.
Syntax: frombytes(var as reference to anytype, -> toset[] as byte, bigendian as boolean)
Parameters: {var} A variable (see description below) to receive the binary data.
{bigendian} The desired byte order for the data stored in “{tobreak}.” A value of “true” stores the data in big endian byte order, while a value of “false” stores the data in little endian byte order. Description:
{toset} A byte array containing the binary data. {bigendian} A flag indicating the endianness of the data in “{toset}.” A value of “true” indicates big endian byte order, while a value of “false” indicates little endian byte order. Description: This function stores the binary data in “{toset}” in variable “{var}.” This is useful for extracting variable data (such as integers or floating point numbers) from a byte stream. Only certain built-in data types are supported, and the “{toset}” array must be the correct size for “{var}'s” data type, as follows: Data Type
This function returns a byte array containing the binary data from the “{tobreak}” variable. Only certain built in data types for “{tobreak}” are supported, and the length of the returned byte array is as follows: Data Type
Size
Integer
4 bytes
Float
4 bytes (in IEEE 754 format)
Boolean
1 byte
Byte
1 byte
Unibyte
2 bytes
Array (of one of the above data types)
Size of data type (see above) * Number of elements
Size 4.10.5 LowerCase
Integer
4 bytes
Float
4 or 8 bytes (in IEEE 754 format)1
Boolean
1 byte
Byte
1 byte
Parameters:
Unibyte
2 bytes
{str} The string to convert to lower case.
Array (of one of the above data types)
Size of data type (see above) * Number of elements
1. When an 8-byte array is passed for storage in a float variable, the data in “{toset}” is assumed to be a double precision floating point number, and it is automatically converted to single precision before storage in “{var}.”
Syntax: lowercase(str[] as byte) returns string
Description: This function converts all capital letters in the “{str}” string to lower case letters and returns the resulting string.
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770
Page 85
QSI Qlarity-based Terminal Programmer’s Reference
4.10.6 UpperCase
73
Description: This function returns the Tangent of “{x}.”
Syntax: uppercase(str[] as byte) returns string
4.11.4 Asin
Parameters:
Syntax:
{str} The string to convert to upper case.
asin(x as float) returns float
Parameters: Description: This function converts all lower case letters in “{str}” to upper case letters and returns the resulting string.
{x} The floating point operand. Description:
4.11 Math Functions
This function returns the Arc Sine of “{x}.”
4.11.1 Sin
4.11.5 Acos
Syntax:
Syntax:
sin(x as float) returns float acos(x as float) returns float
Parameters:
Parameters:
{x} The floating point operand.
{x} The floating point operand.
Description:
Description:
This function returns the Sine of “{x}.”
This function returns the Arc Cosine of “{x}.”
4.11.2 Cos
4.11.6 Atan
Syntax:
Syntax:
cos(x as float) returns float atan(x as float) returns float
Parameters:
Parameters:
{x} The floating point operand.
{x} The floating point operand.
Description:
Description:
This function returns the Cosine of “{x}.”
This function returns the Arc Tangent of “{x}.”
4.11.3 Tan
4.11.7 Power
Syntax:
Syntax:
tan(x as float) returns float power(x as float, exp as float) returns float
Parameters:
Parameters:
{x} The floating point operand.
{x} The base operand (floating point).
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770
Page 86
74
QSI Qlarity-based Terminal Programmer’s Reference
{exp} The exponent operand (floating point).
4.12 User Message Functions 4.12.1 UserBroadcastMsg
Description: This function returns “{x}” raised to the “{exp}” power.
Syntax:
4.11.8 Exp userbroadcastmsg(startobj as objref, -> msgnum as message, parm as integer, donow -> as boolean)
Syntax: exp({x} as float) returns float
Parameters: {x} The exponent operand (floating point). Description: This function returns e raised to the “{x}” power.
Parameters: {startobj} First object in Z-order to receive the message. Only this object and its children will receive the message. Specify a value of “default” to send the message to all objects. {msgnum} The user message to send. {parm} The integer parameter to associate with the sent message.
4.11.9 Ln Syntax: ln(x as float) returns float
Parameters: {x} The floating point operand.
{donow} A flag to select preemption of the current message while the user message is processed. Description:
Description:
This function sends the “{msgnum}” user message as a broadcast message; it will go to all objects (enabled or disabled) starting with “{startobj}” in Z-order. Any object with a handler for “{msgnum}” is eligible to handle the message. Messages sent with this function cannot be terminated by a handler. The return value of the handler is ignored. The “{parm}” parameter may be set to any integer value and may be used for any purpose. If “{donow}” is set to “true,” processing of the current message is suspended while the user message is processed by the system. When the user message processing is complete, this function returns and the current message continues processing. Any pending exceptions are thrown in the calling function. Setting “{donow}” to “false” causes the user message to be enqueued and handled as any other message.
This function returns the square root of “{x}.”
4.12.2 UserSendMsg
Description: This function returns the natural logarithm of “{x}.” 4.11.10 Sqrt Syntax: sqrt(x as float) returns float
Parameters: {x} The floating point operand.
Syntax: usersendmsg(startobj as objref, msgnum as -> message, parm as integer, donow as boolean)
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770
Page 87
QSI Qlarity-based Terminal Programmer’s Reference
Parameters: {startobj} First object in Z-order to receive the message. Only this object and its children will receive the message. Specify a value of “default” to send the message to all objects.
75
{donow} A flag to select preemption of the current message while the user message is processed Description:
{donow} A flag to select preemption of the current message while the user message is processed
This function sends a user message directly to the “{startobj}” object. If “{startobj}” has a handler for “{msgnum}” and “{donow}” is “true,” the handler is immediately called and executed. Otherwise, the “{msgnum}” message is posted in the messaging queue as a direct message to “{startobj}.” The return value is the value returned by the called handler (if “{donow}” is “true”) or “false” if “{startobj}” has no handler for “{msgnum}” (or if “{donow}” is “false”). The message is delivered whether “{startobj}” is enabled or disabled.
Description:
4.12.4 FakeKeyMsg
{msgnum} The user message to send. {parm} The integer parameter to associate with the sent message.
This function sends the “{msgnum}” user message as a normal message; it will go only to enabled objects starting with “{startobj}” in Z-order. Any object with a handler for “{msgnum}” is eligible to handle the message. Messages sent with this function can be terminated by a handler returning “true.” If “false” is returned, the message continues through Z-order. The “{parm}” parameter may be set to any integer value and may be used for any purpose. If “{donow}” is set to “true,” processing of the current message is suspended while the user message is processed by the system. When the user message processing is complete, this function returns and the current message continues processing. Any pending exceptions are thrown in the calling function. Setting “{donow}” to “false” causes the user message to be enqueued and handled as any other message. 4.12.3 UserDirectMsg Syntax: userdirectmsg(startobj as objref, msgnum -> as message, parm as integer, donow as -> boolean) returns boolean
Parameters: {startobj} The object to which the message is being sent. {msgnum} The user message to send. {parm} The integer parameter to associate with the sent message.
Syntax: fakekeymsg(msgtype as fake_key, keycode -> as UNIBYTE)
Parameters: {msgtype} The type of key message to post. {keycode} The keycode of the key to post. Description: This function allows the programmer to introduce a simulated key message into the messaging system (simulating a physical key press or release). The variable “{msgtype}” must be one of the following: KEY_PUSH KEY_REPEAT KEY_RELEASE 4.12.5 FakeScreenMsg Syntax: fakescreenmsg(msgtype as fake_screen, x1 -> as integer, y1 as integer, x2 as integer, -> y2 as integer)
Parameters: {msgtype} Type of screen message to post.
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770
Page 88
76
QSI Qlarity-based Terminal Programmer’s Reference
{x1} The x-location of the simulated screen event (for SCREEN_PUSH and SCREEN_RELEASE messages). For SCREEN_MOVE events, this is the x-location at the start of the move event. {y1} The y-location of the simulated screen event (for SCREEN_PUSH and SCREEN_RELEASE messages). For SCREEN_MOVE events, this is the y-location at the start of the move event. {x2} For SCREEN_MOVE events, this is the x-location at the end of the move event. This parameter is ignored for other types of screen events. {y2} For SCREEN_MOVE events, this is the y-location at the end of the move event. This parameter is ignored for other types of screen events. Description: This function allows the programmer to introduce a fake screen message into the messaging system. The variable “{msgtype}” must be one of the following: SCREEN_PUSH SCREEN_MOVE SCREEN_RELEASE
• Container objects in the capture list behave normally by passing the message to their children and then receiving a second pass. If an object in the capture list is not enabled back to root, that object does not capture an input message (although it still appears in the capture list).
• If an input message is killed while being processed by the capture list, it does not pass to other objects in the capture list or to root for normal message processing. If an input message is not killed, normal message processing occurs on the message (it is passed to root, which may cause objects in the capture list to receive the message twice). The following API functions are used to examine and modify the capture list. 4.13.1 SetCapture Syntax: setcapture(obj as objref)
Parameters: {obj} The object to appear in the capture list. Description: This function places “{obj}” in the capture list (if it is not already). If it is already in the list, the object is moved to the front of the list.
4.13 User Input Capture
4.13.2 GetCapture
Some objects in Qlarity may want to capture or pre-process user input messages for themselves. Input messages are touch screen, keyboard, and keypad messages. To provide this, a capture list identifies objects wishing to receive input messages before they are passed through the normal messaging tree. Any object may appear in the list, but it will only appear once.
Syntax:
Input messages are handled as follows:
• All input messages go to the objects in the capture list first.
getcapture(obj as objref) returns integer
Parameters: {obj} The object to look for in the capture list. Description: This function checks the capture list to determine if “{obj}” appears in the list. The return value indicates the location of the object in the list with 0 being first, 1 second, and so on. A –1 indicates that the object does not appear in the list.
• Each object in the capture list is treated as a root object (receiving all touch screen messages regardless of location).
4.13.3 RemoveCapture Syntax: removecapture(obj as objref)
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770
Page 89
QSI Qlarity-based Terminal Programmer’s Reference
77
Parameters:
Parameters:
{obj} The object to remove from the capture list.
{msg} An array of bytes (or a string) to receive specific information about what exception occurred.
Description: This function looks for “{obj}” in the capture list. If it is found, it is removed from the list.
{errtype} A unibyte to receive the error type.
4.14 Exception Functions
{errlevel} A unibyte to receive the error level.
Refer to section 2.15, “Exception Handling” for general information and to the Qlarity Foundry User’s Manual for more specific information on the Qlarity exception handling system. Exception names (types) and description strings are listed in Appendix B.
Description:
4.14.1 Throw Syntax: throw(loc[] as reference? to byte, msg[] -> as reference? to byte)
Parameters: {loc} An array of bytes (or a string) indicating where the exception occurred (i.e., in which function). {msg} An array of bytes (or string) detailing specific information about what exception occurred. Description: This function throws a user exception to the exception handling system. “{loc}” should give information on where the exception was thrown, and “{msg}” should give details on what actual exception occurred. The error type is always EXCEPT_USER, and the error level is always EXLEV_ USER. 4.14.2 GetException Syntax: getexception(msg[] as reference to byte, -> errtype as reference to unibyte, -> errlevel as reference to unibyte) returns -> boolean
This function retrieves information about the last exception that occurred and is typically called in error handling code (such as inside an on error block). Once information about an exception is retrieved via a call to GetException(), the exception is removed from the exception queue; system handling for the exception is terminated. If the user exception handling code is insufficient, the exception can be returned to the exception queue by calling Rethrow(). Important: If you do not call GetException() in an “on error” clause, the exception remains in the exception queue. A MSG_ ERROR message is sent through the messaging system if there are still errors in the queue at the end of a message. 4.14.3 Rethrow Syntax: rethrow()
Description: This function returns an exception to the exception queue after it has been removed by a previous call to GetException(). Rethrow() is typically called inside error handling code (such as inside an on error block) when an exception is retrieved that is not handled in that block of code.
4.15 User Non-Volatile Configuration Functions The user configuration block is a nonvolatile section of system memory that can be used for any purpose. Typically, it is used to store configuration data that is specific to the user application. Data written to this memory is persistent across power cycles. Up to 8 kilobytes of data can be stored in the user configuration block.
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770
Page 90
78
QSI Qlarity-based Terminal Programmer’s Reference
4.15.1 ReadUserConfig
\, it is considered to be relative to the current directory. The root directory is the default initial current directory.
Syntax: readuserconfig(len as integer) returns -> byte[]
Parameters:
This section describes functions for creating and using the file system. Since flash memory will fatigue and eventually fail after many write cycles (100,000+), care should be taken to avoid excessive calls to these functions.
{len} The number of bytes to read from the user configuration block.
4.16.1 GetAvailFilespace
Description:
getavailfilespace() returns integer
This function reads “{len}” number of bytes from the user configuration block and returns them in a byte array. If the bytes were not previously written with a call to WriteUserConfig(), the bytes will contain garbage.
Syntax:
Description:
4.15.2 WriteUserConfig
This function returns an estimate of the file space available for storing user data. As there is some storage overhead in the file system, the amount that is available for storing user data is slightly less than the returned value.
Syntax:
4.16.2 MakeDir writeuserconfig(cfg[] as reference? to byte)
Syntax:
Parameters:
makedir(name[] as reference? to byte)
{cfg} An array of bytes to write to the user configuration block.
Parameters:
Description:
{name} A string containing the desired name (and possibly path) for the new directory.
This function writes the bytes contained in “{cfg}” to the user configuration block. These bytes may subsequently be retrieved with a call to ReadUserConfig(). Since flash memory will fatigue and eventually fail after many write cycles (100,000+), care should be taken to avoid excessive calls to this function.
4.16 File System Functions The Qlarity-based terminal implements a simple file system for storage of user data in flash, non-volatile memory. The file system supports a directory structure (of any depth) with path directory names delimited by either a forward slash (/) or a backslash (\). Directory and file names are limited to 128 characters in length, and the maximum path length is 256 characters. The file system root directory is designated by a single forward slash (/) or backslash (\). Any path beginning with / or \ starts at the root directory. If a path does not start with / or
Description: This function creates a new directory in the file system at the specified location. If the path included in “{name}” begins with / or \, it starts with the root directory; otherwise it is relative to the current directory. 4.16.3 ChangeCurDir Syntax: changecurdir(name[] as reference? to byte)
Parameters: {name} A string containing the desired path and directory name to make the current directory. Description: This function changes the current directory to the specified directory.
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770
Page 91
QSI Qlarity-based Terminal Programmer’s Reference
79
4.16.4 GetCurDir
4.16.7 GetFileInfo
Syntax:
Syntax:
getcurdir() returns string getfileinfo(name[] as reference? to byte, -> size as reference to integer, -> usedfilespace as reference to integer, -> flags as reference to fileinfo_flags)
Description: This function returns a string containing the current directory. 4.16.5 GetDirEntry Syntax: getdirentry(index as integer) returns string
Parameters: {index} The index of the desired directory entry (see below). Description: This function lists the contents of the current directory. If “{index}” is 0, the first entry in the current directory is returned. Subsequent calls to GetDirEntry() with “{index}” set to -1 return subsequent entries in the directory. An empty string ("") is returned if no more entries are available. If the file system is accessed with other API function calls that alter the file system or current directory (such as ChangeCurDir()), GetDirEntry(0) should always be called before GetDirEntry(-1) or the returned results will be invalid. Calling GetDirEntry(N) will return the Nth entry in the directory or an empty string ("") if the Nth entry does not exist. 4.16.6 EraseFile Syntax: erasefile(name[] as reference? to byte)
Parameters: {name} A string containing the name (possibly including path) of the file to remove.
Parameters: {name} A string containing the name (possibly including path) of the desired file. {size} A variable to receive the size of the file in bytes (directories return a size of 0 bytes). {usedfilespace} A variable to receive the number of bytes allocated to the file by the file system (which includes file system overhead). {flags} A variable of type “fileinfo_flags” to receive information about the file (see below). Description: This function returns information about a file in the file system. The actual size of the specified file is returned in the “{size}” variable. The number of bytes that the file consumes in the file space is returned in the “{usedfilespace}” variable. The “{flags}” parameter is a variable of type “fileinfo_flags,” which can take on the following legal values (logically ORed together): FILEINFO_ISTEXT Indicates that the file was created in text mode. FILEINFO_ISBIN Indicates that the file was created in binary mode. FILEINFO_ISDIR Indicates that the file is a directory.
Description: This function removes the specified file from the file system. If the path included in “{name}” begins with / or \, it starts with the root directory; otherwise it is relative to the current directory. This function also erases directories.
FILEINFO_ISOPEN Indicates that the file has been opened with a previous call to OpenFile().
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770