ReadArea Appendix B CX-Server Communications Control
132
In this example, 'NewValue' will be written to the point 'MyPoint' in the PLC
called 'MyPLC'. The script will wait for the write operation to complete before
continuing to execute the next line due to the '0' parameter. This is identical to
the operation of the 'Value' method.
B.9 ReadArea
Reads a specified block of memory from a PLC.
Examples of synchronous read:
MyVariant = CXServer.ReadArea("MyPLC/DM0", 12, vbString)
MyVariant = CXServer.ReadArea("BoilerTemp",10, vbInteger)
MyVariant = CXServer.ReadArea("BoilerTemp", 20)
In the first example, DM0 to DM11 will be read as characters (part of a string)
from 'MyPLC' and will be stored in 'MyVariant'. The second example
demonstrates that it is also possible to use a logical name for the start
address, and that any VB variant types (such as vbInteger) can be used. The
third example shows that the VB Variant type parameter is optional - if none is
specified then vbInteger is assumed. The script will wait for the read operation
to complete before continuing to execute the next line.
Note: If the PLC is not open, then this command will cause it to be opened, and then
closed after the write is complete. If more than one read or write operation is
to be performed, it is considerably faster and more efficient to use the
OpenPLC command first, do all the reading and writing, and then (if required)
use the ClosePLC command to close the PLC.
Note: If accessing from a CX-Supervisor script, the following integral values should
be used for the return type:
Constant Value Description
vbEmpty 0 Uninitialized (default)
vbNull 1 Contains no valid data
vbInteger 2 Integer subtype
vbLong 3 Long subtype
vbSingle 4 Single subtype
vbSingle 5 Double subtype
vbCurrency 6 Currency subtype
vbDate 7 Date subtype
vbString 8 String subtype
vbObject 9 Object
vbError 10 Error subtype
vbBoolean 11 Boolean subtype
vbVariant 12 Variant (used only for arrays of variants)
vbDataObject 13 Data access object
vbDecimal 14 Decimal subtype
vbByte 17 Byte subtype