11.07.2015 Views

BCL Programmers Manual V2.00 (PDF) - Barix

BCL Programmers Manual V2.00 (PDF) - Barix

BCL Programmers Manual V2.00 (PDF) - Barix

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

FIRST$ = "Hi,"'assign value to the FIRST$ variableSECOND$ = " everything OK!" 'assign value to the SECOND$ variableCONCAT$ = FIRST$+SECOND$SYSLOG CONCAT$'syslog concatenationSyslog output will be the same as in the previous example.String variables should be declared with the DIM command at the beginning of the programfor better code legibility. If DIM is omitted, variables are declared implicitly.At startup string variables are initialized to an empty string.By default the maximum length of string variables is 256 characters. String variables longerthen 256 characters must be declared using the DIM command, with syntax DIM NAME$(SIZE), as in the following example:DIM LONG$(600) 'LONG$ can hold 599 charactersLONG$="........"'assign 8 dotsLONG$=LONG$+LONG$+LONG$+LONG$ 'assign 32 dotsLONG$=LONG$+LONG$+LONG$+LONG$ 'assign 128 dotsLONG$=LONG$+LONG$+LONG$+LONG$ 'assign 512 dotsThis program creates a string consisting of 512 dots to syslog (useful probably only as anexample). For normal use, string variables are terminated with a trailing zero character, so avariable dimensioned to a size of 600 can hold a string of maximum 599 characters.Commonly used string constants (like the CR/LF newline sequence) can be defined in astring, which can save code space. However, these strings should be dimensioned with theDIM command before assigning them to avoid excessive memory usage.DIM CR$(3)CR$="\r\n"'newline sequenceNote: String array is not available in <strong>BCL</strong>. If needed, it can be simulated with one longstring using string functions to access substrings.5.5 Binary arraysStrings can be used as binary buffers (e.g. when reading/writing files) or as bit or byte arrays.E.g. when interfacing to a security system with 300 rooms where there is an 8-bit state foreach room, it is better to store the states into a string variable (DIM it with a length of 300bytes) instead of an integer array. This way memory can be saved because an integer array ofthe same size would need four times more memory (integers are 32-bit).When storing binary data into a string, the string concatenation operation can not be used,since binary data may contain the 0 character which is a string terminator in text mode.Therefore it's always necessary to work with the string and its length (in separate variable)and concatenate strings with MIDCPY. To access elements of a binary array useMIDSET/MIDGET commands.For string calculations <strong>BCL</strong> uses a temporary buffer with a size of the largest string variabledeclared (if it exceeds 256 bytes a warning will be issued to the tokenizer console). If thestring is not going to be used for calculations (typically if it is a binary working buffer forMIDSET/MIDCPY/MIDGET commands), the string name should start with the "_M" prefix toavoid changing of the internal string buffer. The "_M" prefix counts as two of the fivesignificant variable name characters.<strong>Barix</strong> AG | 15/106

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!