CX-Server Lite User Manual

CX-Server Lite User Manual

OMRON

Getting Started with CX-Server Lite

‘Set the device to remote mode

Comms1.TCRemoteLocal "E5AK”, 0

PLC Memory Functions (A, AR, C, CIO, D, DM, DR, E, EM, G, H, HR,

IR, LR, SR, ST, T, TC, TK, W)

All PLC memory functions (e.g. A, AR, D, DM etc.) work in exactly the same way. The following examples use the DM function to get and set the value of a DM address in a PLC.

Example 1

intVal = Comms1.DM(100)

In this example, the contents of DM100 will be read from the PLC and stored in ‘intVal’.

Note:

These examples assume there is only 1 PLC in the CX-Server project file, or that the ‘SetDefaultPLC’ function has been used to select the required PLC.

Refer to the ‘SetDefaultPLC’ function for details about using script with multiple

PLCs in the project.

Example 2

Comms1.DM(100) = 75

In this example, the value 75 will be written to DM100 in the PLC.

Bit addressing, that is accessing data from individual memory bits, is also supported by these memory areas: IR, AR, HR and CIO.

Example 3

intVal = Comms1.IR(“100.2”)

In this example, the status of bit IR100.2 (i.e. bit 2 of IR100) will be read from the PLC and stored in ‘intVal’ (e.g. ‘value’ will be set to TRUE or FALSE).

Example 4

Comms1.IR(“100.2”) = True

In this example, bit IR100.2 (i.e. bit 2 of IR100) in the PLC will be set to True. Note that use of the quotes is optional, but is required to differentiate between 100.1 and 100.10

SetDeviceAddress [Advanced function]

This function is for advanced users only

. This function can be used to set key elements of a device address (the network number, node number, unit number and Ethernet IP address). The numbers are in the range 0 to 255, with -1 being used to denote “ignore this parameter”.

Note: this method does not interpret the data passed, and it is possible to pass invalid data that will prevent a device communicating. Care should be taken to ensure that all data passed is valid. This method should not be used while a PLC is open and communicating.

Page 43

OMRON

VBA (e.g. Excel) Example 1

Getting Started with CX-Server Lite

NetworkNum = 1

NodeNum = 2

UnitNum = -1 iPAddress = “10.0.0.1” b Valid = Comms1.SetDeviceAddress ("PLC1", NetworkNum, NodeNum, UnitNum, IPAddress)

Note: The return Boolean value, bValid, is set to True if no errors were detected. However, this does not necessarily mean that all the parameters used were valid or appropriate for the PLC being used.

SetDeviceConfig [Advanced function]

This function is for advanced users only

. This is a function that can be used to set any element of CX-Server device configuration. All the data is passed in textual form.

Note: this method does not interpret the data passed, and it is possible to pass invalid data that will prevent a device communicating. Care should be taken to ensure that all data passed is valid. This method should not be used while a PLC is open and communicating.

Currently supported values are:

VBA (e.g. Excel) Example

Device = “PLC1”

Section = “ADDRESS”

Entry = “IPADDR”

Setting = “10.0.0.1” bValid = Comms1.SetDeviceConfig( Device, Section, Entry, Setting)

Note: The return Boolean value, bValid, is set to True if no errors were detected. However, this does not necessarily mean that all the parameters used were valid or appropriate for the device being used.

CX-Supervisor script example:

CXServer.SetDeviceConfig "MyPLC", "ADDRESS", "IPADDR", "10.0.0.1"

This function is primarily intended for future use. Only the following Section, Entry and Setting parameter value combinations are currently supported:

Section = “ADDRESS”, Entry = “DNA”, Setting = “0”..Setting = “255” - this can be used to set the network number

Section = “ADDRESS”, Entry = “DA1”, Setting = “0”..Setting = “255” - this can be used to set the node number

Section = “ADDRESS”, Entry = “UNIT”, Setting = “0”..Setting = “255” - this can be used to set the unit number

