Sie sind auf Seite 1von 60

 S7ProSim V5.

4

1 ___________________ Introduction 2 ___________________ S7ProSim overview

SIMATIC Engineering tools S7ProSim V5.4


Operating Manual

3 ___________________ Methods 4 ___________________ Events 5 ___________________ Type definitions

07/2011
A5E00992430-02

Legal information Legal information Warning notice system


This manual contains notices you have to observe in order to ensure your personal safety, as well as to prevent damage to property. The notices referring to your personal safety are highlighted in the manual by a safety alert symbol, notices referring only to property damage have no safety alert symbol. These notices shown below are graded according to the degree of danger. DANGER indicates that death or severe personal injury will result if proper precautions are not taken. WARNING indicates that death or severe personal injury may result if proper precautions are not taken. CAUTION with a safety alert symbol, indicates that minor personal injury can result if proper precautions are not taken. CAUTION without a safety alert symbol, indicates that property damage can result if proper precautions are not taken. NOTICE indicates that an unintended result or situation can occur if the relevant information is not taken into account. If more than one degree of danger is present, the warning notice representing the highest degree of danger will be used. A notice warning of injury to persons with a safety alert symbol may also include a warning relating to property damage.

Qualified Personnel
The product/system described in this documentation may be operated only by personnel qualified for the specific task in accordance with the relevant documentation, in particular its warning notices and safety instructions. Qualified personnel are those who, based on their training and experience, are capable of identifying risks and avoiding potential hazards when working with these products/systems.

Proper use of Siemens products


Note the following: WARNING Siemens products may only be used for the applications described in the catalog and in the relevant technical documentation. If products and components from other manufacturers are used, these must be recommended or approved by Siemens. Proper transport, storage, installation, assembly, commissioning, operation and maintenance are required to ensure that the products operate safely and without any problems. The permissible ambient conditions must be complied with. The information in the relevant documentation must be observed.

Trademarks
All names identified by are registered trademarks of Siemens AG. The remaining trademarks in this publication may be trademarks whose use by third parties for their own purposes could violate the rights of the owner.

Disclaimer of Liability
We have reviewed the contents of this publication to ensure consistency with the hardware and software described. Since variance cannot be precluded entirely, we cannot guarantee full consistency. However, the information in this publication is reviewed regularly and any necessary corrections are included in subsequent editions.

Siemens AG Industry Sector Postfach 48 48 90026 NRNBERG GERMANY

A5E00992430-02 05/2011

Copyright Siemens AG 2011. Technical data subject to change

Table of contents
1 2 Introduction................................................................................................................................................ 5 S7ProSim overview ................................................................................................................................... 7 2.1 2.2 3 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 3.20 3.21 3.22 3.23 3.24 3.25 3.26 Adding an S7ProSim COM object to your project..........................................................................7 Programming an interface to S7-PLCSIM with S7ProSim.............................................................8 BeginScanNotify ..........................................................................................................................13 Connect........................................................................................................................................14 ConnectExt...................................................................................................................................15 Continue.......................................................................................................................................16 Disconnect ...................................................................................................................................17 EndScanNotify .............................................................................................................................18 ExecuteNmsScan ........................................................................................................................19 ExecuteNScans ...........................................................................................................................20 ExecuteSingleScan......................................................................................................................21 GetPauseState.............................................................................................................................22 GetScanMode ..............................................................................................................................23 GetStartUpSwitch ........................................................................................................................24 GetState .......................................................................................................................................25 HotStartWithSavedValues ...........................................................................................................26 Pause ...........................................................................................................................................27 ReadDataBlockValue...................................................................................................................28 ReadFlagValue ............................................................................................................................30 ReadOutputImage........................................................................................................................32 ReadOutputPoint .........................................................................................................................34 SavePLC ......................................................................................................................................36 SetScanMode...............................................................................................................................37 SetStartUpSwitch.........................................................................................................................38 SetState .......................................................................................................................................39 StartPLCSim ................................................................................................................................40 StartPLCSimExt ...........................................................................................................................41 WriteDataBlockValue ...................................................................................................................42

Methods................................................................................................................................................... 11

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

Table of contents

3.27 3.28 3.29 4 4.1 4.2 4.3 4.4 4.5 5 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 5.10

WriteFlagValue............................................................................................................................ 44 WriteInputImage.......................................................................................................................... 46 WriteInputPoint............................................................................................................................ 47 ConnectionError .......................................................................................................................... 49 PauseStateChanged ................................................................................................................... 49 PLCSimStateChanged ................................................................................................................ 50 ScanFinished .............................................................................................................................. 50 ScanModeChanged .................................................................................................................... 50 Type definitions ........................................................................................................................... 51 CPURunMode ............................................................................................................................. 51 ImageDataTypeConstants .......................................................................................................... 52 PauseStateConstants ................................................................................................................. 52 PointDataTypeConstants ............................................................................................................ 53 RestartSwitchPosition ................................................................................................................. 53 ScanModeConstants................................................................................................................... 54 tagPauseState............................................................................................................................. 54 ScanInfo constants...................................................................................................................... 55 Error return codes ....................................................................................................................... 55

Events...................................................................................................................................................... 49

Type definitions........................................................................................................................................ 51

Index........................................................................................................................................................ 57

S7ProSim V5.4

Operating Manual, 07/2011, A5E00992430-02

Introduction

S7ProSim provides programmatic access to the simulated PLC in S7-PLCSIM. With S7ProSim, you can write software to perform such tasks as changing the key-operated switch position of the simulated PLC, running the control program in single scan mode, reading or writing controller values, and many other work steps.

Target group
This manual is aimed at developers, programmers and maintenance personnel with knowledge of and experience in the areas of programmable S7 controllers and software development in Visual Basic (6.0 or .NET) or Visual C++ (6.0 or .NET).

Scope of the manual


This document describes the functions and operation of S7ProSim as of V5.4 SP5.

Other manuals
For additional information, refer to the STEP 7 and S7-PLCSIM online help and the following manuals: Programming with STEP 7 manual. This manual provides the basic information on designing and creating control programs. Use this manual when you are designing a control program with the STEP 7 automation software. System Software for S7-300/400, System and Standard Functions reference manual. In this manual, you can find descriptions of system functions, organization blocks and standard functions which you use when developing a control program. Working with STEP 7, Getting Started. This manual describes how you work the the STEP 7 automation software. It gives you an overview of the procedures for configuring a PLC and developing control programs. S7-PLCSIM - Testing your S7 CPU Program. This manual describes the user interface and functionality of S7-PLCSIM, the S7-SPS simulator. You can find this and other manuals by selecting the menu command Start > SIMATIC > Documentation in the Windows start menu of the computer on which STEP 7 is installed.

Additional support
If you have technical questions or you require information on ordering this product or on training courses, please contact your Siemens representative.

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

Introduction

S7ProSim V5.4

Operating Manual, 07/2011, A5E00992430-02

S7ProSim overview

S7ProSim provides a COM object for program-controlled access to the process simulation user interface of S7-PLCSIM. You can use S7ProSim in any application that supports COM objects for attachment to an S7-PLCSIM process simulation. This online document describes how to add S7ProSim to an application. It also explains the features, user interface, and functions of S7ProSim as well as the software object definitions of the methods and events.

2.1

Adding an S7ProSim COM object to your project


if you want to use an S7ProSim COM object in your project, you add a reference to the object. The procedure for adding a project reference depends on your programming environment.

