Manual Prodave Eng
Manual Prodave Eng
SIMATIC S7
Toolbox for PGs and PCs (AT and compatibles)
PRODAVE S7
Toolbox for MS-DOS and WINDOWS 3.11/95/NT
Applications for a Data Link
of PGs/PCs to SIMATIC S7 via MPI Interface and
PC/MPI Cable
Operating Instructions
1. INTRODUCTION .................................................................................................. 1
2. DESCRIPTION ..................................................................................................... 4
3. OPERATION....................................................................................................... 10
Functions Overview................................................................................................................................... 23
4.3 Asynchronous Functions (only possible under MS-DOS and Windows 3.11)............................ 66
e_field_read_as................................................................................................................................ 66
a_field_read_as................................................................................................................................ 66
m_field_read_as............................................................................................................................... 66
t_field_read_as ................................................................................................................................ 66
z_field_read_as................................................................................................................................ 66
d_field_read_as................................................................................................................................ 67
db_read_as....................................................................................................................................... 67
6. APPENDIX.......................................................................................................... 82
This is where the software package PRODAVE S7 will offer the solution.
PRODAVE S7 offers tried and tested functions (tools) in a DLL (Dynamic Link
Library) or LIB (Library) which you can combine for each of your applications.
The combination of the tools is carried out in programming languages for
Windows NT, Windows 95, Windows 3.11 or MS-DOS.
Via these combined functions the process data traffic between PLC and PG/PC
is established by PRODAVE S7 using the MPI interface of the PLC. The data
now available can be translated into a format suitable for PCs and can be
processed by your own application or any standard application. This will
enable you to create a data link between PLC and PG/PC without having
detailed knowledge, and all your development activities can be concentrated on
specific processing of your data.
PRODAVE S7 enables you to not only evaluate and monitor but to influence
your process as well inasmuch that you can have several functions available to
you to enable you to write data to the PLC from the PG/PC.
2. Description
Using the programming package PRODAVE S7 you can read data from a
programmable logic controller (PLC) and write data to a PLC under Windows
95, Windows NT, Windows 3.11 or MS-DOS via several CPUs from the S7-
series.
and
PRODAVE S7 offers the adaptor for Windows 95/NT in the form of a 32-Bit-
DLL (Dynamic Link Library) created in VC++ Version 5.0, for Windows 3.11 in
the form of a 16-Bit-DLL created in BC Version 3.1. The adaptors for MS-DOS
are available as MSC-/ and BC-Libraries in the Large-Model.
If you wish to read data from the PLC or write data to the PLC using a high
language, you will only require the adaptor and its functions.
2.3 Pre-requisites
PRODAVE S7 operates with the following PLC types: S7-200, S7-300, S7-400,
M7 and C7 from the S7 series.
Software-Prerequisites:
Hardware-Prerequisites:
PRODAVE S7 DOS/WFW
ATTENTION !
PRODAVE S7
PRODAVE S7 mini
o CP 5611 PCI-Card
o CP 5511 PCMCIA-Card
o CP 5411 ISA-Card
PC S7-300/400/M7/C7
MPI-ISA MPI-interface
CP5411/5511/5611 S7-200
PPI-interface
PC S7-300/400/M7/C7
Installation and set-up of the required hardware is carried out via the STEP7-
Tool PG/PC interface parameterisation, which is available in the system after
successful installation.
PC S7-300/400/M7/C7
MPI-ISA MPI-interface
Default
Value
ATTENTION!
PC S7-300/400/M7/C7
Default
Value
PC S7-200
Default
Value
retries = 0
The drivers to be used can be loaded, parameterised and linked into the
system by means of the STEP7 tool PG/PC-interface parameterisation
(S7EPATSX.EXE). After correct installation the drivers are automatically
activated every time Windows 95/NT is started.
w Copy path \SINEC\BIN and all associated files on to the hard disk
containing Windows.
Prior to calling an application load the communication driver. Please refer to file
\SINEC\BIN\WINSTART.BAT on the the customer disk for examples:
rem *******************************************************
rem ***** install mpi-driver or pc/mpi-cable-driver*****
rem ***** for connection to AS300 and AS400 *****
rem *******************************************************
rem ***** install ppi-driver *****
rem ***** for connection to AS200 *****
rem *******************************************************
c:
cd c:\sinec\bin
rem ********************************************************
rem ***** prodave mpi driver *****
rem ********************************************************
rem s7mpipgx
rem s7monpgx -s
rem ********************************************************
rem ***** prodave pc/mpi-cable driver *****
rem ********************************************************
rem s7smcpgx
rem s7smnpgx -s
rem ********************************************************
rem ***** prodave ppi-driver *****
rem ********************************************************
rem s7ppipgx
rem s7pmnpgx -s
ATTENTION !
SIEMENS\PRODAVE\INCLUDE\
SIEMENS\PRODAVE\LIB\
SIEMENS\PRODAVE\SAMPLE_VC\
SIEMENS\PRODAVE\SAMPLE_VB\
WINDOWS\SYSTEM\
SIEMENS\PRODAVE\MINI\INCLUDE\
SIEMENS\PRODAVE\MINI\LIB\
SIEMENS\PRODAVE\SAMPLE_VC\
SIEMENS\PRODAVE\SAMPLE_VB\
WINDOWS\SYSTEM\
The user program is written in a high language and the function calls are used
in the form listed in Para. 4 "Description of PRODAVE Functions".
When creating a data link to S7-200 it is not allowed to have more than one
connection parameterised in the load_tool function.
When carrying out the development of your program, the following points
should be noted to avoid data loss or a system crash:
- When reading data from the PLC, the fields into which data is to be
transferred, must be big enough to receive this data as the adaptor does not
carry out a field check!
- The error text file must be located in the same directory as the developed
program as otherwise the adaptor will not be able to read the error texts!
- In order to avoid a repeated “check if it exists” of the error text file, you can
call the function error_message at the start of the program to enable you to
output an appropriate message in the event of an error. This error text file is
loaded when calling this function for the first time.
S5 S7
bit 15 .. bit 0 bit 7..0 bit 7..0
DW 0 DB0 DB1 = DW 0
DW 1 DB2 DB3 = DW 2
= DW 4
DW 2 DB4 DB5
= DW 6
DW 3 DB6 DB7
...
... ... ...
When using the d_field_read function, the data block is accessed byte by byte
such as, for instance, applies to the flag area.
When you read 3 data words using the db_read function, the PLC transfers
DBW0 - DBW5. I.e. three 16bit words are available for processing in the
PG/PC, which the PLC addresses via DBW0, DBW2 and DBW4, by the
PG/PC, however, they are addressed via DW0, DW1 and DW2.
Block: DB10
DB_10
STRUCT
DW ARRAY[0 .. 255]
WORD
END STRUCT
L “DB_10“.DW[2]
T MW10
or
L MW10
T “DB_10“.DW[2]
To enable you to use the PRODAVE functions under Delphi, they must be
declared as follows:
function Unload_tool:Integer;
stdcall;
external ´w95_s7.dll´ name ´unload_tool´;
Example:
var
plc_adr_table : array [0..15] of byte;
name:array[0..255] of char;
res ,amount: integer;
buffer : array[0..255] of word;
plc_adr_table[0] := 2; {address}
plc_adr_table[1] := 0; {segment id}
plc_adr_table[2] := 2; {slotno}
plc_adr_table[3] := 0; {rackno}
plc_adr_table[4] := 0;
strcopy(name,'S7ONLINE');
res := Load_tool(1,addr(name),addr(plc_adr_table[0]));
res := DB_read(10,0,amount,buffer);
res := Unload_tool;
To enable you to use the PRODAVE functions under Access, they must be
declared as follows:
Example:
To enable you to use the PRODAVE functions under Visual-Basic, they must
be declared as follows:
Example:
Functions included in the software package PRODAVE S7 mini have the suffix
mini in the headline.
int a_field_read
(int nr, int amount, void* buffer);
load_tool
This function initialises the adaptor, checks if the driver is loaded, initialises the
parameterised addresses and switches the selected interface to active. Under
MS-DOS and Windows 3.11 it is possible to parameterise a maximum of 4
connections, under Windows 95 a maximum of 16.
#pragma pack(1)
struct {
unsigned char adr; /* station address default 2 */
unsigned char segmentid; /* segment id default 0 */
unsigned char slotno; /* slot no default 2 */
unsigned char rackno; /* rack no default 0 */
} adr_table[5];
#pragma pack()
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
int load_tool
(int nr,char* device,char* adr_table);
Example:
This example initialises 3 connections. Connection 1 to PLC with station
address 2, connection 2 to PLC with station address 4 and connection 3 to PLC
with station address 9. For any further program execution following “load_tool“
connection 3 is set to active.
C-Adapter
#include <w95_s7.h>
int error;
adr_table_type plc_adr_table[3] = { {2,0,2,0},
{4,0,2,0},
{9,0,2,0},
{0,0,2,0} };
:
:
res = load_tool(3,"S7ONLINE",plc_adr_table);
:
res = new_ss(1); /* PLC No 1 address = 2 */
:
res = new_ss(2); /* PLC No 2 address = 4 */
:
res = new_ss(3); /* PLC No 3 address = 9 */
:
error = unload_tool();
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
unload_tool
This function deinitialises the connections and the adaptor and must be re-
called prior to leaving the application!
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
C-Adapter (mini)
int unload_tool(void);
a_field_read
The function a_field_read reads “amount” of output bytes from the PLC starting
from "no" and stores the read value into a variable field of the PG/PC.
If there were no errors, the function supplies 0 as the return value, otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
Example:
Output byte 10 is read. The read value is stored in "buffer".
C-Adapter
#include <w95_s7.h>
char buffer;
int error;
adr_table_type plc_adr_table[2] = { {2,0,2,0},{0,0,2,0} };
error = load_tool(1,”S7ONLINE”,plc_adr_table);
:
error = a_field_read(10,1,&buffer);
:
error = unload_tool();
:
:
The function a_field_write writes "amount" of bytes from the specified storage
area into the PLC starting from output byte "no".
If there were no errors, the function supplies 0 as the return value, otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
The function ag_info reads the issue level of the PLC software and the PG
interface as well as the MLFB number of the PLC and stores them in a storage
area of the PG/PC as an ASCII string zero-terminated.
The issue levels must be interpreted as integer values, the MLFB numbers as
ASCII values:
If there were no errors, the function supplies 0 as the return value, otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
Example:
The issue levels of the PLC software, the PG interface as well as the PLC type
are read.
C-Adapter
#include <w95_s7.h>
int error;
adr_table_type plc_adr_table[2] = { {2,0,2,0},{0,0,2,0} };
#pragma pack(1)
struct {
unsigned short plcas
unsigned short pgas;
char mlfb[21];
} info;
#pragma pack()
:
error = load_tool(1,”S7ONLINE”,plc_adr_table);
:
error = ag_info(&info);
:
error = unload_tool();
:
This function reads the PLC status (RUN or STOP) from the PLC and stores
the data in a storage area of the PG/PC.
buffer[0] = 0 ð AG is in RUN
buffer[0] = 1 ð AG is in STOP
buffer[0] = 1 ð AG is in RESTART
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
C-Adapter
Example:
C-Adapter
#include <w95_s7.h>
unsigned short buffer[512];
int error;
:
:
error = db_buch(buffer);
if (buffer[123] != 0)
{
/* DB 123 ist im AG vorhanden */
}
:
error = unload_tool();
:
:
The function db_read reads an “amount“ of data words from a data block in the
PLC and transfers them into a variable field of the PG/PC.
If the data block does not exist, this is indicated by a return value = error
number.
If the data which is being read, exceeds the amount available in the data block,
the " amount” is corrected and error message 303 hex is returned.
Important!
The data words are stored in the "buffer" not in accordance with Intel-Notation
(low byte - high byte) but in STEP5-Notation (high byte - low byte). This is
important if the data is processed further.
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
int db_read
(int dbno, int dwno, int* anzahl, void* buffer);
The read values are stored in the data buffer “buffer” and are available for
processing.
C-Adapter
#include <w95_s7.h>
int buffer[100];
int error;
int dbno,dwno,anzahl;
:
:
dbno = 10;
dwno = 5;
anzahl = 45;
error = db_read(dbno,dwno,&anzahl,buffer);
:
error = unload_tool();
:
The function db_write writes an amount of data words from a variable field of
the PG/PC into the PLC.
If the data block does not exist this is indicated by a return value = error
number.
If the data which is being written, exceeds the amount available in the data
block, the " amount” is corrected and error message 303 hex is returned.
Important!
The data words must be stored in "buffer" in accordance with STEP5-Notation
(high byte - low byte).
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
int db_write
(int dbno,int dwno, int* anzahl, void* buffer);
Example:
DB10 consisting of 20 data words (DW 0 - DW 19) exists in the PLC.
Value 2468 hex is assigned to DW 1 and DW 2.
C-Adapter
#include <w95_s7.h>
int buffer[100];
int error,dbno,dwno,anzahl;
:
dbno = 10;
dwno = 1;
anzahl = 2;
buffer[0] = 0x6824;
buffer[1] = 0x6824;
error = db_write(dbno,dwno,&anzahl,buffer);
:
error = unload_tool();
:
The function d_field_read reads “ amount“ of data bytes from the PLC starting
from data byte "no" and stores the read values in a variable field of the PG/PC.
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
int d_field_read
(int bstno, int no,int anzahl,void * buffer);
d_field_write
The function d_field_write writes "amount“ of bytes from the specified storage
area to the PLC, starting from data byte "no".
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
int dfield_write
(int bstno, int no,int anzahl,void* buffer);
The function e_field_read reads “amount” of input bytes from the PLC starting
from input byte "no" and stores the read values into a variable field of the
PG/PC.
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
This function checks a bit in a specified flag byte and supplies the status of the
specified bit via "return_wert" (return value) (= boolean variable).
C-Adapter
mb_resetbit
The function mb_resetbit sets a flag in the PLC to 0. It is not checked whether
the flag bit exists in the used PLC.
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
The function mb_setbit sets a flag in the PLC to 1. It is not checked whether
the flag bit exists in the used PLC.
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
The function m_field_read reads “amount” of flag bytes from the PLC starting
from flag byte "no" and stores the read values in a variable field of the PG/PC.
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
m_field_write
The function m_field_write writes "amount" of bytes from the specified storage
area to the PLC starting from flag byte "no".
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
The function t_field_read reads “amount” of timer words from the PLC starting
from timer word "no" and stores the read values in a variable field of the
PG/PC.
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
z_field_read
The function z_field_read reads “amount” of counter words from the PLC
starting from counter word "no" and stores the read values in a variable field of
the PG/PC.
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
z_field_write
The function z_field_write writes “amount” of words to the PLC starting from
counter word "no" from the specified storage area.
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
C-Adapter
E = Input bytes
A = Output bytes
M = Flag bytes
T = Timer words
Z = Counter words
D = Data from DB
The mix_read function reads the data parameterised by “data“ from the PLC
and stores the read values in the specified storage area.
The read values are saved in sequence. I.e. the user himself must carry out
structured processing of the field occupied with the read values. "data" must
have the following structure:
1..255
dbno
:
:
:
type E,A,M,T,Z,D
1..255
dbno
C-Adapter
Input byte 0, output byte 3 and DW 5 from DB 10 are read and the values are
stored in variables e, a and d:
C-Adapter
#include <w95_s7.h>
#pragma pack(1)
typedef struct {
char typ;
char size;
unsigned short dbno;
unsigned short no;
} data_type;
data_type data[10];
#pragma pack()
char buffer[100];
char e,a;
int d;
int error;
:
:
data[0].typ = 'e';
data[0].size= 'b';
data[0].no = 0;
data[1].typ = 'a';
data[1].size= 'b';
data[1].no = 3;
data[2].typ = 'd';
data[2].size= 'w';
data[2].dbno= 10;
data[2].no = 5;
data[3].typ = 0; /* endekennung der liste */
error = mix_read((char*)data,buffer);
e = buffer[0];
a = buffer[1];
d = ((int)buffer[2] << 8) | (int)buffer[3];
:
:
E = Input bytes
A = Output bytes
M = Flag bytes
T = Timer words
Z = Counter words
D = Data in DB
The function mix_write overwrites the data in the PLC parameterised by “data“
with the values transferred in “buffer“..
C-Adapter
Flag Bytes MB 0 - 15 0 - 31 0 - 31 0 - 31
For further information on data types and ranges please refer to the Manual
STEP 7 - Micro / Programming S7-200.
This function reads the issue level of the PLC software and the PC interface as
well as the type of PLC and stores them in a storage area of the PG/PLC as an
ASCII-String zero-terminated.
The issue levels must be interpreted as integer values, the PLC types as
ASCII-values:
If there were no errors, the function supplies a 0 as the return value, otherwise
an error message which can be evaluated in accordance with the error table
(see error_message).
Example:
The issue levels of the PLC software, the PG interface as well as the PLC type
are read.
C-Adapter
#include <w32_s7micro.h>
int error;
adr_table_type plc_adr_table[2] = { {2,0,2,0},{0,0,2,0} };
#pragma pack(1)
struct {
unsigned short plcas
unsigned short pgas;
char mlfb[21];
} info;
#pragma pack()
:
error = load_tool(1,”S7ONLINE”,plc_adr_table);
:
error = as200_ag_info(&info);
:
error = unload_tool();
Toolbox for Data Link PGs/PCs to SIMATIC S7
:
This function reads the PLC status (RUN or STOP) from the PLC and stores
the data in a storage area of the PG/PC.
buffer[0] = 0 ð AG is in RUN
buffer[0] <> 0 ð AG is in STOP
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
Example:
C-Adapter
#include <w32_s7micro.h>
int error;
adr_ table_type plc_adr_table[2] = { {2,0,2,0},{0,0,2,0} };
char state;
:
error = load_tool(1,”S7ONLINE”,plc_adr_table);
:
error = as200_ag_zustand(&state);
if (state == 0); //plc in run
if (state != 0); //plc in stop
:
error = unload_tool();
:
as200_a_field_read
as200_m_field_read
as200_sm_field_read
as200_vs_field_read
The functions as200_X_field_read read “amount” of bytes from the data area of
the PLC starting from "no" and store the read values in a variable field of the
PG/PC.
If there were no errors, the function supplies a 0 as the return value, otherwise
an error number which can be evaluated in accordance with the error table (see
error_message).
C-Adapter
C-Adapter (mini)
C-Adapter
#include <w32_s7micro.h>
int error;
adr_table_type plc_adr_table[2] = { {2,0,2,0},{0,0,2,0} };
#pragma pack(1)
unsigned char buffer[10];
#pragma pack()
:
error = load_tool(1,”S7ONLINE”,plc_adr_table);
:
error = as200_a_field_read(0,10,buffer);
:
error = unload_tool();
:
as200_m_field_write
as200_sm_field_write
as200_vs_field_write
If there were no errors, the function supplies a 0 as the return value, otherwise
an error number which can be evaluated in accordance with the error table (see
error_message).
C-Adapter
C-Adapter (mini)
The functions as200_t_field_read read “amount” of bytes from the data area of
the PLC starting from "no" and store the read values in a variable field of the
PG/PC.
Attention!
5 bytes are received per timer value, and only 2 bytes contain the requested
value (see example)
If there were no errors, the function supplies a 0 as the return value, otherwise
an error number which can be evaluated in accordance with the error table (see
error_message).
C-Adapter
Example:
Timer values 0 and 1 are read and saved in ”T0” and ”T1”.
C-Adapter
#include <w32_s7micro.h>
int error;
adr_table_type plc_adr_table[2] = { {2,0,2,0},{0,0,2,0} };
unsigned char buffer[10];
unsigned short T0,T1;
:
error = load_tool(1,”S7ONLINE”,plc_adr_table);
:
error = as200_t_field_read(0,2,buffer);
T0 = (unsigned short)buffer[4] |
(unsigned short)buffer[3] << 8;
T1 = (unsigned short)buffer[9] |
(unsigned short)buffer[8] << 8;
:
error = unload_tool();
:
The function as200_z _field_read reads "amount" of counter values from the
data area of the PLC starting from "no" and stores the read values in a variable
field of the PG/PC.
Attention!
3 bytes are received per counter value, and only 2 bytes contain the requested
value (see example)
If there were no errors, the function supplies a 0 as the return value, otherwise
an error number which can be evaluated in accordance with the error table (see
error_message).
C-Adapter
Example:
Counter values 3 and 4 are read and saved in ”Z3” and ”Z4”.
C-Adapter
#include <w32_s7micro.h>
int error;
adr_table_type plc_adr_table[2] = { {2,0,2,0},{0,0,2,0} };
unsigned char buffer[10];
unsigned short Z3,Z4;
:
error = load_tool(1,”S7ONLINE”,plc_adr_table);
:
error = as200_z_field_read(3,2,buffer);
Z3 = (unsigned short)buffer[2] |
(unsigned short)buffer[1] << 8;
Z4 = (unsigned short)buffer[5] |
(unsigned short)buffer[4] << 8;
:
error = unload_tool();
:
The function as200_z _field_write writes "amount" of bytes from the specified
storage area to the PLC starting from "no".
Attention!
3 bytes are received per counter value, and only 2 bytes contain the requested
value
If there were no errors, the function supplies a 0 as the return value, otherwise
an error number which can be evaluated in accordance with the error table (see
error_message).
C-Adapter
This function checks a bit in a specified flag byte and supplies the status of this
bit via "return_wert” (= “return_value") (= boolean variable).
C-Adapter
as200_mb_resetbit
This function sets a flag in the PLC to 0. It is not checked whether the flag bit
exists in the used PLC.
If there were no errors, the function supplies a 0 as the return value, otherwise
an error message which can be evaluated in accordance with the error table
(see error_message).
C-Adapter
as200_mb_setbit
This function sets a flag in the PLC to 1. It is not checked whether the flag bit
exists in the used PLC.
If there were no errors, the function supplies a 0 as the return value, otherwise
an error message which can be evaluated in accordance with the error table
(see error_message).
C-Adapter
The as200_mix_read function reads the data parameterised by "data" from the
PLC, and stores the read values in the specified storage area.
size B
0
res
no
:
:
:
type E,A,M,S,V
size B
0
res
no
Example:
Input byte 0, output byte 3 and variable memory bytes 5 and 6 are read and the
values are stored in variables e, a v5 and v6.and d:
C-Adapter
#include <w32_s7micro.h>
#pragma pack(1)
typedef struct {
char typ;
char size;
int dbno;
int no;
} data_type;
data_type data[10];
#pragma pack()
char buffer[100];
char e,a,v5,v6;
int v;
int error;
:
:
data[0].typ = 'e'; /* eingangsbyte 0 */
data[0].size= 'b';
data[0].no = 0;
data[1].typ = 'a'; /* ausgangsbyte 3 */
data[1].size= 'b';
data[1].no = 3;
data[2].typ = 'v'; /* variablen speicher byte 5 */
data[2].size= 'b';
data[2].no = 5;
data[3].typ = 'v'; /* variablen speicher byte 6 */
data[3].size= 'b';
data[3].no = 6;
data[4].typ = 0; /* endekennung der liste */
error = mix_read(data,buffer);
e = buffer[0];
a = buffer[1];
v5= buffer[2];
v6= buffer[3];
:
C-Adapter
boolean_byte
char buff[8] buff[0] buff[1] buff[2] buff[3] buff[4] buff[5] buff[6] buff[7]
return value bit 0 bit 1 bit 2 bit 3 bit 4 bit 5 bit 6 bit 7
C-Adapter
byte_boolean
char buff[8] buff[0] buff[1] buff[2] buff[3] buff[4] buff[5] buff[6] buff[7]
C-Adapter
Example:
-5
Assumption: DBW 0 and DBW 2 = floating point 1,234*10 or
DBW 0 = 374F hex, DBW 2 = 07E5 hex in DB 1.
This program reads 2 data words (DBW 0 and DBW 2), converts the S7
floating point format to IEEE format and makes the value available for
processing in the variable "ieee".
C-Adapter
#include <komfort.h>
#include <w95_s7.h>
int error;
int buffer[100]
int dbno,dwno,anzahl;
float ieee;
:
dbno = 10;
dwno = 0;
anzahl = 2;
error = db_read(dbno,dwno,&anzahl,buffer);
gp_to_float(buffer,&ieee);
:
error = unload_tool();
:
kg_to_float
If there were no conversion errors, the function supplies 0 as the return value,
otherwise 1.
float_to_kg
If there were no conversion errors, the function supplies 0 as the return value,
otherwise 1.
The function kf_integer swaps the high byte and the low byte of a transferred
16-bit value and returns the new value.
C-Adapter MS-DOS
testbit
The function testbit checks whether a specified bit is set in a byte variable.
The byte variable and the bit number are transferred to the function in the form
of parameters.
C-Adapter
This function supplies the approprioate error text relating to an error message
in the form of a zero terminated character string. For this purpose the
ERROR.DAT file is read when the function is first called and the texts are
stored in a file.
When transferring error number 0 the file name of the error text file to be
loaded can be transferred in “buffer“. If no valid file name was transferred or a
ZERO pointer was transferred, the ERROR.DAT file is read in the current
directory. Therefore it must be ensured that the ERROR.DAT file exists and is
in the same directory as the program.
The error texts are stored in English. Should you require the error texts in
German, you must rename the ERROR.GER file (stored on the customer disk
under the \DLL\ERROR.GER directory) to ERROR.DAT, and copy this file into
the directory of your application, or load this file explicitly.
.
A maximum of 100 error texts can be stored.
Note:
We recommend calling the error_message function shortly after program start
by means of error_no = 0 to load the ERROR.DAT file. This ensures almost
consistent processing time for further calls of this function.
C-Adapter
C-Adapter
#include <komfort.h>
#include <w95_s7.h>
int buffer[100];
int error;
int anzahl;
char message[100];
:
:
error = error_message(0,"error.eng");
:
anzahl = 45;
error = db_read(10,5,&anzahl,buffer);
if (error != 0)
error = error_message(error,message);
:
error = unload_tool();
:
:
The Asynchronous Functions serve to read and write data from the PLC
asynchronously to the program.
In the event of an error, the status variable contains the error number.
e_field_read_as
int e_field_read_as
(int no,int anzahl,void * buffer,int * status);
a_field_read_as
int a_field_read_as
(int no,int anzahl,void * buffer,int * status);
m_field_read_as
int m_field_read_as
(int no,int anzahl,void * buffer,int * status);
t_field_read_as
int t_field_read_as
(int no,int anzahl,void * buffer,int * status);
z_field_read_as
int z_field_read_as
(int no,int anzahl,void * buffer,int * status);
int d_field_read_as
(int dbno, int no,int anzahl,void * buffer,
int * status);
db_read_as
int db_read_as
(int dbno, int no,int anzahl,void * buffer,
int * status);
a_field_write_as
int a_field_write_as
(int no,int anzahl,void * buffer,int * status);
m_field_write_as
int m_field_write_as
(int no,int anzahl,void * buffer,int * status);
z_field_write_as
int z_field_write_as
(int no,int anzahl,void * buffer,int * status);
d_field_write_as
int d_field_write_as
(int dbno, int no,int anzahl,void * buffer,
int * status);
db_write_as
int db_write_as
(int dbno, int no,int anzahl,void * buffer,
int * status);
mix_read_as
mix_write_as
The Teleservice functions enable the user to establish and close remote
connections between PG/PCs and TS Adapters. The conversion of data
between the public telephone network / modem and the MPI interface is carried
out by the TS Adapter hardware.
When the TeleService functions are in use it is important to note that the
PG/PC interface in system control the module parameter assignment is set to
TS-Adaptor
When access protection is activated the TS-Adapter checks the specified password.
Providing the password is correct, the connection is established either immediately
or after re-dialling from the TeleService Adapter (depending on TeleService
parameterisation).
The function ts_dial returns the connection status and / or in the event of an
asynchronous call of function ts_dial the message TS_CONNECTED (connection
established) or TS_DISCONNECTED (connection not established) is sent to the
specified window only after the connection is established or if the TeleService
Adapter replies with error (e.g. password not correct).
After the TeleService connection has been established successfully, the user
can establish a connection to the PLC connected to the TS adaptor using the
load_tool function. It is possible to use any amount of PRODAVE functions.
This is followed by closing the connection to the PLC using the unload_tool
function and closing the TeleService connection by means of ts_hang_up_dial
or ts_hang_up_ring.
Note:
After establishing a remote connection this remains active until the user
program calls the ts_hang_up_dial and / or ts_hang_up_ring functions!
The Modem parameters such as dial parameters, location parameters etc. must
be specified in the WINDOWS system control / modems.
The PLC has the facility to establish a TeleService connection via the TS
Adapter. This is carried out by calling the function block 46 PG_DIAL.
For further information please refer to the Product Description TS Adapter and
SIMATIC TeleService.
The function ts_dial dials a remote station via the modem and establishes the
connection to the TS-Adapter. When access protection is activated the
password is checked by the TS-Adapter and the TS-Adaptor may ring back, if
required.
• ModemName
Name of Modem to be used, can be selected in system control / modems
• Location
Name of Modem location, can be selected in system control / modem / dial
parameters
• TelNo
Telephone number, which is dialled by the connected modem.
The telephone number must be transferred in canonical format:
+ CountryCode Space [(area code) Space] Tel.Nr. | SubAddress(ISDN) ^
Name(ISDN)
z.B.: +49 (0711) 137-3969
maximum amount of characters to be input is 31.
• UserName
Specifiy UserName parameterised in TS Adaptor to be called.
Maximum amount of characters to be input is 8.
• Password
Specify password parameterised in TS Adaptor to be called.
Maximum amount of characters to be input is 8.
• WindowHandle
Here it is possible to transfer a window handle. If the handle is valid, the
ts_dial function is processed asynchronously, i.e. the calling application is
advised as to whether the connection has been estalblished positively or
negatively by means of a Windows message.
If the WindowHandle NULL (ZERO) is transferred, the function is processed
synchronously, i.e. the function does not return until after the connection has
been established or the timeout has elapsed.
• Message
Message which is sent to the window when the connection has been
established or the timeout has elapsed.
• wParam
Parameters for the message.
Toolbox for Data Link PGs/PCs to SIMATIC S7
• res1
reserved, must be set to NULL.
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
C-Adapter
C-Adapter
#include <w95_s7.h>
#pragma pack(1)
#pragma pack()
char * ModemName = "Standardmodem";
char * Standort = "Standardstandort";
char * TelNo = "+49 (0711) 137-3978"
char * UserName = "ADMIN"
char * Password = "admin"
int error;
:
:
error = ts_dial(ModemName,Standort,TelNo,
UserName,Password,NULL,0,0,NULL);
if (error == 0)
{
error = load_tool(...);
:
:
:
error = unload_tool();
error = ts_hang_up_dial();
}
:
:
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
C-Adapter
• ModemName
Name of the modem to be used for the ring indication, can be selected in
system control / modem
• NumberOfRings
Number of rings until the modem replies.
• WindowHandle
Here it is possible to transfer a window handle. If the handle is valid, the
calling application is advised as to whether the connection has been
estalblished positively or negatively by means of a Windows message.
If the WindowHandle NULL (ZERO) is transferred, it is possible to recognize
a successful connection by means of the cyclic structure of the ts_read_info
function.
• Message
Message which is sent to the window when the connection has been
established.
• wParam
Parameters for the message.
• res1
reserved, must be set to NULL.
In order to end the ring indication call the function with ModemName=NULL
(ZERO).
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
int ts_set_ringindicator (
char * ModemName,
int NumberOfRings
HANDLE WindowHandle,
UINT Message,
WPARAM wParam,
char * res1);
• EventId
Pointer to a field 16 Bytes long. Information on the alarm triggering station is
entered here.
See Product Description SIMATIC TeleService, FB PG-DIAL.
• MpiAdr
Pointer to a Byte. The MPI address of the alarm triggering station is entered
here.
If no connection is established via the ring indication the function supplies error
number 0336 Hex.
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
C-Adapter
ts_hang_up_ring
If there were no errors, the function supplies 0 as the return value otherwise an
error message which can be evaluated in accordance with the error table (see
error_message).
C-Adapter
The demonstration programs operate on the principle that process data traffic
to a PLC is based on Address = 2 and Slot no = 2!
When connecting an S7-400 with double wide power supply module set Slot
no = 3.
- Insert the appropriate data link cable PLC - PG/PC into the PG interface on
the PLC and into the MPI interface (and/or COM-Port when using the PC/MPI-
or PC/PPI cable) of the PG/PC.
- Expand or create the file WINSTART.BAT in path \SINEC\BIN for the used
data link.
- Start the driver for the used data link by calling WINSTART.BAT.
- Insert the appropriate data link cable PLC - PG/PC into the PG
interface on the PLC and into the MPI interface (and/or COM-Port when
using the PC/MPI- cable) of the PG/PC.
n Insert the appropriate data link cable PLC - PG/PC into the PG interface on
the PLC and into the MPI interface (and/or COM-Port when using the
PC/MPI- cable) of the PG/PC.
n In the event of a data link to S7-200 it is required to dial the relevant module
parameterisation with the suffix (PPI)
n Select the load_tool menu and specify the parameters (address, slot
number, segment ID and rack number) of the destination system.
You may add your own error texts in the ERROR.DAT file to the ones listed
below. See function "error_message".
Error Messages:
CP Communications Processor
CPU Central-Processing-Unit
DB Data Block
PC Personal Computer
PG Programming Unit
6.3.1 Modules
TS-Adaptor
Part No.: 6ES7-972-0CA30-0XA0
PC-Adaptor
Part No.: 6ES7-972-0CA20-0XA0
PC/PPI Cable
Part No.: 6ES7-901-3BF00-0XA0