Speed7ComDrv V6 2 English
Speed7ComDrv V6 2 English
Speed7ComDrv V6 2 English
Communication Driver
V6.2X
for VIPA 100V/200V/300S/SLIO and
S7-1500®, S7-1200®, S7-300®, S7-400® from Siemens
Documentation
Developers Guide
Feb. 2014
_________________________________________________
Page 1
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
LOGO!®, STEP®, SIMATIC®, S7-1500®, S7-1200®, S7-300®, S7-400® are registered trademarks
of SIEMENS AG.
Page 2
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Page 3
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Page 4
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Page 5
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
7.2 The two initialisation functions of the NETLink PRO Page 135
Page 6
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
As of version 6.23 a 64 bit version of the driver is available. You can use this DLL for 64 bit
applications, on a 64 bit OS. A 64 bit application is necessary, if the limits of 32 bit applications
become a problem. For example files become greater then 4 GB. The disadvantage of 64 bit
applications is, that they only run on a 64 bit OS., e.g. Windows 8-64bit.
A 32 bit applications can be used on a 32 bit and 64 bit OS.
The DLL can be integrated into Windows applications to communicate with the PLC. You need
a PC/MPI cable (RS232, USB), the NetLink or NETLink PRO (TCP/IP) to communicate. You
can also communicate via an Ethernet-CP or an Ethernet interface (also Profinet) that is
integrated into the CPU. In this case, the units communicate via a standard Ethernet cable.
SIMATIC®-NET is supported from the 32-Bit version, provided that the drivers were installed on
the PC. In this case, it is possible, for example, to address CPs 5711, 5512, 5611 and the
Siemens USB-MPI adapter. In the presence of Siemens’ Teleservice V6, the driver can also
acquire data via telephone lines (e.g. using the Teleservice II-Adapter).
Page 7
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
System requirements
Platform: WinXP, Vista, Win7 (32/64 bit), Win8 (32/64 bit)
Platform CE-Version: Windows CE 6.0 or higher (ARM/x86)
Page 8
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Page 9
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
After installation, all DLLs are available on the hard disk. These differ in the programming
languages into which they may be integrated. Please make absolutely sure that you use the
DLL that is supplied for your programming language.
A DLL that has not been activated automatically reverts to a demo version.
The demo version displays a demo message with every open-function. This message requires
confirmation. Subsequently, the demo message will appear at certain intervals or when you
execute the open-function.
Page 10
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Page 11
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Since different versions of the individual development environments may be used, the user
must ensure that the proper declarations are used for the respective programming languages.
2.1 Windows CE
There is an example for the CE-Version of the driver as an Visual C++ 2008 solution.
You find this example in the directory "EXAMPLES Windows CE".
For WinCE-projects please use the DLLs from the directory "DLL-WinCE". Here you find the
files for ARM and x86.
Page 12
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
To use the driver-DLL in the project the lib file must be included in the project configuration.
The following figure shows an example for VC 2008:
In order to execute the application in the development environment the driver-DLLs must be
copied into the project directory.
2.2.2 Example for VC++
The example for VC6 is located in the directory "Example Visual C V6". This can also be used
for versions < VC2008, the project is converted to the respective version when it is opened.
The example for VC2008 is located in the directory "Example Visual C 2008".
Note:
The VC-examples cannot be used with the express version of Visual C, since the MFC class
library is not available in the express version.
Page 13
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
In the Builder project, the LIB file is simply included in the project group of the EXE file.
In order to execute the application in the development environment the driver-DLLs must be
copied into the project directory.
If you use the 64-bit DLL, the extension of the lib file is ".a". The C++ Builder XE3 is the first
version, where the 64 bit DLL can be used.
2.3.2 C++ Builder example
The installation directory of the driver contains several examples for the C++ Builder. These are
sorted in accordance with the version number of the Builder.
This includes examples for the Builder version C++Builder 5, C++Builder 2007 and C++Builder
2010. For versions < C++Builder 2007 you can use the Project C++Builder 5.
Newer versions (Builder XE, XE 2, ..) can use the example C++ Builder 2010.
There is also an 64-bit example for C++ Builder XE3 or higher.
Page 14
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
If you use VB 2010 or higher, open the example "Example Visual Basic 2010" or "Example
Visual Basic 2010 with wrapper"
Important note:
If you start your application inside of Visual Studio, the DLLs of the driver must be copied into
the BIN-Directory of the solution.
Example:
If you set the configuration manager to "Debug" and "x86", you have to copy the DLLs into the
directory "...\bin\x86\Debug\".
Page 15
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
2.5 Visual C#
The files in the directory "DLL Bit32\VC" or "DLL-Bit64\VC" must be used. This contains the
necessary DLL files. This directory contains another directory named "NET". This is where the
DLL the wrapper-class is stored. It is named "ComDrvS7V6_Net.dll". Copy the DLLs into the
project directory "..\bin\Debug".
The wrapper-class (or the ComDrvS7V6_Net.dll file) must be inserted into the project folder
references.
using MHJSW.ComDrvS7V6_Net;
Refer to the example "Example Visual C# 2008 with PCPanel WPF" if you are using the
PCPanel WPF Controls.
Important note:
If you start your application inside of Visual Studio, the DLLs of the driver must be copied into
the BIN-Directory of the solution.
Example:
If you set the configuration manager to "Debug" and "x86", you have to copy the DLLs into the
directory "...\bin\x86\Debug\".
Page 16
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
2.6 Delphi
Newer versions of Delphi IDE can use the exampel of Delphi XE5. The declarations of the
driver functions (32-Bit and 64-Bit) are in the file "ComDrvS7Functions.pas".
Page 17
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
3 General procedure
The image below shows the basic procedure when using the communication driver.
Depending on the connection that was established with a CPU, one of the 6 MPI6_Open
functions is called.
Then the MPI6_ConnectToPLC function is called.
If this function did not result in an error, the CPU may be accessed via the read, write and
information functions.
If the data is exchanged cyclically with the CPU, so you can leave the connection open and
regain access to the CPU at any time.
The function MPI6_CloseCommunication is only called at the end of the communication
session (or in case of an error) to disconnect the CPU and to release the instance of the
communication driver.
Page 18
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
In this driver, the access path to the CPU is defined via the open function. When the open
function has been executed, there are no differences regarding the access path.
For example, if you must change from NetLink to TCP/IP Direct, then the call must access
"MPI6_OpenTcpIp" instead of "MPI6_OpenNetLink“. Otherwise, no changes are necessary.
This also applies to all the other access paths.
Page 19
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
When using the wrapper class in .Net, the handle for the communication instance is not
required, since this handle is managed by the wrapper class.
Page 20
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
This function creates a communication instance. The variable "Handle" supplies the
"identification" for this instance. This identifier must be passed to the other functions of the DLL
to ensure that the specified communication path is used (COM port, baud rate, etc.). This
means that the handle defines the communication instance (not applicable for .Net wrapper
class).
Page 21
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Function return BOOL If the function was executed successfully, a value '1'(TRUE) is
returned. When an error has occurred, the returned value is '0'
(FALSE).
Example
The following example opens the COM2 interface using the function MPI6_OpenRS232. A
transmission rate of 115200 baud was selected.
//Variables
int ComNr=2; //COM2 port
long BaudRate=115200; //baud rate 115200BYTE PGMPIAdresse=0;
//address of the DLL application = 0
BYTE HoechsteMPI=31; //highest address permitted in network = 31
bool SchnittstelleWarSchonAllokiert=false; //true if the
//interface was
//already in use
WORD Error=0; //error variable
char ErrorString[255];//error string to return the error
int MPIHandle=-1; //handle of the new communication instance
//establish connection
if (!MPI6_OpenRS232(&MPIHandle, ComNr, BaudRate, PGMPIAdresse,
HoechsteMPI,
&SchnittstelleWarSchonAllokiert,
&Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
return;
}//end if
MessageBox(AppHandle, "Einleitung war erfolgreich.", "",
MB_ICONINFORMATION);
Page 22
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
This function creates a communication instance. The variable "Handle" supplies the
"identification" for this instance. This identifier must be passed to the other functions of the DLL
To ensure that the specified communication path (IP address) is used (not required for the .Net
wrapper class).
Page 23
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The following example employs the MPI6_OpenNetLink function to connect to a NetLink with
the IP address 172.16.130.84.
Note:
It should be mentioned again that the specifying the PG-address and the highest MPI/DP
address does not change the values defined in the NetLink. The NetLink settings are defined by
means of the configuration utility that is included. These settings must only be entered once,
thereafter the settings are stored permanently the NetLink.
Page 24
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
This function creates a communication instance. The variable "Handle" supplies the
"identification" for this instance. This identifier must be passed to the other functions of the DLL
to ensure that the specified communication path (IP address) is used (not required for the .Net
wrapper class).
Page 25
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The following example employs the MPI6_OpenTcpIp function to establish a connection with an
Ethernet-CP with the IP address 172.16.130.84.
Page 26
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
The function establishes a connection with a S7-1500® that has the specified IP address.
Please read the chapter "Required settings in a PLC 1500 from Siemens" for the important
hardware settings!
This function creates a communication instance. The variable "Handle" supplies the
"identification" for this instance. This identifier must be passed to the other functions of the DLL
to ensure that the specified communication path (IP address) is used (not required for the .Net
wrapper class).
Example
The following example employs the MPI6_OpenTcpIp_S71500 function to establish a
connection with a S7-1500? CPU with the IP address 172.16.130.84
Page 27
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
The function establishes a connection with a S7-1500® that has the specified IP address.
In addition to the function "MPI6_OpenTcpIp_S71500", the function supports the selecting of
the used network adapter. This function is required, when there are more than one network
adapter available.
Please read the chapter "Required settings in a PLC 1500 from Siemens" for the important
hardware settings!
This function creates a communication instance. The variable "Handle" supplies the
"identification" for this instance. This identifier must be passed to the other functions of the DLL
to ensure that the specified communication path (IP address) is used (not required for the .Net
wrapper class).
Page 28
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
The function establishes a connection with a S7-1200® that has the specified IP address.
This function creates a communication instance. The variable "Handle" supplies the
"identification" for this instance. This identifier must be passed to the other functions of the DLL
to ensure that the specified communication path (IP address) is used (not required for the .Net
wrapper class).
Example
The following example employs the MPI6_OpenTcpIp_S71200 function to establish a
connection with a S7-1200? CPU with the IP address 172.16.130.84
Page 29
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Page 30
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The following example employs the MPI6_Open_NetLinkPro_TCP_AutoBaud function to
connect to a NETLink PRO with the IP address 172.16.130.84.
Note:
Before the NETLink PRO is used for the first time, it must be set to the necessary
communication parameters. Use the configuration software that is supplied with the SPEED7
communication driver. After the driver has been installed, it is located in the directory "NETLink
PRO Konfigurator".
The settings you have entered (such as IP address, subnet mask, etc.) are permanently stored
in the NETLink PRO. This means that the settings are still available after the supply voltage has
been disconnected from of the NETLink PRO.
No additional driver is required to operate the NETLink PRO with this driver!
Page 31
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Page 32
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
BaudrateUsed WORD Passing the baud rate defined for the MPI/DP network. Here the
following valued have been defined:
9.6 kBaud: MPIA_BAUD_96 corresponds to a value 0
19.2 kBaud: MPIA_BAUD_19_2 corresponds to a value 1
45.45 kBaud: MPIA_BAUD_45_45 corresponds to a value 2
93.74 kBaud: MPIA_BAUD_93_75 corresponds to a value 3
187.5 kBaud: MPIA_BAUD_187_5 corresponds to a value 4
500 kBaud: MPIA_BAUD_500 corresponds to a value 5
1500kBaud: MPIA_BAUD_1500 corresponds to a value 6
3000 kBaud: MPIA_BAUD_3000 corresponds to a value 7
6000 kBaud: MPIA_BAUD_6000 corresponds to a value 8
12000 kBaud: MPIA_BAUD_12000 corresponds to a value 9
Error WORD* If the function returns '0’, an error has occurred during execution.
In this case, the Error parameter contains an error value.
Function return BOOL If the function was executed successfully, a value '1'(TRUE) is
returned. When an error has occurred, the returned value is '0'
(FALSE).
Page 33
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The following example employs the MPI6_Open_NetLinkPro_TCP_SelectBaud function to
connect to a NETLink PRO with the IP address 172.16.130.84. The NETLink PRO is connected
to the Profibus-DP interface of the CPU. The DP network is set to operate at 1.5MBaud.
Note:
Before the NETLink PRO is used for the first time, it must be set to the necessary
communication parameters. Use the configuration software that is supplied with the SPEED7
communication driver. After the driver has been installed, it is located in the directory "NETLink
PRO Konfigurator".
The settings you have entered (such as IP address, subnet mask, etc.) are permanently stored
in the NETLink PRO. These settings are also retained when the supply power to the NETLink
PRO is turned off.
No additional driver is required to operate the NETLink PRO with this driver!
Page 34
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
The condition is that the SIMATIC® NET driver was installed on the PC. This driver is installed
on the PC, for example, when the Simatic®-Manager (from V5.4), the driver for the
SIEMENS-USB adapter or the Teleservice V6 are installed. You must select the interface to be
used here in the "PG/PC interface configuration" dialog. You can access this dialog by means
of the file "s7epatsx.exe" in the Windows System32 directory.
With the Siemens Teleservice V6, you can start a remote query via the telephone line using the
TS-adapter II.
The function MPI6_Open_SimaticNet establishes a connection with the device that was
selected in the dialog "PG/PC interface configuration".
Page 35
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
if (!MPI6_Open_SimaticNet(&DLLHandle, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
return;
}//end if
MessageBox(AppHandle, "Initialisation successful.", "",
MB_ICONINFORMATION);
Note:
The SIMATIC®-NET connection must not be used to establish connections NetLink, NetLink
PRO or TCP/IP-Direkt. Please use the appropriate initialisation functions (e.g.
MPI6_Open_NetLinkPro_TCP_SelectBaud, MPI6_OpenTcpIp, etc.) for these communication
paths.
Page 36
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_CloseCommunication function must be called last in order to stop the
communications with a PLC for good. This function also closes the interface that was opened
by means of the function "MPI6_OpenRS232" or via the MPI6_OpenNetLink, MPI6_OpenTcpIp,
MPI6_Open_SimaticNet, MPI6_Open_NetLinkPro_TCP_AutoBaud or
MPI6_Open_NetLinkPro_TCP_SelectBaud functions. Furthermore, the communication instance
identified by the specified handle will be eliminated.
WORD Error=0;
char ErrorString[255]={0};//error string to return the error
if (!MPI6_CloseCommunication(MPIHandle, &Error)){
MPI_A_GetDLLError(ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
MessageBox(AppHandle, "communications terminated without
errors.", "", MB_ICONEXCLAMATION);
}//end else
Note:
Even if the function returns an error, the serial interface or the socket is closed and the
communication instance eliminated. One exception is the error
ERROR_MPIA_PARAMETER_ERROR (number 510) that does not pass a correct handle. In
this case, no action can be executed (does not apply to the .Net wrapper class).
Page 37
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_GetAccessibleNodes function can be used to identify the MPI/DP addresses of the
devices connected to an MPI network or to Profibus-DP.
Page 38
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example MPI6_GetAccessibleNodes:
The example below determines the nodes that are accessible on the connected MPI-network.
Page 39
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_SetRoutingData function must be called before you can access a CPU that is not
directly connected using the MPI6_ConnectToPLCRouting function. The parameters of the
function define the CPU to which you want to be routed. Routing means that you do not
communicate with the CPU that is directly connected to the PC but via a different CPU that is
linked with this CPU.
Important exception:
Routing can employ communication channels NetLink, NetLink PRO, TCP/IP direct and
SIMATIC®-NET. Routing is not possible with the MPI6_OpenRS232 function.
Routing example:
The MPI6_ConnectToPLCRouting function is explained by an example regarding routing.
Page 40
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Page 41
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_ConnectToPLC function must be called before you can address the desired CPU
with read or write access functions. This function determines which node is addressed via the
connected MPI or Profibus-DP network. Here the communication partner is specified by the
MPI or the Profibus address.
Important exception:
If the initialisation was executed by means of the MPI6_ConnectToPLC function, then the MPI
address is a dummy value, since the CPU is already defined by the IP address and the CPU
slot number. In this case, the MPI/DP address must always be specified as 2.
Note:
Page 42
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The example below establishes a communication link with a PLC. The CPU has the MPI
address 10.
Page 43
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_ConnectToPLCRouting function must be called before you can address the desired
CPU with read or write access functions. In contrast to the MPI6_ConnectToPLC function, the
CPU that is connected directly to the PC will not be accessed. Here a CPU will be accessed
that is connected via a network link with the directly connected CPU. The CPU that will be
accessed can be specified by means of the parameters of the MPI6_SetRoutingData function.
Important exception:
If the initialisation was executed by means of the MPI6_OpenRS232 function, then it is not
possible to perform routing. In this case, the MPI6_ConnectToPLCRouting function must not be
used.
Page 44
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Page 45
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Here there is no different to a call that does not use routing. The IP address of the NetLink PRO
is specified in the call. In this example, the IP address is "192.168.2.100".
4.17.2 Routing data transfer
Now the data must be passed to the actual CPU being accessed using the
MPI_A_SetRoutingData function.
BYTE TargetBaugruppeSlotNr=2;
BYTE TargetBaugruppeRackNr=0;
BYTE TargetBaugruppeMPI_DP_Adresse=2;//address not relevant
char TargetBaugruppeIPAdresseStr[50]={0};
strcpy(TargetBaugruppeIPAdresseStr, "192.168.2.177");//IP of the 315-PN/DP
WORD TargetSubnetzID_High=0x1122;
WORD TargetSubnetzID_Low=0x3344;
BYTE TargetNetzIstMPI_DP_Netz=0;//the target network is Ethernet
//
if (!MPI6_SetRoutingData(DLLHandle, TargetBaugruppeSlotNr,
TargetBaugruppeRackNr, TargetBaugruppeMPI_DP_Adresse,
TargetBaugruppeIPAdresseStr, TargetSubnetzID_High,
TargetSubnetzID_Low, TargetNetzIstMPI_DP_Netz,
&Error)){
//error
MPI_A_GetDLLError(DLLHandle, DLLErrorString, Error);
MessageBox(AppHandle, DLLErrorString, "", MB_ICONSTOP);
//
return;
}//end if
MessageBox(AppHandle, "Routing data transferred successfully.", "",
MB_ICONINFORMATION);
Page 46
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Now the parameters are complete. This only leaves the last function
MPI6_ConnectToPLCRouting to be called.
4.17.3 Call the function MPI6_ConnectToPLCRouting
The MPI6_ConnectToPLC function must not be used, since the connection will not be
established with the CPU that is connected directly to the PC but with a CPU that is networked
with this CPU. You must use the function MPI6_ConnectToPLCRouting to establish
communications.
The example below shows this call:
BYTE AGMPIAdresse=8; //the MPI address of the directly connected CPU
if (!MPI6_ConnectToPLCRouting(MPIHandle, AGMPIAdresse,
&Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
MessageBox(AppHandle, "Communications established successfully!",
"", MB_ICONINFORMATION);
}//end else
The CPU MPIAdresse must have the value 8, since this is the MPI address of CPU C313-DP to
which the PC is connected. This CPU then forwards the request to the CPU that must be
accessed.
Page 47
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
When configuring the hardware of the CPUs it is important to note, that the routing data must
also be transferred. In the Simatic?-Manager for example, this type of configuration must be
performed by means of the NetPro. This is necessary to ensure that the CPUs are aware of the
other CPUs will be accessible via them.
It should also be noted that the rate of communication when routing is less that that of a direct
connection.
The driver supports routing for the communication paths NetLink, NetLink PRO, TCP/IP direct
and SIMATIC®-NET (only 32-Bit).
Page 48
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The function MPI6_ReadByte can be used to determine the status of input, output, flags and
data block bytes.
If the CPU is protected by a password, this does not have to be transferred.
Page 49
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The example below retrieves the status information from the communication partner having MPI
address 10 starting with memory byte 10. 30 bytes must be read.
Page 50
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
//terminate communications
if (!MPI6_CloseCommunication(MPIHandle, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
MessageBox(AppHandle, "Communications terminated without errors.", "",
MB_ICONINFORMATION);
Page 51
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The function MPI6_ReadWord can be used to determine the status of input, output, flags and
data block words.
If the CPU is protected by a password, this does not have to be transferred.
Page 52
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Note:
It should be noted that the structure of the returned status values is as follows (example of word
memory MW2):
Word memory 2 = clock memory 2 (HIBYTE) and clock memory 3 (LOBYTE)
It should also be noted that byte-oriented word operands overlap. For this reason, the function
either reads all even or all odd words in the specified area. This depends on the value specified
in "wAddress". If you specify an even number here (e.g. 10), all even-numbered words are
read. If, for example, the value passed is 13, then all the odd words read.
In actual fact it only makes sense to read even-numbered words, the option was left open to
cater for exceptions.
Example
In the example below, the status information of the even numbered word memories from word
memory 0 are read from a communication partner. There are 5 words to be read. After the
action, the status buffer contains the contents of word memories MW0, MW2, MW4, MW6 and
MW8.
The example assumes that the initialisation functions (e.g. MPI6_OpenTcpIp) were completed
successfully. Similarly, the function MPI6_ConnectToPLC must have been executed without
errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance. In the
same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
//read data
if (!Fehler){
WORD StatusBuffer[100]={0};
BYTE Operand=77; //clock memory ASCII-Code 77
if (!MPI6_ReadWord(MPIHandle, Operand, 0, StatusBuffer,
5, 0, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
char AusgabeStr[255]={0};
wsprintf(AusgabeStr, "Word memory 2 has status (hex):
%04X", StatusBuffer[1]);
MessageBox(AppHandle, AusgabeStr, "", MB_ICONINFORMATION);
}//end else
}//end if
.
.
.
Page 53
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The function MPI6_ReadDword can be used to determine the status of input, output, flags
(memory bits) and data block double words.
If the CPU is protected by a password, this does not have to be transferred.
Page 54
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Note:
It should be noted that the structure of the returned status values is as follows (example of
double word memory MD2):
MD2 consists of word memories MW2 and MW4, where MW2 represents the Hi-word. MW2 in
turn consists of the bytes MB2 and MB3. MW4 consists of the bytes MB4 and MB5. Thus, MD2
includes 4 bytes, i.e. MB2, MB3, MB4 and MB5.
It should also be noted that byte-oriented double word operands overlap. For this reason, the
function reads either all even or all odd double words or all the odd double words in the
specified area. This depends on the value specified in "wAddress". If you specify an even
number here (e.g. 10), all even-numbered double words are read. If, for example, the value
passed is 13, then all the odd double words read.
In fact, it only makes sense to read even-numbered double words, the option was left open to
cater for exceptions.
Example
In the example below the status information of the even numbered double word memories from
double word memory 0 are read from a communication partner. There are 5 double words to be
read. After the action, the status buffer contains the contents of double word memories MD0,
MD4, MD8, MD12 and MD16.
The example assumes that the initialisation functions (e.g. MPI6_OpenTcpIp) were completed
successfully. Similarly, the function MPI6_ConnectToPLC must have been executed without
errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance. In the
same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
//read data
if (!Fehler){
DWORD StatusBuffer[100]={0};
BYTE Operand=77; //clock memory ASCII-Code 77
if (!MPI6_ReadDword(MPIHandle, Operand, 0, StatusBuffer,
5, 0, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
char AusgabeStr[255]={0};
wsprintf(AusgabeStr, "MD4 has the status (hex):
%08X", StatusBuffer[1]);
MessageBox(AppHandle, AusgabeStr, "", MB_ICONINFORMATION);
}//end else
}//end if
.
.
Page 55
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_ReadTimer function can be used to determine the status of timer blocks.
If the CPU is protected by a password, this does not have to be transferred.
Note:
The timer-word has the following structure:
Bit 0-9: BCD-coded time factor
Bit 12+13: time base (0=10ms, 1=100ms, 2=1s, 3=10s)
Page 56
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
In the example below, the status information of timers 0 to 4 is read from a communication
partner.
The example assumes that the initialisation functions (e.g. MPI6_OpenTcpIp) were completed
successfully. Similarly, the function MPI6_ConnectToPLC must have been executed without
errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance. In the
same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
//read data
if (!Fehler){
WORD StatusBuffer[10]={0};
if (!MPI6_ReadTimer(MPIHandle, 0, StatusBuffer, 5, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
char AusgabeStr[255]={0};
wsprintf(AusgabeStr, "Timer 1 has status (hex):
%04X", StatusBuffer[1]);
MessageBox(AppHandle, AusgabeStr, "", MB_ICONINFORMATION);
}//end else
}//end if
.
.
.
Page 57
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_ReadCounter function can be used to determine the status of counter blocks.
If the CPU is protected by a password, this does not have to be transferred.
Note:
The strcture of the counter word is as follows:
Bit 0-9: BCD-coded counter reading
Page 58
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
In the example below the status information of timers 0 to 4 is read from a communication
partner.
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others.
Executing the function MPI6_CloseCommunication will terminate communications and eliminate
the instance.
In the same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
//read data
if (!Fehler){
WORD StatusBuffer[10]={0};
if (!MPI6_ReadCounter(MPIHandle, 0, StatusBuffer, 5, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
char AusgabeStr[255]={0};
wsprintf(AusgabeStr, "Counter 1 has the status (hex):
%04X", StatusBuffer[1]);
MessageBox(AppHandle, AusgabeStr, "", MB_ICONINFORMATION);
}//end else
}//end if
.
.
.
Page 59
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_MixRead_2 function can be used to read the status of the operands in areas E, A, M,
DB, T and Z.
Here, the status of different operands can read by means of a single call and in no particular
order. For example, it is possible to read the status of input word EW2, clock memory MB10,
data word 2 of DB10 (DB10.DBW2) and timer block T2 by means of a call to the
MPI6_MixRead_2 function.
The function automatically optimises the request. Overlapping operands, duplicate requests,
etc. are detected and the protocol to the CPU is optimised accordingly.
This function can be used to read the status from different operand areas when different
addresses of an operand area must be read (e.g. MW0, MW100, MB150, etc.).
Page 60
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The example below requests the status information of the operands MB10, DB2.DBW0 and
DB1.DBD100 from a communication partner.
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others.
Executing the function MPI6_CloseCommunication will terminate communications and
eliminate the instance. This takes place in the same way as it was shown in the example of the
MPI6_ReadByte function.
Page 61
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
.
.
.
char ErrorString[255]={0};
WORD Error=0;
//create the arrays
DWORD Op_Type[3];
DWORD Op_Address[3];
DWORD Op_LengthByte[3];
DWORD DBNr[3];
DWORD Data[3];
//enter MB10 into array index 0
Op_Type[0]=0x0101; //clock memory
Op_Address[0]=10; //address 10
Op_LengthByte[0]=1; //length 1 byte
DBNr[0]=0; //DB number=0 since this is not DB data
//DB2.DBW0 im Array-Index 1 eintragen
Op_Type[1]=0x7101; //DB data
Op_Address[1]=0; //address 0
Op_LengthByte[1]=2; //length 2 byte = 1 word
DBNr[1]=2; //DB number=2
//enter DB1.DBD100 into array-index 2
Op_Type[2]=0x7101; //DB data
Op_Address[2]=100; //address 100
Op_LengthByte[2]=4; //length 4 bytes = 1 double word
DBNr[2]=1; //DB number=1
//the number of operands to read
WORD wCountParam=3; //3 operands
//call to the MixRead function
if (!MPI6_MixRead_2(MPIHandleV6, Op_Type, Op_Address, DBNr,
Op_LengthByte, Data, wCountParam, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandleV6, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
char AusgabeStr[255]={0};
wsprintf(AusgabeStr, "DB2.DBW0 has the status(hex): %04X",
LOWORD(Data[1]));
MessageBox(AppHandle, AusgabeStr, "", MB_ICONINFORMATION);
}//end else
//
.
.
.
Page 62
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_WriteByte function can control the value of input, output, flags (memory bist) and
data block bits. This means that the operands can be set to the value passed by the function.
Note
The use of the MPI6_WriteBit_2 function is inefficient; it should only be used in exceptional
cases. The function should only be used when it is important to control a single bit without
affecting the other bits of the byte. In all other cases, the WriteByte, WriteWord or WriteDword
functions are preferable.
Page 63
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The example below sets memory bit M10.3 in the communication partner to the value 1.
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance. In the
same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
//write data
if (!Fehler){
BYTE SteuerWert=1;
WORD wByteAddress=10;
BYTE bBitAddress=3;
WORD wDBNR=0;
BYTE Operand=77; //clock memory ASCII-Code 77
Page 64
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_WriteByte function can control the value of input, output, flags (memory bits) and
data block bytes. This means that the operands can be set to the value passed by the function.
Page 65
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
In the example below, clock memory bytes 0 to 9 in the communication partner are set to the
value FF (hex).
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance. This
takes place in the same manner as it was shown in the example of the MPI6_ReadByte
function.
.
.
.
//write data
if (!Fehler){
BYTE SteuernBuffer[10]={0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF};
BYTE Operand=77; //clock memory ASCII-Code 77
if (!MPI6_WriteByte(MPIHandle, Operand, 0, SteuernBuffer,
10, 0, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
MessageBox(AppHandle, "Control was successful!", "",
MB_ICONINFORMATION);
}//end else
}//end if
.
.
.
Page 66
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_WriteWord function can control the value of input, output, flag (memory bit) and data
block words. This means that the operands can be set to the value passed by the function.
If the CPU is protected by a password, this does not have to be transferred.
Page 67
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Note:
It should be noted that the values specified in wordBufferPtr are written as follows (for example,
clock memory MW2):
MB 2 = HIBYTE(wordBufferPtr[0])
MB 3 = LOBYTE(wordBufferPtr[0])
It should also be noted that byte-oriented word operands overlap. For this reason, the function
either writes to all even or all odd words in the specified area. This depends on the value
specified in "wAddress". If you specify an even number here (e.g. 10), all even-numbered words
will be written. If the value passed is 13, all the odd words are written.
In fact, it only makes sense to write even-numbered words, the option was left open to cater for
exceptions.
Example
In the example below, clock memory words 30 to 38 in the communication partner are set to the
value 1F00(hex).
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others. When the
MPI6_CloseCommunication function was executed, communications can be terminated and
the instance removed. This takes place in the same way as it was shown in the example of the
MPI6_ReadByte function.
.
.
.
//write data
if (!Fehler){
WORD SteuernBuffer[5]={0x1F00, 0x1F00, 0x1F00, 0x1F00, 0x1F00};
BYTE Operand=77; //clock memory ASCII-Code 77
if (!MPI6_WriteWord(MPIHandle, Operand, 30, SteuernBuffer,
5, 0, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
MessageBox(AppHandle, "Control was successful!", "",
MB_ICONINFORMATION);
}//end else
}//end if
.
.
.
Page 68
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_WriteDword function can control the value of input, output, flag (memory bit) and
data block double words. This means that the operands can be set to the value passed by the
function.
If the CPU is protected by a password, this does not have to be transferred.
Page 69
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Note:
It should be noted that the values specified in dwordBufferPtr are written as follows (for
example, double word memory MD2):
MB 2 = HIBYTE(HIWORD(dwordBufferPtr[0]))
MB 3 = LOBYTE(HIWORD(dwordBufferPtr[0]))
MB 4 = HIBYTE(LOWORD(dwordBufferPtr[0]))
MB 5 = LOBYTE(LOWORD(dwordBufferPtr[0]))
It should also be noted that byte-oriented word operands overlap. For this reason, the function
reads either all even double words or all the odd double words in the specified area. This
depends on the value specified in "wAddress". If you specify an even number here (e.g. 10), all
even-numbered double words are written. If the value passed is 13, all the double odd words
are written.
In fact, it only makes sense to write even-numbered double words, the option was left open to
cater for exceptions.
Example
In the example below, memory double words 10 and 14 in the communication partner are set to
the value 11223344(hex).
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance. In the
same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
//write data
if (!Fehler){
DWORD SteuernBuffer[2]={0x11223344, 0x11223344};
BYTE Operand=77; //clock memory ASCII-Code 77
if (!MPI6_WriteDword(MPIHandle, Operand, 10, SteuernBuffer,
2, 0, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
MessageBox(AppHandle, "Control was successful!", "",
MB_ICONINFORMATION);
}//end else
}//end if
.
.
.
Page 70
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_WriteTimer function can be used to control the value of timer blocks. This means
that the timer can be set to the value passed by the function.
If the CPU is protected by a password, this does not have to be transferred.
Note:
The timer-word has the following structure:
Bit 0-9: BCD-coded time factor
Bit 12+13: time base (0=10ms, 1=100ms, 2=1s, 3=10s)
Page 71
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The example below writes the value 100 (hex) to timers 3-9 in the communication partner.
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance. In the
same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
//write data
if (!Fehler){
WORD SteuernBuffer[7]={0x100, 0x100, 0x100, 0x100, 0x100, 0x100,
0x100};
if (!MPI6_WriteTimer(MPIHandle, 3, SteuernBuffer, 7, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
MessageBox(AppHandle, "Control was successful!", "",
MB_ICONINFORMATION);
}//end else
}//end if
.
.
.
Page 72
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_WriteCounter function can be used to control the value of counter blocks. This
means that the counter can be set to the value passed by the function.
If the CPU is protected by a password, this does not have to be transferred.
Page 73
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The example below writes the value 10 (hex) to timers 10 to 21 in the communication partner.
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance. In the
same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
//write data
if (!Fehler){
WORD SteuernBuffer[12]={0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
0x10, 0x10, 0x10, 0x10, 0x10, 0x10};
if (!MPI6_WriteCounter(MPIHandle, 10, SteuernBuffer, 12
&Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
MessageBox(AppHandle, "Control was successful!", "",
MB_ICONINFORMATION);
}//end else
}//end if
.
.
.
Page 74
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_MixWrite_2 function can be used to control the operands in the areas E, A, M, DB, T
and Z, i.e. to set these to the specified value.
Here, the control of different operands can occur by means of a single call and in no particular
order. For example, it is possible to control input word IW2, flags (memory bits) MB10, data
word 2 of DB10 (DB10.DBW2) and timer block T2 by means of a single call to the
MPI6_MixWrite_2 function.
The function automatically optimises the control request. Overlapping operands, duplicate
requests, etc. are detected and the protocol to the CPU is optimised accordingly.
This function can be used to control different operand areas when different addresses of an
operand area must be written (e.g. MW0, MW100, MB150, etc.).
Page 75
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The example below controls the operands MB10, DB2.DBW0 DB1.DBD100 in the CPU to set
them to the target values.
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance. In the
same way as it was shown in the example of the MPI6_ReadByte function.
Page 76
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
.
.
.
char ErrorString[255]={0};
WORD Error=0;
//
DWORD Op_Type[3];
DWORD Op_Address[3];
DWORD Op_LengthByte[3];
DWORD DBNr[3];
DWORD Data[3];
//MB10: enter data into array index 0
Op_Type[0]=0x0101; //clock memory
Op_Address[0]=10; //address 10
Op_LengthByte[0]=1; //length 1 byte
DBNr[0]=0; //DB number=0 since this is not DB data
Data[0]=0x33; //control value
//DB2.DBW0: enter data into array index 1
Op_Type[1]=0x7101; //DB data
Op_Address[1]=0; //address 0
Op_LengthByte[1]=2; //length 2 byte = 1 word
DBNr[1]=2; //DB number=2
Data[1]=0x1122; //control value
//DB1.DBD100: enter data into array index 2
Op_Type[2]=0x7101; //DB data
Op_Address[2]=100; //address 100
Op_LengthByte[2]=4; //length 4 bytes = 1 double word
DBNr[2]=1; //DB number=1
Data[2]=0x55667788; //control value
//Number of operands to be controlled
WORD wCountParam=3; //3 operands
//call to the MixWrite function
if (!MPI6_MixWrite_2(MPIHandleV6, Op_Type, Op_Address, DBNr,
Op_LengthByte, Data, wCountParam, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandleV6, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
MessageBox(AppHandle, "Control executed successfully.", "",
MB_ICONINFORMATION);
}//end else
//
.
.
.
Page 77
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_WriteBit function can be used to change the contents of a bit in operand areas input,
output, clock memory and data.
Note
The use of the MPI6_WriteBit function is ineffective; it should only be used in exceptional
cases. The function should only be used when it is important to control a single bit without
affecting the other bits of the byte. In all other cases, the WriteByte, WriteWord or WriteDword
functions are preferable.
Page 78
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The example below sets memory bit M10.1 in the communication partner to the value 1.
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance. In the
same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
//write data
if (!Fehler){
WORD SteuerWert=1;
if (!MPI6_WriteBit(MPIHandle, 10, 1, 0, 'M', &SteuerWert,
&Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
MessageBox(AppHandle, "Operand M10.1 was controlled"
"successfully!", "", MB_ICONINFORMATION);
}//end else
}//end if
.
.
.
Page 79
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_WriteDBFromWldToPlc function can be used to
transfer a data block that is contained in a WLD file into the CPU. WLD files are created and
filled with blocks by S7 programming systems (e.g. Simatic-Manager, WinPLC7). The S7
programming systems are also able to read and edit modules from WLD files.
Together with the MPI6_ReadDBFromPlcAndWriteToWld function, you can load data blocks
from the CPU, save them on the PC and write them to the CPU if required.
In addition to backing up data, this can also be used to realize a type of recipe management.
Page 80
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The following example reads DB2 from a WLD file that is named "Test_Datei.wld" and that is
located in the path "D:\MPI6_Testprojekt\" and transfers this to the CPU. If DB2 should already
exist in the CPU, then this must be overwritten.
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance. In the
same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
WORD Error=0;
char ErrorString[255]={0};
char WldFileWithPath[555]={0};
BYTE OverwriteIfExist=1; //overwrite a DB that exists
//in the CPU
WORD wDBNR=2; //DB2 must be transferred
//specify the WLD file with path
strcpy(WldFileWithPath, "D:\\MPI6_Testprojekt\\Test_Datei.wld");
//Execute the transfer of the DB from the WLD file into the CPU
if (!MPI6_WriteDBFromWldToPlc(MPIHandleV6, WldFileWithPath, wDBNR,
OverwriteIfExist, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandleV6, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
MessageBox(AppHandle, "DB was written successfully.", "",
MB_ICONINFORMATION);
}//end else
.
.
.
Page 81
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_ReadDBFromPlcAndWriteToWld function can be used to load a data block from a
CPU to save it to a WLD file on your PC.
The S7 programming systems (e.g. Simatic?-Manager or WinSPS-S7) can read and edit
modules from WLD files.
Together with the MPI6_WriteDBFromWldToPlc function, you can load data blocks from the
CPU, save them on the PC and write them back to the CPU if required.
In addition to backing up data, this can also be used to realize a type of recipe management.
Page 82
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The following example reads DB2 from the CPU and writes it to a WLD file that is named
"Test_Datei.wld" and that is located in the path "D:\MPI6_Testprojekt\".
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance. In the
same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
WORD Error=0;
char ErrorString[255]={0};
char WldFileWithPath[555]={0};
WORD wDBNR=2; //DB2 must be retrieved from the CPU
//specify the WLD file with path
strcpy(WldFileWithPath, "D:\\MPI6_Testprojekt\\Test_Datei.wld");
//Read the DBs from the CPU and save it to the WLD file
if (!MPI6_ReadDBFromPlcAndWriteToWld(MPIHandleV6, WldFileWithPath,
wDBNR, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandleV6, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
MessageBox(Application->Handle, "Read the DBs from the CPU"
"and saving to the WLD was successful.", "",
MB_ICONINFORMATION);
}//end else
.
.
.
Page 83
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_GetDBNrInWldFile function can be used to identify data blocks that exist in a WLD
file.
WLD files are created and filled with blocks by S7 programming systems (e.g. Simatic-Manager
and WinSPS-S7). The S7 programming systems are also able to read and edit modules from
WLD files.
The MPI6_ReadDBFromPlcAndWriteToWld and MPI6_WriteDBFromWldToPlc functions you
can load data blocks from a CPU, save them on the PC and write them back to the CPU if
required.
In addition to backing up data, this can also be used to realize a type of recipe management.
Page 84
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The example below determines the existing data blocks from the WLD file named
"Test_Datei.wld" which is located in the path "D:\MPI6_Testprojekt\".
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
exexuted successfully.
.
.
.
//
WORD Error=0;
char ErrorString[255]={0};
char WldFileWithPath[555]={0};
//specify the WLD file with path
strcpy(WldFileWithPath, "D:\\MPI6_Testprojekt\\Test_Datei.wld");
//Read the DBs from the CPU and save it to the WLD file
WORD wcountDB=0; //this variable returns the number of DBs
WORD DBNrArray[100]; //array for existing DB numbers
WORD MaxDBNumbers=100; //the array for a max. of 100 DB numbers
if (!MPI6_GetDBNrInWldFile(MPIHandleV6, WldFileWithPath, DBNrArray,
&wcountDB, MaxDBNumbers, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandleV6, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
char AusgabeStr[255]={0};
wsprintf(AusgabeStr, "The WLD file contains %u DBs.",
wcountDB);
MessageBox(AppHandle, AusgabeStr, "", MB_ICONINFORMATION);
}//end else
//
.
.
.
Page 85
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_ReadPlcClock function can be used to read the current date and time from the CPU.
The date and time is returned in the format Date-and-Time. In addition, a string specifying the
function will be provided.
Page 86
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The example below reads the date and time from the CPU.
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance. In the
same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
char ErrorString[255]={0};
WORD Error=0;
//
BYTE byteBufferPtr[8]={0}; //buffer for the format Date-and-Time
char DTStr[255]={0}; //returned setting as string
//
if (!MPI6_ReadPlcClock(MPIHandleV6, byteBufferPtr, DTStr, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandleV6, ErrorString, Error);
MessageBox(ApplHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
char AusgabeStr[255]={0};
wsprintf(AusgabeStr, "Datum Uhrzeit in der CPU: %s", DTStr);
MessageBox(ApplHandle, AusgabeStr, "", MB_ICONINFORMATION);
}//end else
.
.
.
Page 87
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_WritePlcClock function can be used to set the date and time in the CPU.
The date and time must be specified in the format Date-and-Time.
Page 88
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
In the example below, the date in the CPU is set to 31.05.2009 and the time to 12:33, 10
seconds and 333 milliseconds.
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance. In the
same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
char ErrorString[255]={0};
WORD Error=0;
//
BYTE byteBufferPtr[8]={0};
byteBufferPtr[0]=0x09; //year 2009
byteBufferPtr[1]=0x05; //month 5
byteBufferPtr[2]=0x31; //day 31
byteBufferPtr[3]=0x12; //hour 12
byteBufferPtr[4]=0x33; //minute 33
byteBufferPtr[5]=0x10; //second 10
byteBufferPtr[6]=0x33; //milliseconds 333 specification 1
byteBufferPtr[7]=0x31; //milliseconds 333 specifiaction 2 day = 1
//
if (!MPI6_WritePlcClock(MPIHandleV6, byteBufferPtr, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandleV6, ErrorString, Error);
MessageBox(ApplHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
MessageBox(ApplHandle, "Date and time was saved.", "",
MB_ICONINFORMATION);
}//end else
.
.
.
Page 89
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_CopyRamToRom function can be used to transfer the actual values of the data
blocks from the CPUs memory into the load memory. This means that these values are
retained even when you issue a master reset to the CPU.
For example, this function may be executed if you have changed the values in a DB by means
of PLC commands or by control functions via the driver and if these values should remain active
after a master reset.
This function can only be executed when the CPU is in STOP mode. If the CPU is not in STOP
mode, you can set it to STOP mode with the MPI6_SetPLCToStop function.
The execution of this function may require a few minutes (depending on available memory).
Page 90
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The example below executes the function copy RAM-to-ROM in the CPU. To start with, the
CPU must be in STOP mode.
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance. In the
same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
char ErrorString[255]={0};
WORD Error=0;
//test whether CPU is in RUN mode
bool PlcInRun=false;
if (!MPI6_IsPLCInRunMode(MPIHandleV6, &PlcInRun, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandleV6, ErrorString, Error);
MessageBox(ApplHandle, ErrorString, "", MB_ICONEXCLAMATION);
return;
}//end if
//
if (PlcInRun){
MessageBox(ApplHandle, "Action not valid in RUN mode!", "",
MB_ICONINFORMATION);
return;
}//end if
//
if (!MPI6_CopyRamToRom(MPIHandleV6, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandleV6, ErrorString, Error);
MessageBox(ApplHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
MessageBox(ApplHandle, "The action was executed.", "",
MB_ICONINFORMATION);
}//end else
.
.
.
Page 91
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_PLCHotRestart and MPI6_CPUWiederanlauf functions issue a restart command to
the CPU. The condition is that the CPU supports a restart (S7-400 with the appropriate
hardware configuration) and that the mode selector is in position RUN.
Page 92
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_PLCWarmRestart or MPI6_CPUNeustart functions result in a restart of the CPU,
provided that the mode selector is in position RUN.
.
char ErrorString[255]={0};
WORD Error=0;
//
if (!MPI6_CPUNeustart(MPIHandleV6, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandleV6, ErrorString, Error);
MessageBox(ApplHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
MessageBox(ApplHandle, "Action was executed.", "",
MB_ICONINFORMATION);
}//end else
.
Page 93
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_SetPLCToStop functions change the status of the CPU to STOP.
.
char ErrorString[255]={0};
WORD Error=0;
//
if (!MPI6_SetPLCToStop(MPIHandleV6, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandleV6, ErrorString, Error);
MessageBox(ApplHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
MessageBox(ApplHandle, "Action was executed.", "",
MB_ICONINFORMATION);
}//end else
.
Page 94
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_IsPLCInRunMode function determines the status of the CPU and returns a value '1'
in parameter PlcInRun if the CPU is in RUN mode.
Page 95
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The example below tests whether the CPU is in RUN mode.
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance. In the
same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
char ErrorString[255]={0};
WORD Error=0;
//Ist die CPU in RUN
bool PlcInRun=false;
if (!MPI6_IsPLCInRunMode(MPIHandleV6, &PlcInRun, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandleV6, ErrorString, Error);
MessageBox(ApplHandle, ErrorString, "", MB_ICONEXCLAMATION);
return;
}//end if
//
if (PlcInRun){
MessageBox(ApplHandle, "CPU ist in RUN mode!", "",
MB_ICONINFORMATION);
}//end if
else {
MessageBox(ApplHandle, "CPU is not in RUN mode!", "",
MB_ICONINFORMATION);
}//end else
.
.
.
Page 96
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_GetSystemValues function can be used to read the system areas from a CPU. For
example, this can provide information on the number of timers, counters and clock memories
that are available for programming.
Page 97
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The example below reads the system areas from the communication partner.
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance. In the
same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
//read data
if (!Fehler){
WORD AnzahlBytePAE, AnzahlBytePAA, AnzahlMerker, AnzahlZeiten;
WORD AnzahlZaehler;
DWORD AnzahlByteRam;
WORD AnzahlByteLokaldaten;
//
if (!MPI6_GetSystemValues(MPIHandle, &AnzahlBytePAE,
&AnzahlBytePAA,
&AnzahlMerker, &AnzahlZeiten,
&AnzahlZaehler,
&AnzahlByteRam,
&AnzahlByteLokaldaten,
&Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
char AusgabeStr[255]={0};
wsprintf(AusgabeStr,
"Number of bytes PAE: %03u\n"
"Number of bytes PAA: %03u\n"
"Number of clock memories: %03u\n"
"Number of timers : %03u\n"
"Number of counters : %03u\n",
AnzahlBytePAE, AnzahlBytePAA, AnzahlMerker,
AnzahlZeiten, AnzahlZaehler);
MessageBox(AppHandle, AusgabeStr, "", MB_ICONEXCLAMATION);
}//end else
}//end if
.
.
.
Note:
The data for this information function are provided by the virtual CPU. The CPU is only able to
do this once "in parallel". If another communication instance should also accesses an
information function of the same CPU, A communication error may result.
Page 98
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_GetLevelOfProtection function can be used to determine the protection levels that
were defined for a CPU. The position of the key switch on the CPU is also returned.
Note:
The data for this information function are provided by the virtual CPU. The CPU is only able to
do this once "in parallel". If another communication instance should also accesses an
information function of the same CPU, A communication error may result.
Page 99
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The example below transfers the position of the key switch the communication partner as a
string.
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication will terminates communications and eliminate the instance. In the
same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
//read data
if (!Fehler){
WORD SchutzstufeSchluesselSchalter, ParametrierteSchutzstufe;
WORD CPUSchutzstufe;
WORD SchluesselschalterStellung=0;
//
if (!MPI6_GetLevelOfProtection(MPIHandle,
&SchutzstufeSchluesselSchalter,
&ParametrierteSchutzstufe,
&CPUSchutzstufe,
&SchluesselschalterStellung,
&Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
switch(SchluesselschalterStellung){
case 0: MessageBox(AppHandle, "Switch position:
STOP", "", MB_ICONEXCLAMATION);
break;
case 1: MessageBox(AppHandle, "Switch position:"
"RUN", "", MB_ICONEXCLAMATION);
break;
case 2: MessageBox(AppHandle, "Switch position:"
"RUN-P", "", MB_ICONEXCLAMATION);
break;
default: MessageBox(AppHandle, "Switch position:"
"unknown", "",
MB_ICONEXCLAMATION);
}//end switch
}//end else
}//end if
.
.
.
Page 100
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_GetOrderNrPlc function can be used to determine the order number of a CPU.
Note:
The data for this information function are provided by the virtual CPU. The CPU is only able to
do this once "in parallel".
If another communication instance should also accesses an information function of the same
CPU, A communication error may result.
Page 101
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The example shown below determines the order number of a CPU.
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others.
Executing the function MPI6_CloseCommunication will terminates communications and
eliminate the instance. In the same way as it was shown in the example of the MPI6_ReadByte
function.
.
.
.
//read data
if (!Fehler){
char BestellNr[100]={0};
//
if (!MPI6_GetOrderNrPlc(MPIHandle, BestellNr, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
char AusgabeStr[255]={0};
wsprintf(AusgabeStr, "Order no.: %s", BestellNr);
MessageBox(AppHandle, AusgabeStr, "", MB_ICONINFORMATION);
}//end else
}//end if
.
.
.
Page 102
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_CanPlcSendIdentData function can be used to determine whether the connected
CPU is capable of supplying identification data. For this reason, the function should be
executed before the MPI6_GetPlcIdentData function if it cannot be guaranteed that the
connected CPU supports this feature.
All the VIPA 300S and SLIO CPUs support this feature.
The Siemens S7-300® series of CPUs support this feature from firmware version 2.6.
Example
See the example on the MPI6_GetPlcIdentData function
Page 103
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
If it is doubtful that the connected CPU can supply the identification data, the
MPI6_CanPlcSendIdentData function must be executed first.
All the VIPA 300S and SLIO CPUs support this feature.
The Siemens S7-300® series of CPUs support this feature from firmware version 2.6.
Brief description
The MPI6_GetPlcIdentData function returns the unique serial number of the connected CPU as
well as the serial number of the MMC card that is available in the CPU. This enables you to
identify the connected CPU clearly. It is also possible to read the text items that may be defined
in the hardware configuration of the CPU, i.e. the CPU name, the station name, the plant
identification and the location identifier.
Page 104
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Page 105
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The example below reads the identification data from the CPU, if the CPU supports this
function. First, the CPU is checked whether it supports this function and, on a positive
response, the data is loaded from the CPU.
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance.
In the same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
bool AbfrageMoeglich=false;
if (!MPI6_CanPlcSendIdentData(MPIHandle, &AbfrageMoeglich, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
//
if (AbfrageMoeglich){
char NameDerStation[100]={0};
char NameDerCPU[100]={0};
char AnlagenKennzeichnung[100]={0};
char OrtsKennzeichnung[100]={0};
char SerienNummerCPU[100]={0};
char MMCIdentNr[100]={0};
//
if (!MPI6_GetPlcIdentData(MPIHandle, NameDerStation, NameDerCPU,
AnlagenKennzeichnung, OrtsKennzeichnung,
SerienNummerCPU, MMCIdentNr, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
char AusgabeStr[255]={0};
wsprintf(AusgabeStr, "Serial number of the CPU: %s",
SerienNummerCPU);
MessageBox(Handle, AusgabeStr, "", MB_ICONINFORMATION);
}//end else
}//end if
.
.
.
Page 106
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_GetPlcErrorLED function returns the status of the error LEDs SF, BF1 and BF2. This
can be used to determine whether a system error or a bus error is present at the CPU. The
programmer can then respond accordingly in the PC program. In spite of these errors, the CPU
can be in RUN mode if the PLC program contains the respective error OBs.
Page 107
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Note:
The data for this information function are provided by the virtual CPU. The CPU is only able to
do this once "in parallel". If another communication instance should also accesses an
information function of the same CPU, a communication error may result.
Example
The example below reads the status of the error LEDs on the CPU.
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance. In the
same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
BYTE SF_LED_Status=0;
BYTE SF_LED_BlinkFrequenz=0;
BYTE BUS1F_LED_Status=0;
BYTE BUS1F_LED_BlinkFrequenz=0;
BYTE BUS2F_LED_Status=0;
BYTE BUS2F_LED_BlinkFrequenz=0;
//
if (!MPI6_GetPlcErrorLED(MPIHandle,
&SF_LED_Status, &SF_LED_BlinkFrequenz,
&BUS1F_LED_Status, &BUS1F_LED_BlinkFrequenz,
&BUS2F_LED_Status, &BUS2F_LED_BlinkFrequenz,
&Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
char AusgabeStr[255]={0};
wsprintf(AusgabeStr, "Status der SF-LED: %s", SF_LED_Status);
MessageBox(Handle, AusgabeStr, "", MB_ICONINFORMATION);
}//end else
.
.
.
Page 108
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_IsPasswordRequired function can be used to determine whether read and/or write
operations for the CPU require a password, i.e. whether the CPU is protected by a password.
This function must be used if you are unsure whether a password must be transferred or not.
An error will be produced if you should transfer a password to the CPU when this is not actually
password protected.
Note
A password is not required for the functions ReadByte, ReadWord, ReadDword, ReadTimer,
ReadCounter, WriteByte, WriteWord, WriteDword, WriteTimer, WriteCounter, MixRead_2 and
MixWrite_2.
Note:
The data for this information function are provided by the virtual CPU. The CPU is only able to
do this once "in parallel". If another communication instance should also accesses an
information function of the same CPU, A communication error may result.
Page 109
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_SendPasswordToPlc function can be used to transfer a password to the CPU to
enable read/write operations on a password-protected CPU. If you are not sure whether the
access mode of the CPU is protected by a password, you must first check this condition with
the MPI6_IsPasswordRequired function. If you are certain that an access password is
required,
Important!
The password remains valid until the connection with the CPU is interrupted. If you are writing
several times to the password-protected CPU, this means that the password must only be
passed once. The condition is, that the communication link to the CPU is not interrupted.
Note
A password is not required for the functions ReadByte, ReadWord, ReadDword, ReadTimer,
ReadCounter, WriteByte, WriteWord, WriteDword, WriteTimer, WriteCounter, MixRead_2 and
MixWrite_2.
Page 110
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The following example checks whether the CPU has a write protection feature. After that, the
password is passed to the CPU.
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance. In the
same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
bool PasswortUebergabeNotwendig=false;
BYTE Modus='W'; //write mode
if (!MPI6_IsPasswordRequired(MPIHandle,
&PasswortUebergabeNotwendig, Modus, &Error)){
Page 111
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The function MPI6_GetCountDB can be used to determine the number of DBs in a CPU.
Page 112
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The example below determines the number of data blocks in the connected communication
partner.
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance. In the
same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
//read data
if (!Fehler){
int AnzahlDB=0;
//
if (!MPI6_GetCountDB(MPIHandle, &AnzahlDB, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
char AusgabeStr[255]={0};
wsprintf(AusgabeStr, "Number of DBs availabe: %u", AnzahlDB);
MessageBox(AppHandle, AusgabeStr, "", MB_ICONINFORMATION);
}//end else
}//end if
.
.
.
Page 113
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_GetDBInPlc function can be used to determine the numbers of the data blocks that
exist in a CPU.
Page 114
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The example below displays the number of the first DB that exists in the CPU.
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance. In the
same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
//read data
if (!Fehler){
int AnzahlDB=0;
WORD DBNummern[255]={0};
//
if (!MPI6_GetDBInPlc(MPIHandle, DBNummern, &AnzahlDB, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
char AusgabeStr[255]={0};
if (AnzahlDB>0){
wsprintf(AusgabeStr, "First available DB: %u",
DBNummern[0]);
MessageBox(AppHandle, AusgabeStr, "",
MB_ICONINFORMATION);
}//end if
else
MessageBox(AppHandle, "First available DB!", "",
MB_ICONINFORMATION);
}//end else
}//end if
.
.
.
Page 115
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_GetLengthDB function can be used to determine the length of a data block that
exists in the CPU. The length is returned in bytes.
Page 116
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Example
The example below determines the length of DB1 in the communication partner.
The example assumes that one of the initialisation functions (e.g. MPI6_OpenTcpIp) was
completed successfully. Similarly, the function MPI6_ConnectToPLC must have been
executed without errors. The action may be followed by others. Executing the function
MPI6_CloseCommunication terminates communications and eliminates the instance. In the
same way as it was shown in the example of the MPI6_ReadByte function.
.
.
.
//read data
if (!Fehler){
WORD LaengeInByte=0;
//
if (!MPI6_GetLengthDB(MPIHandle, 1, &LaengeInByte, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
char AusgabeStr[255]={0};
wsprintf(AusgabeStr, "Length of DB1: %u Byte", LaengeInByte);
MessageBox(AppHandle, AusgabeStr, "", MB_ICONINFORMATION);
}//end else
}//end if
.
.
.
Page 117
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Brief description
The MPI6_GetVersionComDrvS7 function returns the version number of the driver-DLL as a
string. This means that the version in used can easily be checked.
Note
The real number is assembled from ByteBuffer bytes [0], ByteBuffer [1], ByteBuffer [2] and
ByteBuffer [3].
Page 118
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Note
The real number is assembled from the words WordBuffer[0] and WordBuffer[1].
Note
The Int number is assembled from ByteBuffer bytes [0] and ByteBuffer [1].
Page 119
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Anmerkung
The Int number is assembled from WordBuffer[0] .
Note
The DInt number is determined from the the bytes ByteBuffer[0], ByteBuffer[1], ByteBuffer[2]
and ByteBuffer[1].
Page 120
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Note
The DInt number is assembled from the words WordBuffer[0] and WordBuffer[1].
Note
The real number is saved to the words WordBuffer[0] and WordBuffer[1].
Page 121
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Note
The real number is saved to the bytes ByteBuffer[0], ByteBuffer[1], ByteBuffer[2] and
ByteBuffer[3].
Note
The Int number is saved to bytes ByteBuffer[0] and ByteBuffer[1].
Page 122
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Note
The DInt number is saved to bytes ByteBuffer[0], ByteBuffer[1], ByteBuffer[2] and
ByteBuffer[3].
Note
The DInt number is written to the words WordBuffer[0] and WordBuffer[1].
Page 123
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Page 124
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Page 125
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
//establish connection 2
if (!MPI6_OpenRS232(&MPIHandle_2, ComNr, BaudRate,
PGMPIAdresse, HoechsteMPI,
&SchnittstelleWarSchonAllokiert,
&Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle_2, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "Kommu 2",
MB_ICONEXCLAMATION);
//close commu 1
MPI6_CloseCommunication(MPIHandle_1, &Error);
return;
}//end if
MessageBox(AppHandle, "Einleitung 2 war erfolgreich.", "",
MB_ICONINFORMATION);
Please note that different MPI handles are transferred during the initialisation. These handles
are used to specify the different communication instances.
The second call to the function "MPI6_OpenRS232" returns the parameter
"SchnittstelleWarSchonAllokiert" with the value 'true'. This is because the COM2 port was
already opened with the first initialisation of the first communication instance.
//establish communication 1
if (!MPI6_ConnectToPLC(MPIHandle_1, AGMPIAdresse_1, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle_1, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "Commu 1",
MB_ICONEXCLAMATION);
Fehler_1=true;
}//end if
else
MessageBox(AppHandle, "Commu 1 established successfully!!",
"", MB_ICONINFORMATION);
//establish communication 2
if (!MPI6_ConnectToPLC(MPIHandle_2, AGMPIAdresse_2, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle_2, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "Commu 2",
MB_ICONEXCLAMATION);
Fehler_2=true;
}//end if
else
MessageBox(AppHandle, "Commu 2 established successfully!",
"", MB_ICONINFORMATION);
Page 126
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
The accessed PLC MPI address and the MPI handles that are being used in the calls to both
"MPI6_ConnectToPLC" functions are different. For each communication instance is supposed
to access to a different CPU.
if (!Fehler_1){
WORD LaengeInByte=0;
//
if (!MPI6_GetLengthDB(MPIHandle_1, 1, &LaengeInByte, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle_1, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
char AusgabeStr[255]={0};
wsprintf(AusgabeStr, "Commu1\nlength of DB1: %u byte",
LaengeInByte);
MessageBox(AppHandle, AusgabeStr, "", MB_ICONINFORMATION);
}//end else
}//end if
if (!Fehler_2){
WORD LaengeInByte=0;
//
if (!MPI6_GetLengthDB(MPIHandle_2, 1, &LaengeInByte, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle_2, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
char AusgabeStr[255]={0};
wsprintf(AusgabeStr, "Commu2\nlength of DB1: %u bytes",
LaengeInByte);
MessageBox(AppHandle, AusgabeStr, "", MB_ICONINFORMATION);
}//end else
}//end if
This determines and returns the lengths of data blocks 1 in the respective CPU.
At this point further data may be read or written from/to the CPU. The order of read and write
operations is irrelevant.
Page 127
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
//terminate communication 1
if (!MPI6_CloseCommunication(MPIHandle_1, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle_1, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
MessageBox(AppHandle, "Communic. 1 terminated without errors.", "",
MB_ICONINFORMATION);
//terminate communication 2
if (!MPI6_CloseCommunication(MPIHandle_2, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle_2, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
MessageBox(AppHandle, "Communic. 2 terminated without errors.", "",
MB_ICONINFORMATION);
The MPI adapter that must be used for a serial connection can usually manage multiple
connections (SIEMENS adapter 4 connections). This means that for a MPI adapter a max. of 4
communication instances can access the communication partners via an MPI adapter (and thus
a serial interface).
If the connection is established via TCP/IP and a CPU with an integrated Ethernet port or an
Ethernet-CP, the communication instances are also independent of each other. The procedure
is the same as for the serial interface, with only the "MPI6_OpenTcpIp" being used instead of
"MPI6_OpenRS232".
Page 128
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
This indicates that two NetLinks were found on the network. In addition, we can see the IP
address of the NetLinks.
We will initially configure the NetLink with the IP address 172.16.130.84. In the list, select this
unit and press the button "Configure the selected NetLink". If the NetLink had the IP address
0.0.0.0, i.e. as delivered, a dialog would appear where the IP address must be specified. Then
the dialog shown below will appear:
Page 129
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Here you can enter the network settings, the PG-MPI address, etc.
In the example, the bus-profile "MPI" is selected, which is the default setting. Furthermore, the
"MPI address PG/PC" is set to the value '1'. The MPI address of the CPU is not required.
Press the button "Save modified data to NetLink". A message is displayed indicating that the
data was transferred to the NetLink. The process is started if you confirm this message with
"Yes".
A message indicates that the data was saved to the NetLink, whereupon you must turn off the
NetLink. This is accomplished by removing and reinserting the NetLink from the PG interface of
the CPU.
Now you can quit from this dialog by means of the button "Save settings and close dialog".
The same procedure must now be performed on the NetLink with the IP address
172.16.130.81. In the list, select this unit and press the button "Configure the selected NetLink".
The dialog shown above is displayed, but with the other IP address. On this dialog, you also
select "MPI" as the bus-profile. The PG-MPI-address is set to the value '3 '.
Then you press the button "Save changed data in the NetLink" and perform the steps described
above. At this point, you can leave the dialog via the button "Save settings and exit the dialog."
When you have completed these steps, you can close the configurator with the button then
"Quit program".
Additional information on commissioning a NetLink can be found in the Help function for the
software configuration.
Page 130
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Page 131
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
//establish communication 1
if (!MPI6_ConnectToPLC(MPIHandle_1, AGMPIAdresse_1, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle_1, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
Fehler_1=true;
}//end if
else {
MessageBox(AppHandle, "Communic. 1 established successfully!",
"", MB_ICONINFORMATION);
}//end else
//establish communication 2
if (!MPI6_ConnectToPLC(MPIHandle_2, AGMPIAdresse_2, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle_2, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
Fehler_2=true;
}//end if
else {
MessageBox(AppHandle, "Communic. 2 established successfully!",
"", MB_ICONINFORMATION);
}//end else
//read data
if (!Fehler_1){
WORD LaengeInByte=0;
//
if (!MPI6_GetLengthDB(MPIHandle_1, 1, &LaengeInByte, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle_1, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
char AusgabeStr[255]={0};
wsprintf(AusgabeStr, "Commu1\nlength of DB1: %u byte",
LaengeInByte);
MessageBox(AppHandle, AusgabeStr, "", MB_ICONINFORMATION);
}//end else
}//end if
Page 132
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
if (!Fehler_2){
WORD LaengeInByte=0;
//
if (!MPI6_GetLengthDB(MPIHandle_2, 1, &LaengeInByte, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle_2, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
else {
char AusgabeStr[255]={0};
wsprintf(AusgabeStr, "Kommu2\nlength of DB1: %u byte",
LaengeInByte);
MessageBox(AppHandle, AusgabeStr, "", MB_ICONINFORMATION);
}//end else
}//end if
At this point further data may be read or written from/to the CPU. The order of read and write
operations is irrelevant.
//terminate communication 1
if (!MPI6_CloseCommunication(MPIHandle_1, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle_1, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
MessageBox(AppHandle, "Communic. 1 terminated without errors.", "",
MB_ICONINFORMATION);
//terminate communication 2
if (!MPI6_CloseCommunication(MPIHandle_2, &Error)){
//display the error(s)
MPI_A_GetDLLError(MPIHandle_2, ErrorString, Error);
MessageBox(AppHandle, ErrorString, "", MB_ICONEXCLAMATION);
}//end if
MessageBox(AppHandle, "Kommunikation 2 ohne Fehler beendet.", "",
MB_ICONINFORMATION);
Page 133
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Now you can select the required NETLink Pro in the list and then press the button "Settings".
As a result of the dialog, "NETLink PRO settings" will be displayed where you can define
important communication parameters.
Page 134
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Page 135
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Besides the communication driver, the Siemens software products can continue to access the
CPU, provided that the communication resources of the CPU have not been exhausted. It is
thus possible, for example, that your application accesses a CPU with the driver (using
SIMATIC®-NET) while it is being accessed simultaneously via the Simatic®-Manager.
Page 136
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Any kind of modem may be employed on the PC. The system side supports i.e. the Siemens
Teleservice Adapter II.
The figure below shows the necessary components with their names:
On the PC the Siemens Teleservice from V6 must be installed. The PC is connected to the
telephone line via a modem. On the system side the Siemens Teleservice Adapter II may be
used. In the driver the communication path SIMATIC®-NET must be used, i.e. the initialisation
function MPI6_Open_SimaticNet must be called. The interface in the SIMATIC®-NET driver of
the TS-Adapter II that is used in the example is set to "TS Adapter".
This also enables routing.
Page 137
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
When a communication resource is used by multiple instances, e.g. when 2 CPUs are being
accessed via the COM1 port, then the functions of both instances must be executed in a single
thread in succession.
Page 138
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
11 Error messages
The following list contains the possible error numbers. One of these values may be included in
the "error" variable of a DLL function when the value returned by this function is '0 '(FALSE).
The functions MPI_A_GetDLLError, MPI_A_GetDLLErrorEng, or MPI6_GetDLLError
MPI6_GetDLLErrorEng can be used to retrieve a descriptive string (null terminated) for the
respective error.
Value Description
(dec)
54.273 The requested information is not available on the PLC!
53.825 Protection level error of the CPU!
53.409 Action not possible due to the protection level!
53.377 Select the operating mode that is necessary for this function!
53.298 The parameters passed to the PLC are faulty!
33.794 Action cannot be executed because of an incorrect status of the PLC!
33.540 Message from the module. A resource bottleneck exists!
19.718 Temporary lack of resources in the PLC. Repeat the request.
16.997 The MPI address of the PG has already been allocated on the network!
16.949 The node address of a connected PLC is too high!
16.662 The partner refuses to communicate!
1.046 PLC is not a S7-1500
1.045 PLC is not a LOGO
1.044 PLC is not a S7-1200
1.043 Failure to configure the mode for the S7-1200® family
1.030 VM area is only possible with a LOGO!®
1.029 Function is not possible with a S7-1200®
1.028 Function is not possible with a LOGO!®
1.027 Function is only possible with the MICRO version of ComDrvS7
1.026 Function is not possible with the MICRO version of ComDrvS7
1.004 Function is only possible with the Extended version of ComDrvS7
1.003 Unknown block type!
1.002 DB0 not permitted!
1.001 This feature cannot be executed in the Lite version!
1.000 Error when creating a DLL instance!
733 The given handle is not valid.
732 With at least one block, the action is not possible.
731 Error while executing compress.
729 Error, because the WLD-file already exists.
728 Failure to configure the mode for the S7-1200® family
727 Incorrect position of the mode switch or the CPU is already in the required mode.
Page 139
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Page 140
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
500 Demo limit reached. This message appears only in the demo version of the DLL
when the area of the demo version has been exceeded. In this case, please note
the additional information enclosed with demo version on the permitted operand
areas.
Obsolete from version 6.
Page 141
Documentation of SPEED7 Communication Driver V6.2X
Vipa Gesellschaft für Visualisierung und Prozessautomatisierung mbH
Page 142