Procedure
In Microsoft Visual Basic (6.0 or .NET), for example, follow these steps to add an S7ProSim COM object reference: 1. Select the Project > References or Project > Add Reference menu command. 2. In the "References" dialog, select the check box for the Siemens S7ProSim COM object. (IN Visual Basic .NET, this selection is on the "COM" tab of the "References" dialog.) 3. Click "OK". After you add the project reference, you can use the Object Browser to view the methods and events of the S7ProSim COM object. From the Object Browser, select S7PROSIMLib from the drop-down list of libraries. The S7ProSim class contains the methods and events that you can use to program an interface to S7-PLCSIM. In Microsoft Visual Studio C++ V6.0 or in Microsoft Visual C++ .NET, follow the relevant procedure in the specific programming environment to add a COM object. In Microsoft Visual C# .NET, you can add a reference to an S7ProSim COM object by following these steps: 1. Select the Project > Add reference menu command. 2. In the "COM" tab, select the component "Siemens S7ProSim COM Object". 3. Confirm your selection with "OK". 4. End the dialog with "OK".

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

S7ProSim overview 2.2 Programming an interface to S7-PLCSIM with S7ProSim

2.2
Procedure

Programming an interface to S7-PLCSIM with S7ProSim

To use S7ProSim for program-controlled operation of the controller simulated in S7-PLCSIM, you need to perform these tasks: 1. Include the Siemens S7ProSim COM Object in the project. 2. Add a declaration for S7ProSim to your project. Example: Visual Basic 6.0
Option Explicit Private WithEvents S7ProSim As S7PROSIMLib.S7ProSim ... Private Sub Form_Load() Set S7ProSim = New S7PROSIMLIB.S7ProSim ... End Sub

Example: Visual Basic .NET


Private WithEvents S7ProSim As New S7PROSIMLib.S7ProSim

Example: Visual C++ 6.0


// the ProSim library/tlb is in the dll #import <S7wspsmx.dll> named_guids, no_namespace//, raw_interfaces_only class ProSimWrapper { public: ProSimWrapper() : m_pProSim(OLESTR("S7wspsmx.S7ProSim"), NULL, CLSCTX_INPROC_SERVER) {}; application // starts virtual ~ProSimWrapper() {}; // no implementation, smartptr is automatically // spartptr is automatically created in the stack when the

// released // when the application shuts down IS7ProSim * GetPtr() { return m_pProSim; }; // Attributes

S7ProSim V5.4

Operating Manual, 07/2011, A5E00992430-02

S7ProSim overview 2.2 Programming an interface to S7-PLCSIM with S7ProSim

protected: // IProSimPtr is a CComPtr (smart ptr) for the IProSim // interface // It is from the dll file from #import // CoCreateInstance will be called automatically for the ptr object // in the constructor // of this class // The release of ptr is automatically called by the destructor // of this class IS7ProSimPtr }; m_pProSim;

Example: C#
using S7PROSIMLib; ... private S7ProSim ps; // create the COM Object connection ps = new S7ProSim();

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

S7ProSim overview 2.2 Programming an interface to S7-PLCSIM with S7ProSim


3. In Visual Basic, program event handlers for the S7ProSim events. Event handlers are not necessary in Visual C++ and Visual C#. Within each event handler, you can insert any custom code for your application. Example: Visual Basic 6.0
Private Sub S7ProSim_PauseStateChanged(ByVal NewState As String) DoEvents ... End Sub Private Sub S7ProSim_ScanFinished(ByVal ScanInfo As Variant) DoEvents ... End Sub Private Sub S7ProSim_PLCSimStateChanged(ByVal NewState As String) DoEvents ... End Sub Private Sub S7ProSim_ConnectionError(ByVal ControlEngine As String, ByVal error As Long) DoEvents MsgBox "Connection Error" End Sub Private Sub S7ProSim_ScanModeChanged(ByVal NewState As String) DoEvents ... End Sub

Note In Visual Basic .NET, the "DoEvents" call is not necessary. 4. Add command buttons, text boxes or other objects to your application as needed to access the various S7ProSim methods. Program the code for each command button handler to call S7ProSim methods and set suitable values for text boxes as appropriate for your application.

S7ProSim V5.4

10

Operating Manual, 07/2011, A5E00992430-02

Methods

3
Method BeginScanNotify (Page 13) Description Registers S7ProSim for callbacks from the controller. The ScanFinished and PLCSimStateChanged events will be sent when these events occur. Connects S7ProSim to S7-PLCSIM. Connects S7ProSim with the S7-PLCSIM instance with number InstanceNumber. Continues a simulation that has been paused. Disconnects S7ProSim from S7-PLCSIM. Unregisters S7ProSim for callbacks from the controller. The ScanFinished and PLCSimStateChanged events will not be sent. Forces S7-PLCSIM to execute scan cycles for a specified time (Nms) without waiting for the end of the current scan. If scan notification is enabled, the program will be notified when S7-PLCSIM has finished the scans. Forces S7-PLCSIM to execute a specified number of scan cycles without waiting for the end of the current scan. If scan notification is enabled, the program will be notified when S7-PLCSIM has finished the scans. Forces S7-PLCSIM to execute one scan cycle without waiting for the end of the current scan. If scan notification is enabled, the program will be notified when S7-PLCSIM has finished the scan. Returns the current pause state of S7-PLCSIM. Reports the operating mode of S7-PLCSIM. Gets the startup setting (hot restart, warm restart, or cold start) for S7-PLCSIM Returns a string containing the current key switch position of S7-PLCSIM (RUN, RUN-P, or STOP). Sets a Boolean value to specify whether S7-PLCSIM should load saved peripheral I/O values when started in the HotStart state. In order for S7-PLCSIM to start up and load peripheral I/O, the user needs to call HotStartWithSavedValues with a value of TRUE, save the PLC program (SavePLC), and set the startup state for S7-PLCSIM to HotStart (SetStartUpSwitch). When S7-PLCSIM restarts, the peripheral I/O is loaded Pauses a simulation. Reads a particular bit, byte, word, or double word from the DB memory area of S7-PLCSIM. Reads a particular bit, byte, word, or double word from the bit memory area (M) of S7-PLCSIM.

Overview

Connect (Page 14) ConnectExt (Page 15) Continue (Page 16) Disconnect (Page 17) EndScanNotify (Page 18) ExecuteNmsScan (Page 19)

ExecuteNScans (Page 20)

ExecuteSingleScan (Page 21) GetPauseState (Page 22) GetScanMode (Page 23) GetStartUpSwitch (Page 24) GetState (Page 25) HotStartWithSavedValues (Page 26)

Pause (Page 27) ReadDataBlockValue (Page 28) ReadFlagValue (Page 30)

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

11

Methods

Method ReadOutputImage (Page 32)

Description Reads elements from the peripheral outputs (PQ memory area) of S7-PLCSIM.

ReadOutputPoint (Page 34) Reads a particular bit (Boolean), a byte (Byte), a two-byte word (Integer) or a four-byte word (Long) from the peripheral outputs (PQ memory area). SavePLC (Page 36) Saves the current simulated PLC data to a file. The saved data consists of the program, the hardware configuration, the key switch position as indicated by the "CPU" subwindow, the type of program execution (continuous or single scan), the I/O status, time values, symbolic addresses, and the power setting (on or off). Sets the operating mode for S7-PLCSIM. Sets the type of startup (hot restart, warm restart, or cold start) to use when S7-PLCSIM starts up. Sets the current key switch position of S7-PLCSIM (RUN, RUN-P, or STOP). Starts S7-PLCSIM with the specified PLC simulation file (saved from a previous SavePLC call). Starts an instance of S7-PLCSIM with the specified PLC simulation file (saved from a previous call). Writes a particular bit, byte, word, or double word to the DB memory area of S7-PLCSIM. Writes a particular bit, byte, word, or double word to the bit memory area (M) of S7-PLCSIM. Writes elements to the peripheral inputs (PI memory area) of S7-PLCSIM, starting at the StartIndex of the data to which pData points. Writes either a particular bit (Boolean), byte (Byte), a two-byte word (Integer) or a four-byte word (Long) from the Data variant to the peripheral inputs (PI memory area).

