How Can I Change PLC Communication Settings From Within A CX-Supervisor Application?


Sometimes you may wish to change the PLC settings while an application is running. This can be particularly useful if you need to communicate with multiple PLCs of the same type but don't wish to (or can't) configure 100s of PLCs in your application. This can also be useful if you communicate with multiple PLCs via a modem and want to connect to them by changing just the phone number at runtime.


Since CX-Supervisor V2.0 there has been the option to use an embedded CX-Server Lite ActiveX component (included free with CX-Supervisor) which allows you to use CX-Server Lite commands within scripts on the PLC configured in CX-Supervisor.
To use this functionality you must first configure CX-Supervisor to use this embedded CX-Server Lite component and also use an external configuration file (CX-Server cdm file) rather than an internal configuration. To do this you must first click Project->Runtime Settings->Advanced Settings, this displays a dialog containing advanced settings for the project:
The bottom item in this dialog gives you the option of embedding the CX-Server project within the CX-Supervisor project - this option must not be checked.
Next you must choose Project->Runtime settings->Startup Conditions, this displays the following dialog:
The bottom section has the option to Allow script access to PLC via "CXServer" control, this item must be checked.
Once these settings are applied you are ready to use the CXServer control in your scripts. This article has an attached CX-Supervisor project with an example of how to change the IP address and Node of a PLC.

In this project, there are 3 buttons, the first shows the current details using:

mydeviceconfig = CXServer.GetDeviceConfig ("myplc", "ADDRESS", "" )

The second sets the device config using the SetDeviceConfig command:

CXServer.SetDeviceConfig "myplc", "ADDRESS", "IPADDR", ""
CXServer.SetDeviceConfig "myplc", "ADDRESS", "DA1", "73"

The Third sets the device config using the SetDeviceAddress command

CXServer.SetDeviceAddress "myplc", 4, 74, -1, ""
You can choose to use either of these two solutions to change the IP address of a PLC, however using SetDeviceAddress makes it much simpler.  Note: you must always close the PLC before changing the setting.
If you want to change the phone number of a modem connected PLC you must use the SetDeviceConfig command as follows:

CXServer.SetDeviceConfig "myplc", "MODEM", "AREA", "1202"
CXServer.SetDeviceConfig "myplc", "MODEM", "NUMBER", "123456"

This will change the phone number on a PLC that is already configured to use a modem.
If you want to change other settings you can easily find out what the settings are using the GetDeviceConfig command with nothing between the quotes:
mydeviceconfig = CXServer.GetDeviceConfig ("myplc", "", "" )
This will get all settings for this particular PLC something like:
Each section (e.g. MODEM or ADDRESS) is in square brackets '[ ]' and is the second parameter in the SetDeviceConfig command. The third parameter is the item you want to set and is before a colon ':' (e.g. AREA, NUMBER, IPADDR). The final parameter is the value you want to change it to in "".