SET INPUT
Specifies the current input document.
Syntax
SET INPUT docname [FILEPATH options]Parameters
| docname | The name of the application document to which all output is to be sent. Can also be one of the two pre-defined application documents, terminal or printer. |
| FILEPATH options | Specifies that the input document will be governed by the options as follows: file://<the full path of a text file> – subsequent ZIM statements referring to the docname above will read this physical file instead; port://name:speed:bits:parity:stopbits:CTS – It only works for Linux environments and specifies a serial port to be read; connector://IP address:port – reads from the specified IP address (or URL) using that port number; pipe://<OS command> – executes the OS command. fifo://<FIFO name> – reads records from the FIFO name. |
Comments
The SET INPUT defines an input for subsequent Zim commands referring to the defined docname. The input is maintained open until it is explicitly closed by a SET INPUT TERMINAL or another document name.
Usually, the docname is defined as structured with a big field (big enough for the required application) so that the contents of the records read can be processed.
The FIFO option reads from an internal stack of records previously written via the SET OUTPUT command. The <FIFO name> is any name used to identify this FIFO. Usually, many programs (producers) can write to a FIFO whereas only on program (consumer) can read from a FIFO. It works similarly to an entity set with the difference that all operations are in memory (faster and with no locks) and, once a record is read, that record disappears from the stack. This means that you cannot create a set from these records as they are lost immediately. It’s contents are usually collected via a COMPUTE 1 … EVALUATE or LIST 1 EVALUATE, most of the time, one by one.
Under Windows, if a path contains subdirectories, they must be converted from “/” to “\\”. Otherwise, Windows will interpret them as command switches as seen in the examples below.
Examples
set input MyDoc list 1 MyDoc compute 1 MyDoc evaluate (let MyVariable = MyDocField) ... process MyVariable ... list 1 MyDoc set input terminal
The above example is very useful as it allows continuous records to be read from MyDoc without starting from its beginning all the time. The first record of MyDoc is listed, the second is processed, while the third is again listed. Finally, the document is closed.
The next example shows the combination of INPUT and OUTPUT documents. The output is MyReport. All records from FirstFile.txt are listed in the output. Then, 20 records from Zimprof are listed. Next, 10 records from SecondFile.txt are listed and, finally, all records from AnotherDoc are also listed. To wrap up, both INPUT and OUTPUT are closed by assigning them to TERMINAL.
set out MyReport set input MyDoc filepath "file://c:\\myDir\\FirstFile.txt" list all MyDoc list 20 zimprof set input MyDoc filepath "file://c:\\myDir\\SecondFile.txt" list 10 MyDoc list all AnotherDoc set input terminal set output terminal
This example reads and processes all input arriving from a serial port (only for Linux).
set input MyDoc filepath "port:///dev/tty99:115200:8:N:1:N" while ... compute 1 MyDoc evaluate (let MyVariable = MyDocField) ... process MyVariable ... endwhile set input terminal
Executes an OS command and captures its output (i. e. STDOUT).
% In this case, data is formatted. % You can add the lines directly but you need to filter the useful ones. set input MyDoc filepath "pipe://dir ..\\Images\\*.jpg" list all MyDoc Directory: C:\users\cebre\pictures Mode LastWriteTime Length Name ------ ----------------- ------- ------------------- -a---- 21-Oct-2023 09:45 2885941 20200827_114259.jpg -a---- 21-Oct-2023 09:42 2555772 20200827_114311.jpg set input terminal
This example reads and processes records stored in a FIFO:
set input MyDoc filepath "fifo://myfifo" while ... compute 1 MyDoc evaluate (let MyVariable = MyDocField) ... process MyVariable ... endwhile set input terminal