SetScanMode (Page 37) SetStartUpSwitch (Page 38) SetState (Page 39) StartPLCSim (Page 40) StartPLCSimExt (Page 41) WriteDataBlockValue (Page 42) WriteFlagValue (Page 44) WriteInputImage (Page 46)

WriteInputPoint (Page 47)

S7ProSim V5.4

12

Operating Manual, 07/2011, A5E00992430-02

Methods 3.1 BeginScanNotify

3.1

BeginScanNotify
STDMETHOD(CS7ProSim::BeginScanNotify)()

Description
Registers S7ProSim for callbacks from the controller. The ScanFinished and PLCSimStateChanged events will be sent when these events occur.

Parameters
None

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK E_FAIL PS_E_NOTCONNECTED PS_E_POWEROFF Meaning 0x00000000 : Success code 0x80004005 : Unspecified error 0x80040211 : S7ProSim is not connected to S7-PLCSIM 0x80040212 : S7-PLCSIM is powered off

Visual Basic usage


BeginScanNotify() As Long function

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

13

Methods 3.2 Connect

3.2

Connect
STDMETHOD(Connect)()

Description
Connects S7ProSim with the first instance of S7-PLCSIM which has the instance number "1".

Parameters
None

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK E_FAIL PS_E_NOTCONNECTED PS_E_PLCISCONNECTED PS_E_POWEROFF Meaning 0x00000000: Success code 0x80004005: Unspecified error 0x80040211: S7ProSim is not connected to S7-PLCSIM 0x8004020E: S7-PLCSIM is connected 0x80040212: S7-PLCSIM is powered off

Visual Basic usage


Connect() As Long function

S7ProSim V5.4

14

Operating Manual, 07/2011, A5E00992430-02

Methods 3.3 ConnectExt

3.3

ConnectExt
STDMETHOD (ConnectExt)(/*[in]*/ long InstanceNumber)

Description
Connects S7ProSim with the S7-PLCSIM instance with number InstanceNumber.

Parameters
InstanceNumber [in]: Number of the instance with which S7ProSim is to be connected

Error handling
Errors are reported in the ConnectionError event, not by the function call.

Return value
Value S_OK E_FAIL PS_E_NOTCONNECTED PS_E_PLCISCONNECTED PS_E_POWEROFF Meaning 0x00000000: Success code 0x80004005: Unspecified error 0x80040211: S7ProSim is not connected to S7-PLCSIM 0x8004020E: S7-PLCSIM is connected 0x80040212: S7-PLCSIM is powered off

Visual Basic usage


Function ConnectExt() As Long

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

15

Methods 3.4 Continue

3.4

Continue
STDMETHOD(CS7ProSim::Continue)()

Description
Continues a simulation that has been paused.

Parameters
None

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK PS_E_NOTCONNECTED Meaning 0x00000000 : Success code 0x80040211 : S7ProSim is not connected to S7-PLCSIM

Visual Basic usage


Sub Continue()

S7ProSim V5.4

16

Operating Manual, 07/2011, A5E00992430-02

Methods 3.5 Disconnect

3.5

Disconnect
STDMETHOD(CS7ProSim::Disconnect)()

Description
Disconnects S7ProSim from S7-PLCSIM.

Parameters
None

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK E_FAIL PS_E_POWEROFF Meaning 0x00000000 : Success code 0x80004005 : Unspecified error 0x80040212 : S7-PLCSIM is powered off

Visual Basic usage


Disconnect() As Long function

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

17

Methods 3.6 EndScanNotify

3.6

EndScanNotify
STDMETHOD(CS7ProSim::EndScanNotify)()

Description
Unregisters S7ProSim for callbacks from the controller. The ScanFinished and PLCSimStateChanged events are no longer sent.

Parameters
None

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK E_FAIL PS_E_NOTCONNECTED PS_E_POWEROFF PS_E_NOTREGISTERED Meaning 0x00000000: Success code 0x80004005: Unspecified error 0x80040211: S7ProSim is not connected to S7-PLCSIM 0x80040212: S7-PLCSIM is powered off 0x80040209: S7ProSim is not registered for callbacks from S7PLCSIM

Visual Basic usage


Function EndScanNotify() As Long

S7ProSim V5.4

18

Operating Manual, 07/2011, A5E00992430-02

Methods 3.7 ExecuteNmsScan

3.7

ExecuteNmsScan
STDMETHOD(CS7ProSim::ExecuteNmsScan)( long MsNumber)

Description
Forces S7-PLCSIM to execute scan cycles for a specified time (Nms) without waiting for the end of the current scan. If scan notification is enabled, the program will be notified when S7-PLCSIM has finished the scans. S7-PLCSIM must be in single scan mode to use this method.

Parameters
Parameters Declaration Input Description Time (in milliseconds) during which scan cycles will be executed.

MsNumber

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK E_FAIL PS_E_NOTSINGLESCAN PS_E_PLCNOTRUNNING PS_E_NOTCONNECTED Meaning 0x00000000: Success code 0x80004005: Unspecified error 0x8004020A: Single scan program execution is not set in S7-PLCSIM 0x8004020E: S7-PLCSIM is not running 0x80040211: S7ProSim is not connected to S7-PLCSIM

Visual Basic usage


ExecuteNmsScan(MsNumber As Long) As Long function

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

19

Methods 3.8 ExecuteNScans

3.8

ExecuteNScans
STDMETHOD(CS7ProSim::ExecuteNScans)( long NScanNumber)

Description
Forces S7-PLCSIM to execute a specified number of scan cycles without waiting for the end of the current scan. If scan notification is enabled, the program will be notified when S7-PLCSIM has finished the scans. S7-PLCSIM must be in single scan mode to use this method.

Parameters
Parameters Declaration Input Description Number of scan cycles to be executed.

NScanNumber

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK E_FAIL PS_E_NOTSINGLESCAN PS_E_PLCNOTRUNNING PS_E_NOTCONNECTED Meaning 0x00000000: Success code 0x80004005: Unspecified error 0x8004020A: Single scan mode is not set in S7-PLCSIM 0x8004020E: S7-PLCSIM is not running 0x80040211: S7ProSim is not connected to S7-PLCSIM

Visual Basic usage


ExecuteNScans(NScanNumber As Long) As Long function

S7ProSim V5.4

20

Operating Manual, 07/2011, A5E00992430-02

Methods 3.9 ExecuteSingleScan

3.9

ExecuteSingleScan
STDMETHOD(CS7ProSim::ExecuteSingleScan)()

Description
Forces S7-PLCSIM to execute one scan cycle without waiting for the end of the current scan. If scan notification is enabled, the program will be notified when S7-PLCSIM has finished the scan. S7-PLCSIM must be in single scan mode to use this method.

Parameters
None

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK E_FAIL PS_E_PLCNOTRUNNING PS_E_NOTSINGLESCAN PS_E_MODENOTPOSSIBLE Meaning 0x00000000: Success code 0x80004005: Unspecified error 0x8004020E: S7-PLCSIM is not running 0x8004020A: Single scan mode is not set in S7-PLCSIM 0x8004020C: S7-PLCSIM could not set the specified operating mode

Visual Basic usage


ExecuteSingleScan() As Long function

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

21

Methods 3.10 GetPauseState

3.10

GetPauseState
STDMETHOD(CS7ProSim::GetPauseState)( PauseStateConstants *pVal)

Description
Returns the current pause state of S7-PLCSIM.

Parameters
Parameters Declaration Output Description Pointer to the returned S7-PLCSIM state, which is one of the PauseStateConstants settings

pVal