Page 44

OMRON

Getting Started with CX-Server Lite

Section = “ADDRESS”, Entry = “IPADDR”, Setting = “0.0.0.0”..Setting = “255.255.255.255” - this can be used to set the Ethernet IP address

Other parameter values may work, but should only be used on Omron advice.

GetDeviceConfig [Advanced function]

This function is for advanced users only

. This is a function that can be used to read any element of the CX-Server device configuration. All the data is passed (and received) in textual form.

VBA (e.g. Excel) Example 1

Dim Setting As String

Device = “PLC1”

Section = “ADDRESS””

Entry = “IPADDR”

Setting =

Comms1.GetDeviceConfig( Device, Section, Entry)

CX-Supervisor script example:

IPAddrPoint = CXServer.GetDeviceConfig("MyPLC", "ADDRESS", "IPADDR")

Currently supported parameter values are as described for the SetDeviceConfig method.

UploadProgram [Advanced function]

This function is for advanced users only

. The UploadProgram function can be used to read a program (or other file) from a PLC. The program is read in binary form, and stored in a userspecified file. This function should not be used at the same time as any other PLC communications. The project and PLC will automatically be opened if required.

VBA (e.g. Excel) Example 1

Dim Source As String

Dim DestinationFile As String

Source = “”

DestinationFile = “ c:\test1.bin”

Comms1.UploadProgram "PLC1", Source, DestinationFile, WaitUntilComplete, True

VBA (e.g. Excel) Example 2

BValid = Comms1.UploadProgram ("PLC1", "ALL", "c:\test1.bin", WaitUntilComplete,

True)

Page 45

OMRON

Getting Started with CX-Server Lite

Note: The parameters, in order, are the PLC name, the source (see below), the destination file,

WaitUntilComplete (value 0) or NoWaiting (value 1), and whether to report on progress.

Possible values for the source parameter are as follows:

“” (i.e. an empty string) – will upload the program (object) file only

“PRG” – same as above, will upload the program (object) file only

“FBL” – will upload the Function Block Library file (The Function Blocks associated with a program)

“ALL” – will upload both the program file and the Function Block file. The Function Block file will be given the same name as the destination file except that a .FBL extension will be used. Note that currently use of this setting will force the wait setting to always be interpreted as

“WaitUntilComplete” as the program and FB upload need to occur consecutively.

“CANCEL” – will cancel (abort) any current upload. The program is uploaded on a block-byblock basis, and the cancel status is checked after each block is uploaded, so it is possible that an upload will complete before the cancel takes effect. In that case the cancel command will be ignored.

Any other value – will be interpreted as the name of a file in the root directory of a memory card, e.g. “Example.obj”

The second example shows that this method returns a Boolean value, which is set to True if no errors are detected (but note that if the command is used with NoWaiting, then an error may occur after the method returns but before the operation is complete, and must be detected via the OnData routine - see below).

If progress reporting is set, then the progress updates will be provided via the OnData callback.

The format of this is:

Private Sub Comms1_OnData(ByVal PLC As String, ByVal Point As String,

ByVal Value As Variant, ByVal BadQuality as Boolean)

End Sub

When used with program upload reporting, the parameters are used as follows:

PLC – Name of PLC

Point – “UPLOAD:START” or “UPLOAD:RECEIVED” or “UPLOAD:COMPLETE” or

“UPLOAD:ERROR” or “UPLOAD:CANCELLED”

Value – For “UPLOAD:START” this is the total number of bytes to upload (i.e. file size)

For “UPLOAD:RECEIVED” and “UPLOAD:COMPLETE” and “

UPLOAD:CANCELLED” this is the total bytes uploaded so far.

For “UPLOAD:ERROR” this is a CX-Server error code (e.g. 35339 which is 8A0B in hexadecimal, indicates the PLC is in the wrong mode)

