Softplc7 Command Interface

SUMMARY

This document describes the Command Interface.

CONTENTS

  1. Introduction
  2. Processing
  3. Simulation Commands
  4. API for the Interface
  5. SoftPLC7.ini

Introduction

The SoftPLC7 offers an Interface to communicate between an Instructor Station and several SoftPLC7 Instances of an Emulator Platform. Thus provides the opportunity to simulate the emulation. The standard functionalities like start, continue and time information are supported. In addition snapshots can be saved and restored.

Processing

Prior of using the interface a Plugin-Function of the SoftPLC7 must be activated to handle and control the communication; activation is done by an entry in the SoftPLC7.ini file:

Example:
[Plugin-Function] 
Func1=S7Sync,S7SyncControl
                  

While initializing the Plugin a named Shared-Memory-Area as well as a named event for use by the communication is created. The sequence control of the SoftPLC7 will be enlarged in the following way:

To implement these activities a further process, a Control-Instance that deals with communication via the Shared-Memory and the Event-Setting on any SoftPLC7-Instance, is necessary.

To differ between the communication partners any instance got a number. The SoftPLC-Instances use the numbers 2,3,4 etc; 1 is reserved for the Control-Instance.

Naming for the entries in the SoftPLC7.ini file:

Example:
[IPC-SYNC]
INSTNR=2
SNAPBUFSIZE=2
SHMNAME=Name_Shared-Memory
OWNSEM=Name_First_Event
NEXTSEM=Name_Second_Event
                  

Simulation Commands

For Interprocess-Comminication the Shared-Memory is used in both directions, it complies with the following structure SYNC_STRUCT. Any elementary data types are stored in the Intel format ‘little endian’.

typedef struct
{
       long lVersion;     /* not used yet */
       char achBuffer[1]; /* data for Parameter or Snapshots */
} SNAP_BUF;

typedef struct
{
       short sFreezed;    /* not used yet */
       short sCommand;    /* contains command to be executed */
       short sStatusLo;   /* contains additional status information*/
       short sStatusHi;   /* contains status */
       long lSnpDataSize; /* length of the structure SNAP_BUF incl. achBuffer[...] */
       SNAP_BUF snpbuf;
} SYNC_STRUCT;

After the signalizing of the first event is realized by the SoftPLC7 the command is read and executed. It is defined by the value of sCommand and may take the values listed below. After a command is executed the sStatusHi is set to ‘RD’ for “ready” or ‘ER’ for “error” in case an error occurred. sStatusLo is set ‘0’ and sCommand to ‘NO’.

[NOP]
Definition: The command is defined via the value sCommand = ‘NO’
Prerequisite: non
Action: non

[WRITE_SNAPSHOT]
Definition: The command is defined via the value sCommand = ‘WS’
Prerequisite: Size of Shared-Memory_Area. Depending on the project 1-2 MB or larger.
Action: Starting at ‘snpbuf.achBuffer[]’ any changeable data are stored contiguous in the Memory Area. The value at ‘|SnpDataSize’ defines the needed length of the Snapshot.

[RESTORE_SNAPSHOT]
Definition: The command is defined via the value sCommand = ‘RS’
Prerequisite: The SoftPLC7 needs to be in the FREEZE-Mode.
Action: The Memory-Area starting at ‘snpbuf.achBuffer[]’ is interpreted as a stored Snapshot. Finding a valid format, the Snapshot is restored.

[STOP]
Definition: The command is defined via the value sCommand = ‘SO’.
Prerequisite: non
Action: If the SoftPLC7 is in RUN-Mode, it enters STOP-Mode.

[WARMSTART]
Definition: The command is defined via the value sCommand = ‘S1’.
Prerequisite: The SoftPLC7 is in STOP-Mode.
Action: A Warmstart (OB100) is initialized.

[RESTART]
Definition: The command is defined via the value sCommand = ‘S2’.
Prerequisite: The SoftPLC7 is in STOP-Mode.
Action: A Restart (OB101) is initialized.

[COLDSTART]
Definition: The command is defined via the value sCommand = ‘S3’.
Prerequisite: The SoftPLC7 is in STOP-Mode.
Action: A Coldstart (OB102) is initialized.

[LOAD_PROGRAM]
Definition: The command is defined via the value sCommand = ‘LP’.
Prerequisite: The SoftPLC7 is in STOP-Mode.
Action: In the Memory-Area starting at ‘snpbuf.achBuffer[]’ a folder name (zero terminated) is read; the folder name is used as new project folder and the program within is loaded.

[SAVE_PERSISTENT]
Definition: The command is defined via the value sCommand = ‘SP’.
Prerequisite: The SoftPLC7 is in STOP-Mode.
Action: All persistent data are saved in the subfolder “\Persistent” of the project folder.

[FREEZE]
Definition: The command is defined via the value sCommand = ‘FR’.
Prerequisite: non
Action: : If the SoftPLC7 is in UNFREEZE-Mode it enters the simulation status FREEZE. Any timer und counter is halted.

[UNFREEZE]
Definition: The command is defined via the value sCommand = ‘UF’.
Prerequisite: The SoftPLC7 is in FREEZE-Mode.
Action: The SoftPLC7 enters the UNFREEZE-Mode. Any timer and counter is started.