Notes When called from Visual Basic or C# , the pause state is output in the function return value and there is no pVal parameter. When called from C++, the state is returned in the value to which pVal points.

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK PS_E_NOTCONNECTED Meaning 0x00000000: Success code 0x80040211: S7ProSim is not connected to S7-PLCSIM

Visual Basic usage


GetPauseState() As PauseStateConstants function

S7ProSim V5.4

22

Operating Manual, 07/2011, A5E00992430-02

Methods 3.11 GetScanMode

3.11

GetScanMode
STDMETHOD(CS7ProSim::GetScanMode)( ScanModeConstants *pVal)

Description
Reports the operating mode of S7-PLCSIM.

Parameters
Parameters Declaration Output Description Pointer to the returned operating mode. The returned operating mode is one of the ScanModeConstants

pVal

Notes
When called from Visual Basic or C# , the operating mode is output in the function return value and there is no pVal parameter. When called from C++, the state is returned in the value to which pVal points.

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK PS_E_NOTCONNECTED Meaning 0x00000000: Success code 0x80040211: S7ProSim is not connected to S7-PLCSIM

Visual Basic usage


GetScanMode() As ScanModeConstants function

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

23

Methods 3.12 GetStartUpSwitch

3.12

GetStartUpSwitch
STDMETHOD(CS7ProSim::GetStartUpSwitch)( RestartSwitchPosition *pPos)

Description
Gets the startup setting (hot restart, warm restart, or cold start) for S7-PLCSIM.

Parameters
Parameters Declaration Output Description Pointer to S7-PLCSIM startup position value, which is one of the RestartSwitchPosition settings

pPos

Notes When called from Visual Basic or C#, the switch position is output in the function return value and there is no pPos parameter. When called from C++, the state is returned in the value to which pPos points.

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK PS_E_NOTCONNECTED Meaning 0x00000000: Success code 0x80040211: S7ProSim is not connected to S7-PLCSIM

Visual Basic usage


GetStartUpSwitch() As RestartSwitchPosition function

S7ProSim V5.4

24

Operating Manual, 07/2011, A5E00992430-02

Methods 3.13 GetState

3.13

GetState
STDMETHOD(CS7ProSim::GetState)( BSTR *pVal)

Description
Returns a string containing the current key switch position of S7-PLCSIM (RUN, RUN-P, or STOP).

Parameters
Parameters Declaration Output Description Pointer to the returned S7-PLCSIM key switch position value.

pVal

Notes When called from Visual Basic or C# , the state is output in the function return value and there is no pVal parameter. When called from C++, the state is returned in the value to which pVal points.

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK E_FAIL E_INVALID_STATE PS_E_NOTCONNECTED Meaning 0x00000000: Success code 0x80004005: Unspecified error 0x00008002: Invalid state 0x80040211: S7ProSim is not connected to S7-PLCSIM

Visual Basic usage


GetState() As String function

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

25

Methods 3.14 HotStartWithSavedValues

3.14

HotStartWithSavedValues
STDMETHOD(CS7ProSim::HotStartWithSavedValues)( BOOL val)

Description
Sets a Boolean value to specify whether S7-PLCSIM should load saved peripheral I/O values when started in the HotStart state. In order for S7-PLCSIM to start up and load peripheral I/O, the user needs to call HotStartWithSavedValues with a value of TRUE, save the PLC program (SavePLC), and set the startup state for S7-PLCSIM to HotStart (SetStartUpSwitch). When S7-PLCSIM restarts, it will then load the peripheral I/O.

Parameters
Parameters Declaration Input Description A value of TRUE indicates that S7-PLCSIM will load saved peripheral I/O data during a hot start. A value of FALSE indicates that it will not.

val

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK PS_E_NOTCONNECTED Meaning 0x00000000 : Success code 0x80040211 : S7ProSim is not connected to S7-PLCSIM

Visual Basic usage


Sub HotStartWithSavedValues(val As Long)

S7ProSim V5.4

26

Operating Manual, 07/2011, A5E00992430-02

Methods 3.15 Pause

3.15

Pause
STDMETHOD(CS7ProSim::Pause)()

Description
Pauses a simulation.

Parameters
None

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK PS_E_NOTCONNECTED Meaning 0x00000000 : Success code 0x80040211 : S7ProSim is not connected to S7-PLCSIM

Visual Basic usage


Sub Pause()

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

27

Methods 3.16 ReadDataBlockValue

3.16

ReadDataBlockValue
STDMETHOD(CS7ProSim::ReadDataBlockValue)( long BlockNumber, long ByteIndex, long BitIndex, PointDataTypeConstants DataType, VARIANT* pData)

Description
Reads a particular bit (Boolean), a byte (Byte), a two-byte word (Integer) or a four-byte word (Long) from the memory area of a data block.

Parameters
Parameters Declaration Input Input Input Input Input, output Description Number of the data block to be read. Valid values for BlockNumber depend on the CPU. Start byte position in the data block to be read. Valid values for ByteIndex depend on the CPU. Start bit position in the data block to be read, if a Boolean value (bit) is read. Valid values for BitIndex are 0 to 7. Data type to be read. DataType must be one of the PointDataTypeConstants. Pointer to the read data. Valid values for data depend on the data type. Make sure you allocate and free this memory area in your application.

BlockNumber ByteIndex BitIndex DataType pData

Note If the DataType is S7_Bit, then ByteIndex and BitIndex must both be set to valid indexes. If successful, the method returns the given bit in pData, and its data type variant is Boolean. If the DataType is S7_Byte, S7_Word or S7_DoubleWord, then ByteIndex must be set to a valid index (BitIndex is ignored). If successful, the method returns the value in pData. The data type variant is Byte, Integer, or Long, depending on the DataType.

S7ProSim V5.4

28

Operating Manual, 07/2011, A5E00992430-02

Methods 3.16 ReadDataBlockValue

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK E_FAIL PS_E_NOTCONNECTED PS_E_POWEROFF PS_E_BADTYPE PS_E_BADBYTENDX PS_E_BADBYTECOUNT PS_E_READFAILED Meaning 0x00000000: Success code 0x80004005: Unspecified error 0x80040211: S7ProSim is not connected to S7-PLCSIM 0x80040212: S7-PLCSIM is powered off 0x80040206: Invalid data type 0x80040201: Byte index is invalid 0x80040202: Size of data array is invalid for given start byte index 0x80040203: Read operation failed

Visual Basic usage


Sub ReadDataBlockValue(BlockNum As Long, ByteIndex As Long, BitIndex As Long, DataType As PointDataTypeConstants, pData)

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

29

Methods 3.17 ReadFlagValue

3.17

ReadFlagValue
STDMETHOD(CS7ProSim::ReadFlagValue)( long ByteIndex, long BitIndex, PointDataTypeConstants DataType, VARIANT* pData)

Description
Reads a particular bit (Boolean), a byte (Byte), a two-byte word (Integer) or a four-byte word (Long) from the bit memory area.

Parameters
Parameters Declaration Input Input Description Represents the start byte position in the bit memory area to be read. Valid values for ByteIndex depend on the CPU. Represents the start bit position in the bit memory area to be read, if a Boolean value (bit) is to be read. Valid values for BitIndex are 0 to 7. Represents the data type to be read. DataType must be one of the PointDataTypeConstants. Pointer to the read data. Valid values for data depend on the data type. Make sure you allocate and free this memory area in your application.

ByteIndex BitIndex DataType pData

Input Input, output

Note If the DataType is S7_Bit, then ByteIndex and BitIndex must both be set to valid indexes. If successful, the method returns the given bit in pData, and its data type variant is Boolean. If the DataType is S7_Byte, S7_Word or S7_DoubleWord, then ByteIndex must be set to a valid index (BitIndex is ignored). If successful, the method returns the value in pData. The data type variant is Byte, Integer, or Long, depending on the DataType.