Page 46

OMRON

DownloadProgram [Advanced function]

Getting Started with CX-Server Lite

This function is for advanced users only

. The DownloadProgram function can be used to write a program to a PLC. The PLC

must

be in program mode before DownloadProgram is used.

Care should be taken with this function to ensure that the program written is valid for the

PLC to which it is downloaded. In addition, users should be aware that downloading the program object code on its own clears the associated function block area. If a program uses function blocks then the associated function block file

must

be downloaded to the

PLC before the PLC program is run, or a PLC error condition will occur. Any attempt to download a function block to a PLC that does not support FBs will result in an error on download.

This function should not be used at the same time as any other PLC communications. The project and PLC will automatically be opened if required.

VBA (e.g. Excel) Example 1

Dim SourceFile As String

Dim DestinationFile As String

SourceFile =

"c:\test2.bin"

Destination = “ALL”

Comms1.DownloadProgram "PLC1", SourceFile, Destination, WaitUntilComplete, True

VBA (e.g. Excel) Example 2

bValid =Comms1.DownloadProgram("PLC1", "c:\test2.bin", "", WaitUntilComplete, True)

Note: The parameters, in order, are the PLC name, the source file, the destination (see below),

WaitUntilComplete (value 0) or NoWaiting (value 1), and whether to report on progress.

Possible values for the destination parameter are as follows:

“” (i.e. an empty string) – will download the source file as a PLC program (object file) only. This clears the function block area - if the program references any function blocks then these

must

be downloaded (using the FBL parameter) before the PLC is run, or a PLC error condition will occur.

“PRG” – same as above, will download the source file as a PLC program (object file) only. This clears the function block area - if the program references any function blocks then these

must

be downloaded (using the FBL parameter) before the PLC is run, or a PLC error condition will occur.

“FBL” – will download the source file as a Function Block Library file (The Function Blocks associated with a program). Note: The PLC must support function blocks, and the downloaded function blocks must match the PLC program or an error will occur when downloading.

Page 47

OMRON

Getting Started with CX-Server Lite

“ALL” – will download the program file and then any associated Function Block file. The

Function Block file will be downloaded from a file with the same name as the source file except that a .FBL extension will be used. If the FBL file does not exist then only the program file will be downloaded. If a suitably named FBL file is found, then the PLC must support function blocks, and the downloaded function blocks must match the PLC program or an error will occur when downloading. Note that currently use of this setting will force the wait setting to always be interpreted as “WaitUntilComplete” as the program and FB download need to occur consecutively.

“CANCEL” – will cancel (abort) any current download. Care should be taken to ensure that a valid program is downloaded after using this command, otherwise the contents of the PLC are likely to be invalid. The program is downloaded on a block-by -block basis, and the cancel status is checked after each block is downloaded, so it is possible that a download will complete before the cancel takes effect. In that case the cancel command will be ignored.

Any other value – will be interpreted as the name of a file, e.g. “Example.obj”, in which case a file of that name will be created or overwritten in the root directory of a memory card

The second example shows that this method returns a Boolean value, which is set to True if no errors are detected (but note that if the command is used with NoWaiting, then an error may occur after the method returns but before the operation is complete, and must be detected via the OnData routine - see below).

If progress reporting is set, then the progress updates will be provided via the OnData callback.

The format of this is:

Private Sub Comms1_OnData(ByVal PLC As String, ByVal Point As String,

ByVal Value As Variant, ByVal BadQuality as Boolean)

End Sub

When used with program download reporting, the parameters are used as follows:

PLC – Name of PLC

Point – “DOWNLOAD:START” or “DOWNLOAD:SENT” or “DOWNLOAD:COMPLETE” or

“DOWNLOAD:ERROR” or “DOWNLOAD:CANCELLED”

Value – For “DOWNLOAD:START” this is the total number of bytes to upload (i.e. file size)