[DEBUG_ON]
Definition: The command is defined via the value sCommand = ‘D1’.
Prerequisite: The SoftPLC7 is Offline.
Action: The Debug-Interface to the SIMATIC Manager is activated.

[DEBUG_OFF]
Definition: The command is defined via the value sCommand = ‘D0’.
Prerequisite: non
Action: If the SoftPLC is online, the interface to the SIMATIC Manager is closed.

[SET_CLOCK]
Definition: The command is defined via the value sCommand = ‘SC’.
Prerequisite: non
Action: : If the data starting at ‘snpbuf.achBuffer[] got a valid DATE_AND_TIME structure, the system time (SFC1) is set accordingly.

[GET_DATA]
Definition: The command is defined via the value sCommand = ‘GD’.
Prerequisite: non
Action: A dynamic number of Data-Block-Areas from which data should be read is defined. The format is still subject to change.

[PUT_DATA]
Definition: The command is defined via the value sCommand = ‘PD’.
Prerequisite: non
Action: A dynamic number of Data-Block-Areas including the values that will be written to the data blocks of the SoftPLC7 are predefined. The format is still subject to change.

[MALFUNCTION]
Definition: The command is defined via the value sCommand = ‘MF’.
Prerequisite: non
Action: Via that command data may handed over 1:1 to HLL-DLLs. If within a DLL a function "void ExecMalFunction(BYTE* puch, WORD wCount)" is exported, this function is called at that point. The transferred data out of the Shared-Memory merely passed on and have to be interpreted by the function.

API for the Interface

For convenient use of the interface the following functions are available in a library:

[Allocation of the Shared-Memory-Area]
SYNC_API int SyncInitEvents(char* pszOwnSem, char* pszNextSem, DWORD dwMilliseconds, HANDLE* phOwnEvent, HANDLE* phNextEvent);

This function returns a handle to a Shared-Memory-Area; it is used for the communication between the Control-Instance and the SoftPLC7. If the area is not defined by the SoftPLC7 yet it will be created by that function call.

Parameter Description
ppvBase Pointer to the Shared-Memory-Area
pszName Name of the Shared-Memory-Area
lSize Length of the Shared-Memory-Area (when created)
bWait=FALSE
(Call within the SoftPLC7)
The Shared-Memory-Area will be created by that call.
bWait=TRUE
(Call within the Control-Instance)
That call blocks until the Shared-Memory-Area is created.
phSharedMem Pointer to a handle to the Shared-Memory-Area.

[Creating events]
SYNC_API int SyncInitEvents(char* pszOwnSem, char* pszNextSem, DWORD dwMilliseconds, HANDLE* phOwnEvent, HANDLE* phNextEvent);

The Control-Instance creates an event for any SoftPLC-Instance; that event is signalized after any Time-Slice by the SoftPLC7. The event a SoftPLC7 is - prior a Time-Slice - waiting for, is created by the SoftPLC7 itself; it is referenced to via a handle by the Function-Call.

Parameter Description
pszOwnSem Name of the event the SoftPLC7 is signalizing after a Time-Slice. The event is created by the Function-Call.
pszNextSem Name of the event the SoftPLC7 is waiting for prior a Time-Slice. That Function-Call blocks (max. dwMilliseconds) until the SoftPLC7 created the event.
dwMilliseconds see above
phOwnEvent Handle to the created event.
phNextEvent Handle to the event that is reverenced to.

[Waiting for an event]
SYNC_API int SyncWaitForEvent(DWORD dwMilliseconds, HANDLE* phEvent);

The function waits a maximum of dwMilliseconds for an event and resets it if no timeout occurred.

Parameter Description
dwMilliseconds Defines the maximum waiting time in milliseconds.
phEvent Pointer to the event.

[Signalizing an event]
SYNC_API int SyncSignalEvent(HANDLE* phEvent);

The function signalizes an event.

Parameter Description
phEvent Pointer to the event.

INI-FILES

SoftPLC7.ini

Section [Plugin-Functions]

Entry Type Description / Example Default
Func<n> string
Activates Plugin-Functions of the SoftPLC7.
Example
Func1=S7Sync,S7SyncControl
				
Note:
This function is called up by the same fixed cycle that the OBs are synchronized with. It waits for the token, hands over the control to the S7-threads and on cycle end it passes on the token.

Section [IPC-SYNC]

Entry Type Description / Example Default
INSTNR integer
Defines the Instance number, must be >=2.

Number used for passing on the token; not to mix up with the instance number. Value 1 is reserved for the control application.
-1
SNAPBUFSIZE integer
Defines the buffer size for the Snapshot file, depending on the project 1-2 MB is recommended.
That value defines the size of the Shared-Memory-Area.

Defines the size of the user area for commands. 0 allocates 1 MB
0
SHMNAME string
Name of the Shared-Memory-Area defined by the SoftPLC7.

Name of the shared memory area used for communication.
OWNSEM string
Name of the first event defined by the SoftPLC7.

Name of the semaphore the SoftPLC7 is waiting for.
NEXTSEM string
Name of the second event defined by the Control-Instance.

Name of the semaphore the SoftPLC7 sets after executing the OB-cycles.