S7ProSim V5.4

30

Operating Manual, 07/2011, A5E00992430-02

Methods 3.17 ReadFlagValue

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK E_FAIL PS_E_NOTCONNECTED PS_E_POWEROFF PS_E_BADTYPE PS_E_BADBYTENDX PS_E_BADBYTECOUNT PS_E_READFAILED Meaning 0x00000000: Success code 0x80004005: Unspecified error 0x80040211: S7ProSim is not connected to S7-PLCSIM 0x80040212: S7-PLCSIM is powered off 0x80040206: Invalid data type 0x80040201: Byte index is invalid 0x80040202: Size of data array is invalid for given start byte index 0x80040203: Read operation failed

Visual Basic usage


Sub ReadFlagValue(ByteIndex As Long, BitIndex As Long, DataType As PointDataTypeConstants, pData)

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

31

Methods 3.18 ReadOutputImage

3.18

ReadOutputImage
STDMETHOD(CS7ProSim::ReadOutputImage)( long StartIndex, long ElementsToRead, ImageDataTypeConstants DataType, VARIANT* pData)

Description
Reads elements from the peripheral outputs (PQ memory area) of S7-PLCSIM.

Parameters
Parameters Declaration Input Input Description Represents the start byte position in the peripheral outputs for the read. Valid values for StartIndex depend on the CPU. Represents the number of bytes, words, or double words to be read from the image buffer. Valid values for ElementsToRead are dependent on the CPU. Represents the data type to be read. The DataType value must be one of the ImageDataTypeConstants. Pointer to the read data. Valid values for data depend on the data type. Make sure you allocate and free this memory area in your application.

StartIndex ElementsToRead DataType pData

Input Input, output

Note If the DataType is S7_Bit, then ByteIndex and BitIndex must both be set to valid indexes. If successful, the method returns the given bit in pData, and its data type variant is Boolean. If the DataType is S7_Byte, S7_Word or S7_DoubleWord, then ByteIndex must be set to a valid index (BitIndex is ignored). If successful, the method returns the value in pData. The data type variant is Byte, Integer, or Long, depending on the DataType.

S7ProSim V5.4

32

Operating Manual, 07/2011, A5E00992430-02

Methods 3.18 ReadOutputImage

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK E_FAIL PS_E_BADBYTENDX PS_E_BADBYTECOUNT PS_E_READFAILED PS_E_BADTYPE PS_E_NOTALLREADSWORKED PS_E_NOTCONNECTED PS_E_POWEROFF Meaning 0x00000000: Success code 0x80004005: Unspecified error 0x80040201: Byte index is invalid 0x80040202: Size of data array is invalid for given start byte index 0x80040203: Read operation failed 0x80040206: Invalid data type 0x8004020F: Not all read operations were successful 0x80040211: S7ProSim is not connected to S7-PLCSIM 0x80040212: S7-PLCSIM is powered off

Visual Basic usage


Sub ReadOutputImage(StartIndex As Long, ElementsToRead As Long, DataType As ImageDataTypeConstants, pData) As Long

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

33

Methods 3.19 ReadOutputPoint

3.19

ReadOutputPoint
STDMETHOD(CS7ProSim::ReadOutputPoint)( long ByteIndex, long BitIndex, PointDataTypeConstants DataType, VARIANT* pData)

Description
Reads a particular bit (Boolean), a byte (Byte), a two-byte word (Integer) or a four-byte word (Long) from the peripheral outputs (PQ memory area).

Parameters
Parameters Declaration Input Input Input Input, output Description Represents the start byte position in the peripheral area for the read. Valid values for ByteIndex depend on the CPU. Represents the bit position (in bytes) in the peripheral area for the read. Valid values are 0 to 7. One of the PointDataTypeConstants Pointer to the data to be read. Valid values for data depend on the data type.

ByteIndex BitIndex DataType pData

Notes If the DataType is S7_Bit, then ByteIndex and BitIndex must both be set to valid indexes. If successful, the method returns the given bit in pData, and its data type variant is Boolean. If the DataType is S7_Byte, S7_Word or S7_DoubleWord, then ByteIndex must be set to a valid index (BitIndex is ignored). If successful, the method returns the value in pData. The data type variant is Byte, Integer, or Long, depending on the DataType.

S7ProSim V5.4

34

Operating Manual, 07/2011, A5E00992430-02

Methods 3.19 ReadOutputPoint

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK E_FAIL PS_E_BADBYTENDX PS_E_BADBYTECOUNT PS_E_READFAILED PS_E_BADBITNDX PS_E_BADTYPE PS_E_NOTCONNECTED PS_E_POWEROFF Meaning 0x00000000: Success code 0x80004005: Unspecified error 0x80040201: Byte index is invalid 0x80040202: Size of data array is invalid for given start byte index 0x80040203: Read operation failed 0x80040205: Byte index is invalid 0x80040206: Invalid data type 0x80040211: S7ProSim is not connected to S7-PLCSIM 0x80040212: S7-PLCSIM is powered off

Visual Basic usage


Sub ReadOutputPoint(ByteIndex As Long, BitIndex As Long, DataType As PointDataTypeConstants, pData) As Long

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

35

Methods 3.20 SavePLC

3.20

SavePLC
STDMETHOD(CS7ProSim::SavePLC)( BSTR FileName)

Description
Saves the current simulated PLC data to a file. The saved data consists of the program, the hardware configuration, the key switch position as indicated by the "CPU" subwindow, the type of program execution (continuous or single scan), the I/O status, time values, symbolic addresses, and the power setting (on or off).

Parameters
Parameters Declaration Input Description Name of file in which the data of the simulated PLC will be stored

FileName

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK STG_E_CANTSAVE PS_E_NOTCONNECTED Meaning 0x00000000: Success code 0x80030103: Cannot save 0x80040211: S7ProSim is not connected to S7-PLCSIM

Visual Basic usage


Sub SavePLC(FileName As String)

S7ProSim V5.4

36

Operating Manual, 07/2011, A5E00992430-02

Methods 3.21 SetScanMode

3.21

SetScanMode
STDMETHOD(CS7ProSim::SetScanMode)( ScanModeConstants newVal)

Description
Sets the operating mode for S7-PLCSIM.

Parameters
Parameters Declaration Input Description Operating mode to be set for S7-PLCSIM. The operating mode must be one of the ScanModeConstants.

newVal

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK PS_E_NOTCONNECTED Meaning 0x00000000: Success code 0x80040211: S7ProSim is not connected to S7-PLCSIM

Visual Basic usage


Sub SetScanMode(newVal As ScanModeConstants)

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

37

Methods 3.22 SetStartUpSwitch

3.22

SetStartUpSwitch
STDMETHOD(CS7ProSim::SetStartUpSwitch)( RestartSwitchPosition postion)

Description
Sets the type of startup (hot restart, warm restart, or cold start) to use when S7-PLCSIM starts up.

Parameters
Parameters Declaration Input Description Value to be set for S7-PLCSIM startup position

Position

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK PS_E_NOTCONNECTED Meaning 0x00000000 : Success code 0x80040211 : S7ProSim is not connected to S7-PLCSIM

Visual Basic usage


Sub SetStartUpSwitch(postion As RestartSwitchPosition)

S7ProSim V5.4

38

Operating Manual, 07/2011, A5E00992430-02

Methods 3.23 SetState

3.23

SetState
STDMETHOD(CS7ProSim::SetState)( BSTR newVal)

Description
Sets the current key switch position of S7-PLCSIM (RUN, RUN-P, or STOP).

Parameters
Parameters Declaration Input Description Value to be set for the key switch position in S7-PLCSIM. Valid values are RUN, RUN_P, STOP and MRES

