Formatting Text and Serial Data Output |
|
Numbers can now be formatted for storing into text vars, text areas, and
transmission from serial ports. Uses %fomat% in front of a variable. The following examples use a variable VAR containing a value of 2031 and VARF containing 3.1415927 Decimal - s or no format supplied > text(tx,VAR);; -> shows "2031" > load(rs2,%%VAR); -> outputs "2031" > var(txVar,%s%VAR); -> stores "2031" Hex - h or H to store variable as hex where h=lowercase a-f, H = uppercase A-F. > text(tx,%h%VAR);; -> shows "7ef" > text(tx,%H%VAR);; -> shows "7EF" Use h1 to h8 and H1 to H8 to store a variable with a field width where padding uses spaces > text(tx,%H8%VAR);; -> shows " 7EF" > text(tx,%h2%VAR);; -> shows "7ef" Use h01 to h08 and H01 to H08 to store a variable with a field width where padding uses 0's > text(tx,%H08%VAR);; -> shows "000007EF" > text(tx,%h02%VAR);; -> shows "7ef" Float - f to store variable as float > text(tx,%f%VARF);; -> shows "3.141593" f1 to f8 to store variable with number of decimal places > text(tx,%f4%VARF);; -> shows "3.1416" > text(tx,%f8%VARF);; -> shows "3.14159270" Raw - r to store variable as raw number > text(tx,%r%51);; -> shows "3" C-Library printf format - * followed by standard C-library printf() formatting parameters > text(tx,%*08X%VAR);; -> converts to "%08X" and shows "000007EF" > text(tx,%*+d%VAR);; -> converts to "%+d" and shows "000007EF" > text(tx,%*e%VARF);; -> converts to "%e" and shows "3.141593e+00" Convert to Unicode - %w% and Convert to UTF-8 - %m% Convert to Unicode ------------------ * Added %w% formatting character to convert characters to Unicode Characters * For Sending on Serial Port (set with encode=sr;): LOAD( varTxDataTxt, "\\w0033\\w0034\\w0144", %w%45 ); LOAD( AS2, %w%varTxDataTxt, "\\00\\03" ); // Will send 00 33 00 34 01 44 00 45 00 03 * For receiving on serial Port (set with encode=sr;): LOAD( varRxDataTxt, AS2 ); TEXT( txtMsg1, %w%varRxDataTxt );; * For converting text // varRxData = 0000 0033 0000 0034 0001 0044 0000 0045 LOAD( varRxDataTxt, %w%varRxDataTxt ); // varRxData = 0033 0034 0144 0045 * Added additional functionality to convert characters from an U8/S8 array LOAD(txtRxData,"\\22",%w%varRxArr,"\\22"); // 5. From Array formatted into text with LOAD() Convert to UTF-8 ---------------- * Added %m% formatting character to convert characters to UTF-8 Characters * Works with sources of serial ports, text, text variables and U8/S8 arrays TEXT(txtRxData,%m%AS2); // 1. Directly from port formatted into TEXT() TEXT(txtRxData,%m%varRxData); // 2. From text var formatted into TEXT() LOAD(varRxData,%m%AS2); // 3. From port formatted into text var LOAD(txtRxData,"\\22",%m%varRxData,"\\22");; // 4. From text var formatted into text with LOAD() LOAD(txtRxData,"\\22",%m%varRxArr,"\\22"); // 5. From Array formatted into text with LOAD() LOAD(varA,%m%varRxData); // 6. From text var to text var Arrays Support for loading arrays into text boxes and text variables and support for loading text into arrays added. The %t% and %r% formatting characters are used when working with arrays and text. The %t% operator observes NUL characters as string terminators, the %r% operator processes all characters the same. |