SetDefaultPLC Appendix B CX-Server Communications Control
131
B.4 SetDefaultPLC
The 'SetDefaultPLC' function can be used to inform the script parser that a
particular PLC is has been set as the default. Once a default PLC has been
set, then it is not necessary (with some functions) to specify a PLC name. For
example,
CXServer.SetDefaultPLC("MyPLC")
intVal = CXServer.Value("BoilerTemp1")
CXServer.Value("BoilerTemp1") = 75
intVal = CXServer.Value("DM50")
Each 'Value' function above will access data in the PLC called 'MyPLC'.
B.5 OpenPLC
Opens a PLC for communications. If no PLC is specified then the default PLC
is opened.
Example 1:
CXServer.SetDefaultPLC("MyPLC")
CXServer.OpenPLC()
CXServer.DM(100) = 10
CXServer.DM(50) = 10
Example 2:
CXServer.OpenPLC("MyPLC")
CXServer.DM(100) = 10
B.6 ClosePLC
Closes a previously opened PLC. If no PLC is specified then the default PLC
is closed.
Example:
CXServer.ClosePLC("MyPLC")
B.7 Read
Function to read the value of a PLC point.
Example of synchronous Read
intVal = CXServer.Read("MyPLC", "MyPoint", 0)
In this example, the Point 'MyPoint' will be read from the PLC 'MyPLC' and
stored in 'intVal'. The script will wait for the read 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.8 Write
Function to write the value of a PLC point.
Example of synchronous write:
CXServer.Write("MyPLC", "MyPoint", NewValue, 0)
Note: If there is only 1 PLC in the project then it is not necessary to call the
'SetDefaultPLC' function. The first PLC in a project will automatically be set as
the default PLC.
Note: If the PLC is not open, then this command will cause it to be opened, and then
closed after the read 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.