newVal

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK E_FAIL E_INVALID_STATE PS_E_NOTCONNECTED Meaning 0x00000000: Success code 0x80004005: Unspecified error 0x00008002: Invalid state 0x80040211: S7ProSim is not connected to S7-PLCSIM

Visual Basic usage


Sub SetState(newVal As String)

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

39

Methods 3.24 StartPLCSim

3.24

StartPLCSim
STDMETHOD(CS7ProSim::StartPLCSim)( BSTR plcFile)

Description
Starts the first instance of S7-PLCSIM with the specified PLC simulation file (saved from a previous SavePLC call).

Parameters
Parameters Declaration Input Description Name of the file with which S7-PLCSIM will be started

plcFile

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK E_FAIL Meaning 0x00000000: Success code 0x80004005: Unspecified error

Visual Basic usage


Sub StartPLCSim(plcFile As String)

S7ProSim V5.4

40

Operating Manual, 07/2011, A5E00992430-02

Methods 3.25 StartPLCSimExt

3.25

StartPLCSimExt
STDMETHOD(StartPLCSimExt)(/*[in]*/ BSTR plcFile)

Description
Starts an instance of S7-PLCSIM with the specified PLC simulation file (saved from a previous call).

Parameters
Parameters Declaration Input Description Name of the file with which S7-PLCSIM will be started

plcFile [in]

Error handling
Errors are reported in the ConnectionError event, not by the function call.

Return value
Value S_OK E_FAIL PS_E_MAXINSTANCE Meaning 0x00000000: Success code 0x80004005: Unspecified error 0x80040214: Maximum number of open S7 PLCSIM instances reached

Visual Basic usage


Sub StartPLCSimExt(plcFile As String)

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

41

Methods 3.26 WriteDataBlockValue

3.26

WriteDataBlockValue
STDMETHOD(CS7ProSim::WriteDataBlockValue)( long BlockNumber, long ByteIndex, long BitIndex, const VARIANT* pData)

Description
Writes a particular bit (Boolean), a byte (Byte), a two-byte word (Integer) or a four-byte word (Long) in the memory area of a data block.

Parameters
Parameters Declaration Input Input Input Description Represents the number of the data block to be written to. Valid values for BlockNumber depend on the CPU. Represents the start byte position in the data block to be written to. Valid values for ByteIndex depend on the CPU. Represents the start bit position in the data block to be written to, if writing a Boolean value (bit). Valid values for BitIndex are 0 to 7. Pointer to the data to be written. Valid values for data depend on the data type. Make sure you allocate and free this memory area in your application.

BlockNumber ByteIndex BitIndex pData

Input

Notes If the DataType is S7_Bit, then ByteIndex and BitIndex must both be set to valid indexes. If successful, the method writes the specified bit (pData) in the data block with the number BlockNumber. If the DataType is S7_Byte, S7_Word or S7_DoubleWord, then ByteIndex must be set to a valid index (BitIndex is ignored). If successful, the method writes the value in pData. The data type variant is Byte, Integer, or Long, depending on the DataType.

S7ProSim V5.4

42

Operating Manual, 07/2011, A5E00992430-02

Methods 3.26 WriteDataBlockValue

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK E_FAIL PS_E_NOTCONNECTED PS_E_POWEROFF PS_E_BADTYPE PS_E_BADBYTENDX PS_E_BADBYTECOUNT PS_E_WRITEFAILED Meaning 0x00000000: Success code 0x80004005: Unspecified error 0x80040211: S7ProSim is not connected to S7-PLCSIM 0x80040212: S7-PLCSIM is powered off 0x80040206: Invalid data type 0x80040201: Byte index is invalid 0x80040202: Size of data array is invalid for given start byte index 0x80040204: Write operation failed

Visual Basic usage


Sub WriteDataBlockValue(BlockNum As Long, ByteIndex As Long, BitIndex As Long, pData)

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

43

Methods 3.27 WriteFlagValue

3.27

WriteFlagValue
STDMETHOD(CS7ProSim::WriteFlagValue)( long ByteIndex, long BitIndex, const VARIANT* pData)

Description
Writes a particular bit (Boolean), a byte (Byte), a two-byte word (Integer) or a four-byte word (Long) in the bit memory area.

Parameters
Parameters Declaration Input Input Description Represents the start byte position in the bit memory area to be written. Valid values for ByteIndex depend on the CPU. Represents the start bit position in the bit memory area to be written, if writing a Boolean value (bit). Valid values for BitIndex are 0 to 7. Pointer to the data to be written. Valid values for data depend on the data type. Make sure you allocate and free this memory area in your application.

ByteIndex BitIndex pData

Input

Notes If the DataType is S7_Bit, then ByteIndex and BitIndex must both be set to valid indexes. If successful, the method writes the specified bit (pData) in the data block with the number BlockNumber. If the DataType is S7_Byte, S7_Word or S7_DoubleWord, then ByteIndex must be set to a valid index (BitIndex is ignored). If successful, the method writes the value in pData. The data type variant is Byte, Integer, or Long, depending on the DataType.

S7ProSim V5.4

44

Operating Manual, 07/2011, A5E00992430-02

Methods 3.27 WriteFlagValue

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK E_FAIL PS_E_NOTCONNECTED PS_E_POWEROFF PS_E_BADTYPE PS_E_BADBYTENDX PS_E_BADBYTECOUNT PS_E_WRITEFAILED Meaning 0x00000000: Success code 0x80004005: Unspecified error 0x80040211: S7ProSim is not connected to S7-PLCSIM 0x80040212: S7-PLCSIM is powered off 0x80040206: Invalid data type 0x80040201: Byte index is invalid 0x80040202: Size of data array is invalid for given start byte index 0x80040204: Write operation failed

Visual Basic usage


Sub WriteFlagValue(ByteIndex As Long, BitIndex As Long, pData)

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

45

Methods 3.28 WriteInputImage

3.28

WriteInputImage
STDMETHOD(CS7ProSim::WriteInputImage)( long StartIndex, const VARIANT* pData)

Description
Writes elements to the peripheral inputs (PI memory area) of S7-PLCSIM, starting at the StartIndex of the data to which pData points.

Parameters
Parameters Declaration Input Input Description Represents the start byte position in the peripheral inputs for the write. Valid values for StartIndex depend on the CPU. Pointer to the data to be written by S7-PLCSIM. Valid values for the data depend on the CPU. Make sure you allocate and free this memory area in your application.

StartIndex pData

Notes The type of elements to be written is determined by the type of the elements in Data. All elements have to be the same data type. A byte array writes bytes, an integer array writes words, and a Long array writes double words. The values written are "raw" and not interpreted or converted by the method in any way. The number of elements written is determined by the size of the array to which Data points.

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK E_FAIL PS_E_BADBYTENDX PS_E_BADBYTECOUNT PS_E_WRITEFAILED PS_E_BADTYPE PS_E_NOTALLWRITESWORKED PS_E_NOTCONNECTED PS_E_POWEROFF Meaning 0x00000000: Success code 0x80004005: Unspecified error 0x80040201: Byte index is invalid 0x80040202: Size of data array is invalid for given start byte index 0x80040204: Write operation failed 0x80040206: Invalid data type 0x80040210: Not all write operations were successful 0x80040211: S7ProSim is not connected to S7-PLCSIM 0x80040212: S7-PLCSIM is powered off

Visual Basic usage


Sub WriteInputImage(StartIndex As Long, Data) As Long S7ProSim V5.4

46

Operating Manual, 07/2011, A5E00992430-02

Methods 3.29 WriteInputPoint

3.29

WriteInputPoint
STDMETHOD(CS7ProSim::WriteInputPoint)( long ByteIndex, long BitIndex, const VARIANT* pData)