For “DOWNLOAD:SENT” and “DOWNLOAD:COMPLETE” and

“DOWNLOAD:CANCELLED” this is the total bytes downloaded so far.

For “DOWNLOAD:ERROR” this is a CX-Server error code (e.g. 35339 which is

8A0B in hexadecimal, indicates the PLC is in the wrong mode)

Protect [Advanced function]

This function is for advanced users only

. The Protect function can be used to protect (or remove protection from) PLC program memory. This function should not be used at the same

Page 48

OMRON

Getting Started with CX-Server Lite

time as any other PLC communications. The project and PLC will automatically be opened if required.

VBA (e.g. Excel) Example 1 (sets protection for CS series PLC)

Dim SetProtection as Boolean

Dim PasswordString As String

Dim PasswordNumber As Long

EnableProtection = true

PasswordString = “Password”

PasswordNumber = 0

Comms1.Protect “PLC1”, EnableProtection, PasswordString, PasswordNumber

VBA (e.g. Excel) Example 2 (unsets protection for C series PLC)

Dim SetProtection as Boolean

Dim PasswordString As String

Dim PasswordNumber As Long

EnableProtection = false

PasswordString = “”

PasswordNumber = 12345678

Comms1.Protect “PLC1”, EnableProtection, PasswordString, PasswordNumber

Note: The parameters of this command are, in order:

PLC – Name of PLC

EnableProtection – true to set password protection, false to unset it

PasswordString – Password as a string. For CS series PLCs this should be a string of up to 8 characters. For CV PLCs this should be a string of up to 8 characters containing a hexadecimal number, e.g. “12345678”. For C series PLCs this should be a string of up to 4 characters containing a hexadecimal number, e.g. “1234”.

PasswordNumber – currently this is only used for C and CV series PLCs, and only when the password string is empty. In those circumstances it is simply a number representing the value of the 4 or 8 digit password. Please note that the password is entered in CX-Programmer as a hexadecimal string (as with the PasswordString parameter above), and that, for example, the value 1234 in decimal is the equivalent to “04d2” as a hexadecimal password string.

Page 49

OMRON

Getting Started with CX-Server Lite

Additional C Series PLC notes: For C series the PLC program needs code (the first line of the application) in the PLC to enable password setting/release, and this fixes the password value. e.g. LD AR10.01

FUN49 0 0 #1234 (#1234 – password value in Hex)

When

setting

the password this value is used rather than the value passed – i.e. the password string or number is ignored. The correct password must be provided, however, when disabling the password protection.

InitCXServer [Advanced function]

This function is for advanced users only

. The InitCXServer function is

not

normally required. It is intended for use only in certain specialised situations, e.g. it may be of use in a multithreading environment, to initialise worker threads before the first CX-Server function in that thread is called. It should not be used in the main thread, and, in general, it should only be used on advice from Omron. An appropriate Microsoft COM initialisation method, e.g. CoInitialize or

CoInitializeEx, may also need to be called within the thread before this method is called.

C++ examples: m_CommsCtrl.InitCXServer(true); // Initialises CX-Server within a thread m_CommsCtrl.InitCXServer(false); // Uninitialises CX-Server within a thread

The unitialise example should only be used when no further CX-Server functionality is required within a thread.

NumErrors

This property, which can be set as well as read, is a count of the number of errors that have occurred since the Lite control was first run.

Excel Examples:

Cells(2,2) = Comms1.NumErrors

Comms1.NumErrors = 0;

LastErrorString

This property, which can be set as well as read, is a textual description of the last error that occurred. If none have occurred, it is blank.

Excel Examples:

Cells(2,2) = Comms1.LastErrorString

Comms1.LastErrorString = “No more yet”

Page 50

OMRON

AboutBox

Brings up the About Box.

Example

Comms1.AboutBox

Help

Brings up the Help information.

Example

Comms1.Help

Getting Started with CX-Server Lite

Page 51

Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project