LINEIN Read one or more characters from COM port |
Top Previous Next |
This script command receives characters from an open COM port and saves the characters in a string variable. The various options control how many characters are received.
This command is generally used to accept printable characters from the COM port. By default FileLink removes any unprintable characters before they are saved in the specified variable. If the loss of unprintable character alters the resulting string in an undesirable way by altering character position, for example, you may use the /allowall option. When this option is used, the relative character position of the string is preserved by replacing the unprintable characters with the configured LINEIN fill character. The fill character defaults to a space.
By default, LINEIN terminates when a carriage-return character is received. You may alter this behavior by using either the /termchr=lf or /termchr=none options. LINEIN also terminates if the maximum number of characters has been received, when a user-defined string pattern is detected, or a time-out expires.
If /termchr=none is specified and /termseq is not, LINEIN terminates after a fixed number of characters has been received - either the number specified by the /length option or the default value of 1020 characters.
Consider the following examples.
;; read until exactly 10 characters have been received LINEIN comdata /termchr=none /length=10
;; read until a line-feed is received or 10 seconds elapses LINEIN comdata /termchr=lf /timeout=10
;; read until string "/end" is received or end of line LINEIN comdata /termseq="/end"
;; read until a line-feed or semi-colon is received LINEIN comdata /termchr=lf /termseq=";"
The following is a more specific example showing how the LINEIN command may be used to scan incoming characters for a specific prompt. For the sake of this example, let’s assume that the remote system sends the following banner and user name prompt immediately after a connection is established.
Welcome to Bozo World Home of the Funniest Clown on Earth To chat with Bozo, please sign in
Username:
One way to handle this character sequence would be to use four LINEIN statements in the FileLink script file. This is fine when you can be certain that the prompt is always to be found in the fourth line. However, using a single LINEIN command, as shown below, is simpler and more dependable since it is not dependent on knowing how many lines there will be before the prompt appears.
LINEIN bozo /termchr=none /termseq="Username:" /timeout=30
If you are unsure of the number of characters that may be received before the prompt, or if this number may be greater than 1020, add the /length=0 option to the command. This results in FileLink discarding all the received characters except for the terminating sequence. It is strongly recommended that you use the /timeout option in this case to prevent the LINEIN command from hanging in any case where the terminating sequence is not received.
LINEIN bozo /termchr=none /termseq="Username:" /length=0 /timeout=30
Related Command(s): FLUSH, LINEOUT, READFILE, WRITEFILE
|