Description
Writes either a particular bit (Boolean), byte (Byte), a two-byte word (Integer) or a four-byte word (Long) from the Data variant to the peripheral inputs (PI memory area).

Parameters
Parameters Declaration Input Input Input Description Represents the start byte position in the peripheral inputs for the write. Valid values for ByteIndex depend on the CPU. Represents the bit position (in bytes) in the peripheral area for the write. Valid values are 0 to 7. Pointer to the data to be written. Valid values for data depend on the data type.

ByteIndex BitIndex pData

Notes If Boolean is specified as the data type, then ByteIndex and BitIndex must both be set to valid indexes. If successful, the method writes the specified bit in pData. If Byte, Integer, or Long is specified as the data type, then ByteIndex must be set to a valid index (BitIndex is ignored). If successful, the method writes the elements in pData.

Error handling
Errors are returned in the ConnectionError event, not by the function call.

Return value
Value S_OK E_FAIL PS_E_BADBYTENDX PS_E_BADBYTECOUNT PS_E_WRITEFAILED PS_E_BADBITNDX PS_E_BADTYPE PS_E_NOTCONNECTED PS_E_POWEROFF Meaning 0x00000000 : Success code 0x80004005 : Unspecified error 0x80040201 : Byte index is invalid 0x80040202 : Size of data array is invalid for given start byte index 0x80040204 : Write operation failed 0x80040205 : Byte index is invalid 0x80040206 : Invalid data type 0x80040211 : S7ProSim is not connected to S7-PLCSIM 0x80040212 : S7-PLCSIM is powered off

Visual Basic usage


Sub WriteInputPoint(ByteIndex As Long, BitIndex As Long, Data) As Long

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

47

Methods 3.29 WriteInputPoint

S7ProSim V5.4

48

Operating Manual, 07/2011, A5E00992430-02

Events

4
Event ConnectionError (Page 49) PauseStateChanged (Page 49) PLCSimStateChanged (Page 50) ScanFinished (Page 50) ScanModeChanged (Page 50) Meaning Generated when unable to connect to the control engine ("S7PLCSIM") or when an error occurs with any S7ProSim method call. Generated when a Pause/Continue state change is detected. NewState is a string that represents one of the PauseStateConstants. Generated when a new PLC switch state is detected. NewState is the new operating state: "RUN", "RUN_P" or "STOP". Generated when a single scan is finished. ScanInfo provides indexed information about the scan. Generated when an operating mode change is detected. NewState is a string that represents one of the ScanModeConstants.

Overview

4.1
Description

ConnectionError
HRESULT ConnectionError(BSTR ControlEngine, long Error)

Generated when no connection can be established to the simulated PLC in S7-PLCSIM or when an error occurs when calling an S7ProSim method.

Visual Basic usage


Event ConnectionError(ControlEngine As String, Error As Long)

4.2
Description

PauseStateChanged
HRESULT PauseStateChanged(BSTR NewState)

Generated when a Pause/Continue state change is detected. NewState is a string that represents one of the PauseStateConstants.

Visual Basic usage


Event PauseStateChanged(NewState As String)

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

49

Events 4.3 PLCSimStateChanged

4.3

PLCSimStateChanged
HRESULT PLCSimStateChanged(BSTR NewState)

Description
Generated when a new PLC switch state is detected. NewState is the new operating state: "RUN", "RUN_P" or "STOP".

Visual Basic usage


Event PLCSimStateChanged(NewState As String)

4.4

ScanFinished
HRESULT ScanFinished(VARIANT ScanInfo)

Description
Generated when a single scan is finished. ScanInfo provides indexed information about the scan.

Visual Basic usage


Event ScanFinished(ScanInfo)

4.5

ScanModeChanged
HRESULT ScanModeChanged(BSTR NewState)

Description
Generated when an operating mode change is detected. NewState is a string that represents one of the ScanModeConstants.

Visual Basic usage


Event ScanModeChanged(NewState As String)

S7ProSim V5.4

50

Operating Manual, 07/2011, A5E00992430-02

Type definitions
5.1 Type definitions

Type definitions overview

Type CPURunMode (Page 51) ImageDataTypeConstants (Page 52) PauseStateConstants (Page 52) PointDataTypeConstants (Page 53) RestartSwitchPosition (Page 53) ScanModeConstants (Page 54) tagPauseState (Page 54) ScanInfo constants (Page 55)

Description Constants for the scan state of the CPU RUN mode Constants for the ReadOutputImage method Constants for the pause state Constants for the ReadOutputPoint method Constants for the front panel startup switch position Constants for the operating mode Constants for the pause state Constants for information about the scan cycle

5.2

CPURunMode
enum CPURunMode { CONTINUOUS_SCAN, SINGLE_SCAN, SINGLE_STEP }

Description
Constants for the scan state of the CPU RUN mode

Elements
CONTINUOUS_SCAN SINGLE_SCAN SINGLE_STEP

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

51

Type definitions 5.3 ImageDataTypeConstants

5.3

ImageDataTypeConstants
enum { S7Byte = 2, S7Word = 3, S7DoubleWord = 4 }

Description
Constants for the ReadOutputImage method

Elements
S7Byte S7DoubleWord S7Word

5.4

PauseStateConstants
enum { Running = 0, Paused = 1, Disabled = 2 }

Description
Constants for the pause state

Elements
DISABLED Paused Running

S7ProSim V5.4

52

Operating Manual, 07/2011, A5E00992430-02

Type definitions 5.5 PointDataTypeConstants

5.5

PointDataTypeConstants
enum { S7_Bit = 1, S7_Byte = 2, S7_Word = 3, S7_DoubleWord = 4 }

Description
Constants for the ReadOutputPoint method

Elements
S7_Bit S7_Byte S7_DoubleWord S7_Word

5.6

RestartSwitchPosition
enum { WarmStart = 0, HotStart = 1, ColdStart = 2 }

Description
Constants for the front panel startup switch position

Elements
ColdStartRestart position OB102
HotStartRestart position OB101

WarmStartRestart position OB100

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

53

Type definitions 5.7 ScanModeConstants

5.7

ScanModeConstants
enum { SingleScan = 0, ContinuousScan = 1 }

Description
Constants for the operating mode

Elements
ContinuousScan SingleScan

5.8

tagPauseState
enum tagPauseState { ENABLED_RUNNING, ENABLED_PAUSED, DISABLED }

Description
Constants for the pause state

Elements
DISABLED ENABLED_PAUSED ENABLED_RUNNING

S7ProSim V5.4

54

Operating Manual, 07/2011, A5E00992430-02

Type definitions 5.9 ScanInfo constants

5.9
ScanInfo

ScanInfo constants

The ScanInfo data type variant represents an array of the data type Long. Each Long data type in the array defines some information about the scan, as defined by the ScanInfo constants.
Table 5- 1 Component NUM_OF_SCANINFO_ELEMENTS EXECUTION_TIME_NDX MIN_CYCLE_TIME_NDX LARGEST_CYCLE_TIME_NDX AVERAGE_CYCLE_TIME_NDX IS_PLC_RUNNING_NDX ScanInfo constants Meaning Number of elements in ScanInfo return array. Index 0: Execution time in ms Index 1: Shortest execution time in ms Index 2: Longest execution time in ms Index 3: Average cycle time in ms Index 4: Bit memory: 1 = PLC is running; 0 = PLC is not running Definition 5 0 1 2 3 4

5.10

Error return codes

Error return codes - overview


