Plant Simulation provides several interfaces for import and export data.
14.1 DDE with Plant Simulation
Dynamic data exchange (DDE) allows accessing another program. A Windows
program that makes DDE functionality available connects to the system under a server name and provides various topics. You can establish a connection to this program by providing the specified server name and a valid theme. You may use the established channel for certain transactions related to data (items) that are supported by the server. All DDE transactions are realized by SimTalk calls in Plant Simulation. You can call any method in Plant Simulation using DDE, including the methods that you have defined. Important: All participating programs must be started.
14.1.1 Read Plant Simulation Data in Microsoft Excel
The following examples are programmed in VBA (Visual Basic for Applications). In principle, this works with Excel, Project, Word and Access. To work with DDE, you need the following commands:
Table 14.1 VBA DDE commands
VBA/SimTalk Method Description
DDEInitiate(<string1>, <string2>) Opens a channel; you have to pass the name of the application (<string1>, (in Plant Simulation 12 this still is eM-Plant) and a topic (<string2>) Plant Simulation supports the following topics: System (you can request information about Plant Simulation and call SimTalk methods) Data (values of global variables can be read and written) Info (version of Plant Simulation, name of the current frame, states of the frame you can read)
S. Bangsow, Tecnomatix Plant Simulation, DOI: 10.1007/978-3-319-19503-2_14 662 14 Data Exchange and Interfaces
Table 14.1 (continued)
DDERequest(<integer>, <string>) Requests information from an application; you need to
pass the channel number (<integer>) and an item (<string>); the passed element (item) will be queried (Note: It must be addressed absolutely.) DDETerminate(<integer>) Closes the channel (<integer>) DDEPoke(<integer>, <string>, Writes data (variant>) into the connected application <string>,<integer>) (channel <integer>, element <string>, timeout<integer>) DDEExecute(<integer>, <string>) Sends a command (<string>) to the connected application (<integer> channel
Example: Data Exchange DDE Excel
The following examples are programmed in VBA. In principle, this works with Excel, Project, Word, and Access. Insert a variable (name: variable; data type: integer; value: 247985) into a Plant Simulation frame (.Models.Frame). This value is to be read in Excel. Start Excel. Open the VBA Editor. Insert a new module (Insert—Module) and a new procedure (sampleDDE) in the module: Public Sub sampleDDE() Dim channel As Long Dim value As Variant 'establish channel channel = DDEInitiate("eM-Plant", "Data") 'read the value value = DDERequest(channel, _ ".Models.Frame.Variable") 'write the value into the table Tabelle1.Range("A2").value = value(1) 'close channel DDETerminate (channel) End Sub
14.1.2 Excel DDE Data Import in Plant Simulation
Plant Simulation can also read data from DDE-enabled programs. Regarding Excel, a few requirements must be met: The Excel file must be opened. You have to specify the worksheet in Excel when opening the connection. All data will be transferred as a string. Reading data from Excel with DDE is done in three steps: 1. Establish a connection with Excel 2. Read the value 3. Close the connection To read a value from the cell B2 in Sheet1, the following program is necessary: is channel:integer; val:string;
EDEM Is An Advanced DEM (Discrete Element Method) Software Package For Simulation and Analysis of Particulate Solids Handling and Processing Operations