Basic programming guide – Remote Processing BASIC for the CX-10 Modbus User Manual

Page 72

Advertising
background image

BASIC PROGRAMMING GUIDE

2-63

Syntax:

A = STR(7,$(put),$(get),position,length)

Description:

Extracts a portion of a string from $(get) and transfers it over to $(put). The actual number of characters
moved is returned. position starts at 1. When position is 0, no characters are placed into $(put) regardless of
length. When length is 0, all characters are copied from $(get) to $(put) starting at position.

Example:

10

STRING 200,20

20 $(0) = "123456.789"
30 A = STR(7,$(1),$(0),3,5)
40

PRINT $(1)

50

PRINT "Length:",A

run
3456.
Length: 5

Syntax:

A = STR(8,$(search),$(substring))

Description:

Scans $(search) for occurrence of substring. Returns position where entire substring first matches search
string. Returns 0 when substring is not in search string.

Example:

10

STRING 200,20

20 $(0) = ">05M34C3"
30 $(1) = "05M"
40 A = STR(8,$(0),$(1))
50

PRINT "Position match at:",a

run
Position match at: 2

The number '0' in $(1) matches $(0) at position 2.

Syntax:

A = STR(9,$(string1),$(string2))

Description:

Compares string1 to string2. Returns position of first mismatch. If both strings exactly match, then 0 is
returned.

Example:

10

STRING 200,20

20 $(0) = ">05M34C3"
30 $(1) = ">05"
40 A = STR(9,$(0),$(1))
50

PRINT "Mismatch starting at:",a

run
Mismatch starting at: 4

Since the first three character positions matched, position 4 is returned as the longer string did not match the
shorter one.

String functions 8 and 9 are useful in RS-485 network communication. In the above example, ">05" could be
the RPC-320's address. Knowing the mismatch starts at position 4, the address can be assumed correct. If the
mismatch started sooner, a smaller number is returned. Hence, the message was not intended for this
particular card and the entire message can be flushed.

Advertising