Error return codes PS_E_BADBITNDX PS_E_BADBYTECOUNT PS_E_BADBYTENDX PS_E_BADTYPE PS_E_INVALIDCALLBACK PS_E_INVALIDDISPATCH PS_E_INVALIDINPUT PS_E_INVALIDSCANTYPE PS_E_MAXINSTANCE PS_E_MODENOTPOSSIBLE PS_E_NOTALLREADSWORKED PS_E_NOTALLWRITESWORKED PS_E_NOTCONNECTED PS_E_NOTIFICATION_EXIST Meaning 0x80040205: Byte index is invalid 0x80040202: Size of data array is invalid for given start byte index 0x80040201: Byte index is invalid 0x80040206: Invalid data type 0x80040207: Invalid callback 0x80040208: Invalid dispatch 0x80040213: Invalid input 0x8004020B: Invalid scan type, must be one of the ScanModeConstants. 0x80040214: Maximum number of open S7-PLCSIM instances reached 0x8004020C: S7-PLCSIM could not set the specified operating mode 0x8004020F: Not all read operations were successful 0x80040210: Not all write operations were successful 0x80040211: S7ProSim is not connected to S7-PLCSIM 0x8004020D: S7ProSim is already registered for notification

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

55

Type definitions 5.10 Error return codes

Error return codes PS_E_NOTREGISTERED PS_E_NOTSINGLESCAN PS_E_PLCNOTRUNNING PS_E_POWEROFF PS_E_READFAILED PS_E_WRITEFAILED E_FAIL E_INVALID_STATE S_OK STG_E_CANTSAVE

Meaning 0x80040209: S7ProSim is not registered for callbacks from S7-PLCSIM 0x8004020A: Single scan program execution is not set in S7-PLCSIM 0x8004020E: S7-PLCSIM is not running 0x80040212: S7-PLCSIM is powered off 0x80040203: Read operation failed 0x80040204: Write operation failed 0x80004005: Unspecified error 0x00008002: Invalid state 0x00000000: Success code 0x80030103: Cannot save

S7ProSim V5.4

56

Operating Manual, 07/2011, A5E00992430-02

Index

A
AVERAGE_CYCLE_TIME_NDX, 55 Defined constants, 51 CPURunMode, 51 ImageDataTypeConstants, 52 PauseStateConstants, 52 PointDataTypeConstants, 53 RestartSwitchPosition, 53 ScanModeConstants, 54 tagPauseState, 54 Disconnect method, 17

B
BeginScanNotify method, 13 Bit memory Read, 30 Writing, 44 Bit memory value Read, 30 Writing, 44

E
EndScanNotify method, 18 Enumeration types, 51 CPURunMode, 51 ImageDataTypeConstants, 52 PauseStateConstants, 52 PointDataTypeConstants, 53 RestartSwitchPosition, 53 ScanModeConstants, 54 tagPauseState, 54 Error return codes, 55 Event handlers, 8 Events ConnectionError, 49 PauseStateChanged, 49 PLCSimStateChanged, 50 ScanFinished, 50 ScanModeChanged, 50 ExecuteNmsScan method, 19 ExecuteNScans method, 20 ExecuteSingleScan method, 21 EXECUTION_TIME_NDX, 55

C
ColdStart, 53 Setting, 38 Connect method, 14 ConnectExt methods, 15 ConnectionError event, 49 Constants, 51 CPURunMode, 51 ImageDataTypeConstants, 52 PauseStateConstants, 52 PointDataTypeConstants, 53 RestartSwitchPosition, 53 ScanModeConstants, 54 tagPauseState, 54 Continue method, 16 Continuous scan program execution GetScanMode, 23 ScanModeConstants, 54 SetScanMode, 37 CPURunMode, 51

D
Data block (DB) values Read, 28 Writing, 42

G
GetPauseState method, 22 GetScanMode method, 23 GetStartUpSwitch method, 24 GetState method, 25

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

57

Index

H
HotStart, 53 Setting, 26, 38 HotStartWithSavedValues method, 26 StartPLCSimExt, 41 WriteDataBlockValue, 42 WriteFlagValue, 44 WriteInputImage, 46 WriteInputPoint, 47 MIN_CYCLE_TIME_NDX, 55

I
ImageDataTypeConstants, 52 Introduction, 7 IS_PLC_RUNNING_NDX, 55

N
NUM_OF_SCANINFO_ELEMENTS, 55

K
Key switch position Get, 25 Setting, 39

O
Operating mode Get, 23 Setting, 37 Overview, 7

L
LARGEST_CYCLE_TIME_NDX, 55 Loading peripheral I/O during a hot start, 26 Loading saved .plc files, 40, 41

P
Pause method, 27 Pause state Get, 22 Setting, 16, 27 PauseStateChanged event, 49 PauseStateConstants, 52 PLCSIM, starting, 40, 41 PLCSimStateChanged event, 50 PointDataTypeConstants, 53 Programming an S7ProSim interface to S7-PLCSIM, 8 Project references, 7

M
Methods BeginScanNotify, 13 Connect, 14 ConnectExt, 15 Continue, 16 Disconnect, 17 EndScanNotify, 18 ExecuteNmsScan, 19 ExecuteNScans, 20 ExecuteSingleScan, 21 GetPauseState, 22 GetScanMode, 23 GetStartUpSwitch, 24 GetState, 25 HotStartWithSavedValues, 26 Pause, 27 ReadDataBlockValue, 28 ReadFlagValue, 30 ReadOutputImage, 32 ReadOutputPoint, 34 SavePLC, 36 SetScanMode, 37 SetStartUpSwitch, 38 SetState, 39 StartPLCSim, 40

R
Read Bit memory value (M), 30 Data block values (DB)T, 28 Output, 34 Output image, 32 ReadDataBlockValue method, 28 ReadFlagValue method, 30 ReadOutputImageT method, 32 ReadOutputPoint method, 34 Reference to an S7ProSim COM object Microsoft Visual Basic, 7 Microsoft Visual C#, 7 Microsoft Visual Studio C++, 7 References, 7

S7ProSim V5.4

58

Operating Manual, 07/2011, A5E00992430-02

Index

RestartSwitchPosition, 53 Return values, 55

T
tagPauseState, 54 Type definitions, 51 CPURunMode, 51 ImageDataTypeConstants, 52 PauseStateConstants, 52 PointDataTypeConstants, 53 RestartSwitchPosition, 53 ScanModeConstants, 54 tagPauseState, 54

S
S7-PLCSIM, starting, 26, 40, 41 S7ProSim Adding to VB project, 7 Interface to S7-PLCSIM, programming, 8 Overview, 7 S7ProSim Pro methods ReadDataBlockValue, 28 ReadFlagValue, 30 WriteDataBlockValue, 42 WriteFlagValue, 44 SavePLC method, 36 Saving .PLC files, 36 Scan execution methods ExecuteNmsScan, 19 ExecuteNScans, 20 ExecuteSingleScan, 21 Scan notification, 13, 18 ScanFinished event, 50 ScanInfo constants, 55 ScanModeChanged event, 50 ScanModeConstants, 54 SetScanMode method, 37 SetStartUpSwitch method, 38 SetState method, 39 Siemens S7ProSim COM object, adding to project, 7 Single scan program execution ExecuteNmsScan, 19 ExecuteNScans, 20 ExecuteSingleScan, 21 GetScanMode, 23 ScanModeConstants, 54 SetScanMode, 37 StartPLCSim method, 40 StartPLCSimExt methods, 41 Startup switch position, 53 Get, 24 Setting, 38

W
WarmStart, 53 Setting, 38 WriteDataBlockValue method, 42 WriteFlagValue method, 44 WriteInputImage method, 46 WriteInputPoint method, 47 Writing Bit memory value (M), 44 Data block (DB) values, 42 Input image, 46 Input point, 47

S7ProSim V5.4 Operating Manual, 07/2011, A5E00992430-02

59

Index

S7ProSim V5.4

60

Operating Manual, 07/2011, A5E00992430-02

Das könnte Ihnen auch gefallen