Ddedemo
Ddedemo
Both drivers are DDE Clients that initiate communications with DDE Servers. Pressing the Enable button in the DCS View initiates a DDE conversation. An error dialog is generated if the server is unavailable. Pressing the Disable button in the DCS View terminates the DDE conversation. The HYSYS DDE Drivers detect if the server disconnects the conversation with the client. For example, suppose an Excel spreadsheet was closed while a DDE conversation was in progress with a HYSYS application. An error dialog is generated if this situation occurs. DDE client transactions are also initiated periodically according to the data transfer interval configured on the Drivers page tab of the DCS View. Both drivers are synchronous. This means that DDE client transactions may time out when poking / requesting data to / from, or attempting to execute DDE commands on a slow DDE server. The timeout is configurable with the default value set to five thousand milliseconds. If a transaction times out, an error dialog box is generated. Unfortunately, DDE error dialogs may appear at the bottom of the window stack. If HYSYS seems completely unresponsive and a DDE driver is being used, using the ALT-TAB key sequence to cycle the visible window stack may indicate a DDE Error dialog that is causing the problem.
string. If the DDE Server name is excel or matlab, the delimiter string will be internally set to the correct delimiter regardless of what the user enters for a delimiter. The timeout value for synchronous DDE transactions is configured in the Timeout (ms) General Data Page Tab Column. The default value is 5000 milliseconds. For large array based client transactions with a slow DDE Server, this timeout value may need to be increased.
page tab of the DCS View indicates whether setpoint only (Internal) or setpoint and output (DCS) data transfer is desired for a given controller. In the first scenario, only the controller setpoint is modified externally. This type of situation might occur in a multivariable control problem where the setpoints of several dependent controllers are modified according to some external algorithm. In this case, the internal HYSYS controllers still calculate their own output values. In the second scenario, an external program modifies both controller setpoints and outputs. This mechanism allows an external controller to replace an internal HYSYS controller. The output of the external controller is written directly to the output of the internal HYSYS controller thus bypassing the internal control. Controller setpoint information is also transferred for HYSYS GUI purposes. A simple HYSYS case including two tanks with level controls is used for demonstration purposes. Controller Status fields are both set to DCS in the demonstration HYSYS cases. Control actions are computed by an external program and results are transferred via the DDE Client DCS link. Equation 1 gives the basic PID controller response. Both the DDE Server demonstrations use this equation to calculate the controller outputs signals to send back to HYSYS. Note that the implementation of this equation in the demonstrations is very basic to keep the example code clear. The controller output calculations are synchronized with the HYSYS integrator using the Execute Cmd configured in the General Data Page Tab of the DCS View. Each data transfer period in HYSYS triggers the execution of the Execute Cmd on the DDE Server allowing iterative calculation of controller outputs.
action kp
( error ) dt + ction
kp d
d ( error dt
(1)
bias = control valve bias parameter 1.0 = direct action 1.0 = reverse kp = controller gain error = setpo int process var iable action = controller
The current time and step sizes are transferred to calculate integral and derivatives of the error. Note that this assumes that the Data Transfer Period on the DCS Drivers Page Tab is set to 0.0 so that data is transferred every time step. If this is not the case the server code must be changed to calculate the previous time and store it.
The DDE Server Commands in the table above are entered into the appropriate columns of the matrix on the General Data Page DCS View. The demo m-files indicated in the table are executed when the corresponding event occurs in HYSYS. The following m-files are used for the demo. Tparrset.m Tparrplt.m Pid.m Pidstart.m Pidstop.m Pidexec.m The DDE item tags to configure arrays for data transfer of controller setpoints, controller outputs, and process variables are MATLAB vector names as indicated in the following table. Array Setpoint Output PV Export PV Import Array Tags sp op pv pvimport
These tag names are entered in the General Data page tab of the DCS View. Once the HYSYS DCS link is enabled, these variables may be viewed by typing their names in the MATLAB command window. The contents of the vector will be listed in the command window. Other MATLAB vectors of interest include kp, ti, and td.
In HYSYS, press the DCS View Disable button to disable the DCS link.
The DDE Server Commands in the table above are entered into the appropriate columns of the matrix on the General Data Page of the DCS View. The indicated Excel macro is executed when the corresponding event occurs in HYSYS. The Excel macros are contained in a module named DDEAccess in the demo Excel spreadsheet file.
These tag names are entered in the General Data page tab of the DCS View. The contents of the data vectors are displayed in the demo Excel worksheet. It is straightforward to modify the other controller parameters on the Excel spreadsheet.
In HYSYS, press the DCS View Enable button. In HYSYS, press the Integrator Reset button (:Simulation:Integrator View). This resets the time to zero. In HYSYS, press the Integrator Start button. Plot traces indicating controller response trajectories will begin to appear in the Excel spreadsheet as data transfer events occur. In HYSYS, press the Integrator Stop button to stop the data transfer. In HYSYS, press the DCS View Disable button to disable the DCS link.