Removing Data From Buffers - Crestron SIMPL+ Programming Manual

Crestron simpl+ software: software guide
Hide thumbs Also See for SIMPL+:
Table of Contents

Advertisement

Crestron SIMPL+
Programming Guide – DOC. 5789A
second pass:
jukebox_in = "k=My Way, Album=Very Good Yea"
third pass:
jukebox_in = "rs<CR>"
If this signal, jukebox_in, were then connected to a STRING_INPUT of a SIMPL+
program, it is likely that the string might not be seen as one complete piece. Thus the
artist's name, the track name, and the album name might not be parsed out for
display on a touchpanel. On the other hand, if a BUFFER_INPUT were used instead,
this buffer would collect the data as it arrived. Therefore, after the processor read the
port the third time, this BUFFER_INPUT would contain the complete string.

Removing Data From Buffers

Once data has been routed into a BUFFER_INPUT, techniques are required to
extract data from it. Typically the first thing to be done with data on a
BUFFER_INPUT is to pull off a completed command and store it into a separate
variable. For example, most data that comes from other devices are delimited with a
certain character (or characters) to denote the end of the command. In many
instances a carriage return (or carriage return followed by a line feed) is used.
The getc function is the most basic way to remove data from a buffer. Each call of
getc pulls one character out of the buffer and returns that character's ASCII value as
the function's return value. Characters are removed from the buffer in the order they
arrived. Thus the first character in becomes the first character out. This function now
provides the ability to extract data until the desired delimiter is seen. For example,
the following code is read data from the buffer until a carriage return is seen.
BUFFER_INPUT data_in[100];
INTEGER nextChar;
STRING temp[50], line[50];
CHANGE data_in // trigger whenever a character comes in
{
do
{
nextChar = getc(data_in); // get the next character
temp = temp + chr(nextChar);
if (nextChar = 0x0D) // is it a carriage return?
{
line = temp;
temp = "";
}
} until (len(data_in) = 0) // empty the buffer
}
Function Main()
{
temp = "";
}
Software
• 47
SIMPL+

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents