3.5 Linking to Standard Tools
3.5.1 PRODAVE under Delphi (32-Bit) Example
To enable you to use the PRODAVE functions under Delphi, they must be declared as follows:
function Load_tool ( no:Byte; name: {pointer} PChar; adr:{pointer} PChar):Integer; stdcall
external 'w95_s7.dll' name 'load_tool';
function DB_read ( dbno:Integer; dwno:Integer; var amount:Integer; var buffer):Integer stdcall;
external 'w95_s7.dll' name 'db_read';
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;
begin
.....
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;
....
end;
4.1 Functions
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.
C-Adapter
int load_tool
(int nr,char* device,char* adr_table);
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
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 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).
C-Adapter
int a_field_read (int no,int anzahl,void * buffer);
a_field_write
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).
C-Adapter
int a_field_write (int no,int anzahl,void* buffer);
ag_zustand
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
C-Adapter
int ag_zustand (void * buffer)
db_read
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).
C-Adapter
int db_read
(int dbno, int dwno, int* anzahl, void* buffer);
db_write
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).
C-Adapter
int db_write
(int dbno,int dwno, int* anzahl, void* buffer);
DELPHI 32 - Unit S7_DLL by
[email protected]
{*******************************************************************
PLC S7 - PC Interface Communication
Version : 1.6
Unit : S7_DLL.PAS
Author :
[email protected]
********************************************************************}
Unit S7_DLL;
Interface
Uses
SysUtils, Dialogs;
function Connect ( no:Byte; name: {pointer} PChar; adr:{pointer} PChar)
:Integer; stdcall; external 'w95_s7.dll' name '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.
The following 3 parameters are transferred to this function:
no - number of active connection (1..4).
device - device name (zero terminated) of the used driver
e.g. S7ONLINE for the MPI driver or ZERO (default).
adr_table - pointer to address list of the connected party.
In this instance adr = 0 is interpreted as the end identifier of
the list.
Example:
VAR
Plc_Addr_Table : Array [0..15] of Byte;
S7_Name : Array [0..255] of Char;
res, Amount : Integer;
Buffer : Array [0..255] of Word;
Plc_Addr_Table[0] := 2; //address
Plc_Addr_Table[1] := 0; //segment id
Plc_Addr_Table[2] := 2; //slotno
Plc_Addr_Table[3] := 0; //rackno
Plc_Addr_Table[4] := 0;
Strcopy(S7_Name,'S7ONLINE');
res := Connect(1,Addr(S7_Name),Addr(Plc_Addr_Table[0]));
}