SoftPlc7 Peripheral I/O Interface

SUMMARY

This document describes how to create a HLL-DLL for SoftPlc7 to supply values for and write values from the peripheral I/O-bytes.

CONTENTS

  1. Introduction
  2. Procedure
  3. SoftPLC7.ini

Introduction

In a HardPLC7 the peripheral I/O bytes are automatically used when an interface card is attached to the PLC.
When using SoftPlc7 on a PC an interface DLL has to be provided to map the peripheral I/O bytes to the API provided by the manufacturer of the interface card.
This interface can also be used to connect peripheral I/O bytes to other sources like files or shared memory for test and simulation purposes.

Procedure

For general information about the HLL-DLLs see SoftPlc7 HLL-Interface and the SoftPLC7SampleHll directory in your SoftPlc7 installation.

A HLL-Function for peripheral I/O must always have the following signature:

extern "C" void __declspec(dllexport) MyFunction(
    bool bWrite,            // read or write
    int iOffset,            // offset of the first byte
    unsigned uiDBNum,       // data block number (0=periphery bytes)
    unsigned uiAccessWidth, // 1=='B', 2=='W'
    unsigned uiAccessCount, // number of entries
    void *pValueBuffer);    // the values to read or write 
            

MyFunction will be called twice at the start of each PLC cycle:
first to write (bWrite==true) the values changed by the Step7 program during the last cycle to the periphery and then to read (bWrite==false) new values from the periphery.
MyFunction has to read/write uiAccessWidth * uiAccessCount consecutive bytes to/from pValueBuffer.
iOffset and uiDBNum are values from SoftPLC7.ini, which are only included for information (e.g. to write a log file).

INI-FILES

SoftPLC7.ini

Section [HLL-Functions]

Entry Type Description / Example Default
PYstart,len [,part] string
The defined DLL-Function supplies the peripheral I/O bytes 0 to 255. The following syntax is used: <dll, function>
Note:
If parameter [, part] is missing, it will be replaced by the default '0'
Example
PY0,256=MyDll, MyFunction
					

That entry assigns peripheral bytes to a process image. Actualization is done either after OB cycles or explicitly via SFC 26 and SFC 27, in that case a read after write is performed.

Note:
Prior to start of any first cycle only a read is performed.
DB <num>, start,len [, (R |W |RW ) [,part]] string
Prior to cyclestart that DLL-Function supplies the defined bytes of a given DB by reading and writing. The following syntax is used: <dll, function>
Note:
If DB-Numer=0 the entry applies to a peripheral
If parameter [, part] is missing, it is set to '0' and actualisation is initiated on cycle start of OB1 only.
Example
DB100,10,40,RW=MyDll, MyFunction
					
The bytes 10 to 40 of DB 100 are read from and written to on cycle start of OB 1. Default for parameter 4 is RW.