Datenkopplung
 
PC –
SIMATIC 
 
S7
200/300/400
 
mit 
PC-MPI/PPI-Adapter
 
 
Version 1.34
Vorausetzungen:
Betriebssystem: MS-Windows 95,98 , 2000 oder NT 4.0
Hardware: PC-MPI-Adapter an RS232 des PC
SPS: Simatic S7 300/400 mit  MPI-Schnittstelle
 
Vorausetzungen/ Einschränkung der Demoversion und
Schulversion:
Die
Demoversion läuft ca. 10 Minuten, dann wird der Fehler 4660 von den Funktionen
zurückgeliefert.
Die
Schulversion läßt nur den Zugriff auf 
Merker und DB10 zu. Ansonster liefert der Treiber den Fehler –10.
Die Demoprogramme wurden mit folgenden Programmen erzeugt:
MSVC 6.0 , Excel 2000,  Delphi 5.0 ,
Visual Basic 6.0
 
Lieferumfang:
Auf der Lieferdiskette / CD finden Sie folgende
Dateien
| 
   Hauptverzeichnis  | 
  
      | 
 
| 
   PCS7EASY.htm  | 
  
   diese Datei – Dokumentation  | 
 
| 
   Changes.Txt  | 
  
   Datei über Fehlerbeseitigung  | 
 
 
| 
   Verzeichnis ´C´  | 
  
   Dateien für C / C++  | 
 
| 
   PCS7EASY.H  | 
  
   Header-Datei für C / C++  | 
 
| 
   PCS7EASY.DLL  | 
  
   Treiber DLL  | 
 
| 
   PCS7EASY.LIB  | 
  
   Lib-Datei zum Linken mit C++  | 
 
| 
   ES7DEMO.DSP  | 
  
   Projektdatei für Visual C++ V 6.00  | 
 
| 
   ES7DEMO.C  | 
  
   Beispielprogramm in ´C´ einer Konsolenapplikation  | 
 
| 
   ES7DEMO.EXE  | 
  
   EXE-Datei der C-Demo  | 
 
 
| 
   Verzeichnis ´Delphi´  | 
  
   Dateien für Delphi  | 
 
| 
   PCS7EASY.PAS  | 
  
   Delphi-Header TPU im Quellcode  | 
 
| 
   PCS7EASY.DLL  | 
  
   Treiber DLL  | 
 
| 
   ES7DEMO.exe  | 
  
   EXE-Datei der Delphidemo  | 
 
| 
   ES7DEMO.cfg ES7DEMO.dof ES7DEMO.dpr ES7DEMO.res PCS7EASY.dcu main.dcu main.dfm main.pas OEM.BMP  | 
  
   Delphi - Projektdateien  | 
 
 
| 
   Verzeichnis VisualBasic  | 
  
   Dateien für Visual Basic  | 
 
| 
   PCS7EASY.DLL  | 
  
   Treiber DLL, Achtung:
  Für Visual Basic und Excel diese Datei ins Windowsverzeichnis kopieren !  | 
 
| 
   PCS7EASY.BAS  | 
  
   Header / Moduldatei für Visual Basic  | 
 
| 
   ES7DEMO.EXE  | 
  
   EXE-Datei der VB-Demo  | 
 
| 
   ES7DEMO.FRM  | 
  
   Visual Basic Projektdateien  | 
 
 
| 
   Verzeichnis Excel  | 
  
   Dateien für Excel  | 
 
| 
   PCS7EASY.DLL  | 
  
   Treiber DLL, Achtung:
  Für Visual Basic und Excel diese Datei ins Windowsverzeichnis kopieren !  | 
 
| 
   PCS7EASY.BAS  | 
  
   Header/Moduldatei für Visualbasic  | 
 
| 
   ES7DEMO.XLS  | 
  
   Excel-Datei mit Makro für Demo  | 
 
 
 
Funktionsweise:
PC-S7-LINK ist eine DLL für
MS-Windows (95/98/200 oder NT 4.0), welche die Anbindung eines PC an die
MPI-Schnittstelle der SIMATCI S7 von Siemens ermöglicht. Der PC wird über die
RS 232 mittels des PC-MPI-Adapters direkt mit der MPI-Schnittstelle der SPS
verbunden. Mit einfachen Funktionen kann der Anwender schnell  mit C, C++, Delphi, Visual Basic oder auch
Excel auf die Daten SPS’en im Netz zugreifen. Zur Kopplung wird nur die
MPI-Adresse der SPS benötigt. Sofort kann auf Merker. Eingänge, Ausgänge und
auch Datenbausteine der SPS lesend oder auch schreiben zugegriffen werden. 
 
Funktionsbeschreibung im Detail:
Bitte
beachten Sie: Die Funktionen werden mit der Standard RS232 -Schnittstelle
ausgeführt, was zur Folge hat, dass die Funktion erst nach Erfüllung der
Aufgabe zum Aufrufer zurückkehrt. Zum Asynchronen Betrieb rufen Sie diese
Funktionen einfach von einem separaten Thread aus auf, welcher für die
Kommunikation des System zuständig ist
Folgende
Funktionen stehen zur Verfügung:
 
Funktionen zur Initialisierung:
 
| 
   Funktion  | 
  
   Beschreibung / Zweck  | 
 
| 
   ES7Open ES7OpenEx  | 
  
   Dient
  zur Initialisierung der seriellen Schnittstelle. Es findet an dieser Stelle
  keine Prüfung statt, ob die SPS vorhanden ist Achtung:
  Beim ersten Aufruf der Lese- oder Schreibfunktionen wird, die MPI-Verbindung
  automatisch gestartet. Weiter
  hin wird geprüft, ob Baudrate und lokale MPI-Adresse mit einem eventuell
  vorausgeführten „ES7Open“ identisch sind. Um
  auf mehrere SPS im selben MPI-Bus zugreifen zu können muss für jede SPS ein
  „ES7Open“ ausgeführt  werden. Jedoch
  mit entsprechender  SPS-MPI-Adresse  | 
 
 
Aufrufparameter:
| 
   Nr.  | 
  
   Speicherbreite  | 
  
   Bezeichnung  | 
  
   Funktion  | 
 |
| 
   1  | 
  
   32-Bit-Wert
  ohne Vorzei.  | 
  
   Com  | 
  
   Nummer
  der seriellen Schnittstelle: 0 =
  COM1 1 =
  COM2 ..  | 
 |
| 
   2  | 
  
   32-Bit
  Wert ohne Vorzei.  | 
  
   SPSMPIAdr  | 
  
   MPI-Adresse
  der SPS, welche über diese Verbindung angesprochen werden soll  | 
 |
| 
   3  | 
  
   32-Bit
  Wert ohne Vorzei.  | 
  
   LocalMPIAdr  | 
  
   Die
  MPI-Adresse des PC-MPI-Kabels am PC  | 
 |
| 
   4  | 
  
   32-Bit
  Wert ohne Vorzei.  | 
  
   Baud  | 
  
   Baudrate
  mit  welcher zwischen PC und SPS
  kommuniziert werden soll. Unterstütz werden; 9600,
  (nur S7 200) 19200, oder 38400  | 
 |
| 
   5  | 
  
   32-Bit
  Wert ohne Vorzei.  | 
  
   SPSTyp  | 
  
   200
  = S7 200 (hier bitte PPI-Kabel verwenden) ungleich
  200 -> SPS ist 300 oder 400 -> MPI-Adapter verrwenden  | 
 |
| 
   6  | 
  
   32-Bit
  Wert ohne Vorzei.  | 
  
   MPIBaud nur ES7OpenEx  | 
  
   Baudrate
  auf MPI-Bus ( ab V 1.25) 0 =
  187,5 kBit/s 1 =
  19,2 kBit/s 2 =
  1,5 Mbit/s alle
  andere Werte = 187 kBit/s  | 
 |
| 
   Funktion  | 
  
   Beschreibung / Zweck  | 
  
  | 
 ||
| 
   ES7OpenMPILan  | 
  
   Verbindet
  mit dem MPI-LAN (Ethernetadapter). Ansonsten werden dieselben Operationen
  durchgeführt wie bei ES7Open. Die Funktionen unterscheiden sich jedoch im Aufruf.
  Aufrufparameter beachten! Zudem
  gibt es u.U. andere Rückgabewerte.  | 
  
  | 
 ||
 
Aufrufparameter:
| 
   Nr.  | 
  
   Speicherbreite  | 
  
   Bezeichnung  | 
  
   Funktion  | 
 
| 
   1  | 
  
   Zeiger
  auf „0“-terminierte Zeichenkette (C-String, 32-Bit Zeiger  | 
  
   IPAdr  | 
  
   IP-Adresse
  des MPI-LAN-Adapters  im Format:
  x.x.x.x. Beispiel: 192.169.0.100  | 
 
| 
   2  | 
  
   32-Bit
  Wert ohne Vorzei.  | 
  
   RxTimeout  | 
  
   Timeout
  in Millisekunden für Warten auf TCP/IP-Paket von MPI-LAN 0 bedeutet
  Standardeinstellung = 5000 ms  | 
 
| 
   3  | 
  
   32-Bit
  Wert ohne Vorzei.  | 
  
   TxTimeout  | 
  
   Timeout
  in Millisekunden für Senden eines 
  TCP/IP-Paketes an MPI-LAN 0 bedeutet Standardeinstellung = 5000 ms  | 
 
| 
   4  | 
  
   32-Bit
  Wert ohne Vorzei.  | 
  
   ConnectTimeout  | 
  
   Timeout
  in Millisekunden für Warten auf Verbindungsaufbau mit MPI-LAN  0
  bedeutet  Standardeinstellung = 5000
  ms ( 5sec.) muss
  bei Bedarf verlängert werden.  | 
 
| 
   5  | 
  
   32-Bit
  Wert ohne Vorzei.  | 
  
   SPSMPIAdr  | 
  
   MPI-Adresse
  der SPS, welche über diese Verbindung angesprochen werden soll  | 
 
| 
   6  | 
  
   32-Bit
  Wert ohne Vorzei.  | 
  
   LocalMPIAdr  | 
  
   Die
  MPI-Adresse des PC-MPI-Kabels am PC  | 
 
| 
   7  | 
  
   32-Bit
  Wert ohne Vorzei.  | 
  
   SPSTyp  | 
  
   200
  = S7 200 (hier bitte PPI-Kabel verwenden) ungleich
  200 -> SPS ist 300 oder 400 -> MPI-Adapter verrwenden  | 
 
| 
   8  | 
  
   32-Bit
  Wert ohne Vorzei.  | 
  
   MPIBaud  | 
  
   Baudrate
  auf MPI-Bus ( ab V 1.25) 0 = 187,5 kBit/s 1 = 19,2 kBit/s 2 =
  1,5 Mbit/s alle
  andere Werte = 187 kBit/s  | 
 
 
 
Rückgabewert:
Die
Funktionen liefert einen 32-Bit Wert mit Vorzeichen als Rückgabewert mit
folgender Bedeutung:
| 
   Wert  | 
  
   Fehlerbeschreibung  | 
  
   Bedeutung  | 
 
| 
   > 0  | 
  
   alles
  OK   | 
  
   Die
  Rückgabe ist die Referenznummer für diese Verbindung und muss bei allen
  anderen Funktionen als Eingangsparameter Ref verwendet werden  | 
 
| 
   -1  | 
  
   Keine
  Resourcen mehr frei.    | 
  
   Maximale
  Anzahl an verfügbaren Verbindungen erreicht.  | 
 
| 
   -2  | 
  
   Falsche
  Baudrate angegeben  | 
  
   Die
  Schnittstelle ist bereits geöffnet, jedoch wurde eine andere Baudrate
  angegeben  als bei einem frührem ES7Open.  | 
 
| 
   -3  | 
  
   Falsche
  lokale MPI-Adresse  | 
  
   Die
  Schnittstelle ist bereits geöffnet, jedoch wurde eine andere lokale
  MPI-Adresse angegeben  als bei einem
  frührem ES7Open.  | 
 
| 
   -4  | 
  
   Schnittstelle
  nicht vorhanden  | 
  
   Die
  angegebene Schnittstelle ist im System entweder nicht vorhanden oder wird
  bereits von einer anderen Anwendung verwendet.  | 
 
| 
   -5  | 
  
   allgemeiner
  Fehler  | 
  
      | 
 
| 
   -6  | 
  
   kein
  Speicher für internen IP-Pool vorhanden  | 
  
   Die
  Anzahl der maximal verfügbaren MPI-LAN – Verbindungen ist bereits erreicht.  | 
 
| 
   -7  | 
  
   IP-Adresse
  fehlerhaft  | 
  
   Das
  Format der IP-Adresse ist Fehlerhaft.  | 
 
 
 
| 
   Funktion  | 
  
   Beschreibung / Zweck  | 
 
| 
   ES7Close  | 
  
   Schließt
  die durch Ref gekennzeichnete Verbindung, Gegebenenfalls wird hier auch die
  serielle Schnittstelle geschlossen  | 
 
 
Aufrufparameter:
| 
   Nr.  | 
  
   Speicherbreite  | 
  
   Bezeichnung  | 
  
   Funktion  | 
 
| 
   1  | 
  
   32-Bit
  Wert ohne Vorzei.   | 
  
   Ref  | 
  
   Die
  Referenz der Verbindung, welche mit ES7Open generiert wurde. Dient zur
  internen Identifikation der Verbindung  | 
 
 
Rückgabewert:
Die
Funktionen liefert einen 32-Bit Wert mit Vorzeichen als Rückgabewert mit
folgender Bedeutung:
| 
   Wert  | 
  
   Fehlerbeschreibung  | 
  
   Bedeutung / Reaktion  | 
 
| 
   0  | 
  
   alles
  OK   | 
  
   Speicher
  wieder freigegeben und Verbindung, wenn vorhanden geschlossen  | 
 
| 
   -1  | 
  
   Mit
  der angegebenen Referenznummer wurde kein ES7Open durchgeführt  | 
  
   Haben
  Sie ES7Open aufgerufen ?.  | 
 
| 
   -99  | 
  
   Die
  Referenznummer ist ungültig  | 
  
   ------------------------  | 
 
 
Funktionen
zum Lesen und Schreiben
| 
   Funktion  | 
  
   Beschreibung / Zweck  | 
 
| 
   ES7RdW  | 
  
   wortweise lesen aus der SPS
  (E,A,M, DB, C )  | 
 
| 
   ES7RdB  | 
  
   byteweise lesen aus der SPS
  (E,A,M)  | 
 
| 
   ES7WrW  | 
  
   wortweise schreiben in die
  SPS (E,A,M, DB, C )  | 
 
| 
   ES7WrB  | 
  
   byteweise schreiben in die
  SPS ((E,A,M)  | 
 
| 
   ES7RdDW  | 
  
   doppelwortweise lesen aus
  der SPS (A,M,DB,T)  | 
 
| 
   ES7WrDW  | 
  
   doppelwortweise schreiben in
  die SPS (A,M,DB,T)  | 
 
| 
   ES7RdReal  | 
  
   Real (Fließpunktzahl) lesen
  (E,A,M, DB )  | 
 
| 
   ES7WrReal  | 
  
   Real (Fließpunktzahl)
  schreiben (E,A,M, DB )  | 
 
 
Aufrufparameter:
Die Lese- und Schreibfunktionen besitzen die selben
Eingangparameter:
| 
   Nr.  | 
  
   Speicherbreite  | 
  
   Bezeichnung  | 
  
   Funktion  | 
 
| 
   1  | 
  
   32-Bit
  Wert ohne Vorzei.   | 
  
   Ref  | 
  
   Die
  Referenz der Verbindung, welche mit ES7Open generiert wurde. Dient zur internen
  Identifikation der Verbindung  | 
 
| 
   2  | 
  
   32-Bit
  Wert ohne Vorzei.  | 
  
   Typ  | 
  
   Die
  Auswahl des Speicherbereichs in der SPS (DB, Eingang, Ausgang, Merker),
  welcher bearbeitet werden soll:  ´D´
  = 68 dez. steht für Datenbaustein ´E´
  = 69, dez. steht für Eingänge ´A´
  = 65 dez. steht für Ausgänge ´T’
  = 84 dez. steht für Timer (nur
  mit Doppelwortfunktionen möglich) Die
  Timer werden in der SPS mit Zeitbasis und Wert im BCD-Format gespeichert. Um
  dieses Format sofort im PC verarbeiten zu können, führt der Treiber eine
  automatische Konvertierung in Millisekunden durch. Das kleinst mögliche
  Raster ist 10 ms. Beim schreiben in die SPS wählt der Treiber automatisch
  eine passende Zeitbasis. Dabei kann es zu Rundungen kommen. Der Zeitbereich
  geht von 0 bis 9990000 ms   ´Z´
  = 90 dez. steht für Zähler (nur
  mit Wortfunktionen möglich) Auch
  die Zähler sind in der SPS BCD-Codiert abgelegt. Werden aber für den PC ins
  Binärformat konvertiert. Die Zählerwerte reichen von 0 – 999.  | 
 
| 
   3  | 
  
   32-Bit
  Wert ohne Vorzei.  | 
  
   DBNr  | 
  
   Datenbausteinnummer,
  diese wird nur beim Typ ´D´ verwendet. Ansonsten steht dort der Wert „0“  | 
 
| 
   4  | 
  
   32-Bit
  Wert ohne Vorzei.  | 
  
   Ab  | 
  
   Bei
  Wortoperationen Startwort, bei Byte-Funktionen Startbyte. Bei
  Doppelwortfunktionen StartNr (Timer) bzw. StartByte ! Bei Timer oder Zähler
  ist dies die Nummer des ersten Elements, welches gelesen werden soll.  | 
 
| 
   5  | 
  
   32-Bit
  Wert ohne Vorzei.  | 
  
   Anz  | 
  
   Anzahl
  der Einheiten (Byte, Worte, Doppelworte Real, oder Einheiten, z.B. Timer ),
  die gelesen bzw. geschrieben werden sollen.  | 
 
| 
   6  | 
  
   32-Bit
  Adresse   | 
  
   Buffer  | 
  
   Die
  Adresse auf den Quell- bzw. Zielspeicher im PC. Bei den Wortfunktionen ist
  dies ein Zeiger auf ein Feld von 16-Bit breiten Worten, bei den
  Bytefunktionen ist das eine Adresse auf ein Feld mit 8-Bit breiten Bytes. Bei
  Doppelwort Zeiger auf Long. Bei Real Zeiger auf einen Double.  | 
 
 
Funktionen
zum Bit-Lesen, Setzen und Rücksetzten
| 
   Funktion  | 
  
   Beschreibung / Zweck  | 
 
| 
   ES7RdBit  | 
  
   ein Bit lesen SPS (E,A,M, DB
  )  | 
 
| 
   ES7SetBit  | 
  
   ein Bit setzen lesen aus der
  SPS (E,A,M,DB)  | 
 
| 
   ES7ResetBit  | 
  
   ein Bit zurücksetzen in der
  SPS (E,A,M,DB )  | 
 
 
Aufrufparameter:
Die Lese- und Schreibfunktionen besitzen
die selben Eingangparameter:
| 
   Nr.  | 
  
   Speicherbreite  | 
  
   Bezeichnung  | 
  
   Funktion  | 
 
| 
   1  | 
  
   32-Bit
  Wert ohne Vorzei.   | 
  
   Ref  | 
  
   Die
  Referenz der Verbindung, welche mit IS7Open generiert wurde. Dient zur internen
  Identifikation der Verbindung  | 
 
| 
   2  | 
  
   32-Bit
  Wert ohne Vorzei.  | 
  
   Typ  | 
  
   Die
  Auswahl des Speicherbereichs in der SPS (DB, Eingang, Ausgang, Merker),
  welcher bearbeitet werden soll:  ´D´
  = 68 dez. steht für Datenbaustein ´E´
  = 69, dez. steht für Eingänge ´A´
  = 65 dez. steht für Ausgänge  | 
 
| 
   3  | 
  
   32-Bit
  Wert ohne Vorzei.  | 
  
   DBNr  | 
  
   Datenbausteinnummer,
  diese wird nur beim Typ ´D´ verwendet. Ansonsten steht dort der Wert „0“  | 
 
| 
   4  | 
  
   32-Bit
  Wert ohne Vorzei.  | 
  
   Ab  | 
  
   Byte
  Adresse z.B. M 10.0, dann steht hier 10.  | 
 
| 
   5  | 
  
   32-Bit
  Wert ohne Vorzei.  | 
  
   Bit  | 
  
   BitNr
  muss zwischen 0 und 7 liegen. z.B. bei M5.4 steht hier 4.  | 
 
| 
   6  | 
  
   32-Bit
  Adresse   | 
  
   Buffer  | 
  
   Dieser Parameter ist nur für EPS7RdBit. Die
  Adresse auf den  Zielspeicher im PC.
  Zeiger auf ein Byte. Wenn bBit gestzt ist Inhalt 1 sonst 0. Beispiel:
  lese M 6.5 BYTE W; IPS7RdBit (Ref, ´M`, 0, 6,5 & W);  | 
 
 
 
Rückgabewert:
Die
Funktionen liefert einen 32-Bit Wert mit Vorzeichen als Rückgabewert mit
folgender Bedeutung:
| 
   Wert  | 
  
   Fehlerbeschreibung  | 
  
   Reaktion  | 
 
| 
   0  | 
  
   alles
  OK   | 
  
   Daten
  auswerten  | 
 
| 
   -1  | 
  
   Zeitüberlauf,
  gewünschte SPS offensichtlich nicht oder nicht mehr vorhanden  | 
  
   Einfach
  weitere Schreib- und Leseaufträge absetzten der Treiber baut die Verbindung
  automatisch auf.   | 
 
 
| 
   Wert  | 
  
   Fehlerbeschreibung  | 
  
   Reaktion  | 
 
| 
   2  | 
  
   Baustein
  oder Datenbereich existiert nicht, 
  z.B. Zugriff auf DB, der nicht vorhanden, oder zu klein ist.                                      | 
  
   Überprüfen,
  ob der gewünschte Datenbereich in der SPS vorhanden ist.                                      | 
 
| 
   -10  | 
  
   Gewünschter
  Datentyp nicht erlaubt oder wird nicht unterstützt.                                      | 
  
   Prüfen,
  ob der Code für Datentyp in Ordnung ist. 
  Verwenden Sie die Schullizenz ? Dann sind nur Merker und DB10 zulässig
  !                                    | 
 
| 
   -5  | 
  
   Allgemeiner
  Fehler                                  | 
  
   ----------------------------  | 
 
| 
   -8  | 
  
   Speicherfehler  | 
  
   angeforderter
  Speicher im PC ist nicht verfügbar  | 
 
| 
   -9  | 
  
   Bereichsüberschreitung  | 
  
   z.B
  Timer > 9990000 ms Zähler
  > 999  | 
 
| 
   -99  | 
  
   Die
  Referenznummer ist ungültig  | 
  
   Haben
  Sie ES7Open aufgerufen ?  | 
 
| 
   4660  | 
  
   Demozeit
  ist abgelaufen  | 
  
   Vollversion
  erwerben  | 
 
!!! Beachte bei Wortoperationen !!!              
Beispiel
für Merker. Dies gilt auch für Eingänge Ausgänge und Datenworte                                  
Die
Wortadressierung in der SPS  belegt
jeweils folgende Bytes.                 
| 
   Worteadresse  | 
  
   zugeordnete Bytes  | 
 
| 
   MW0  | 
  
   MB 0
  und MB 1  | 
 
| 
   MW1  | 
  
   MB 1
  und MB 2  | 
 
| 
   MW2  | 
  
   MB 2
  und MB 3   | 
 
 
Sie
sehen, dass es bei  Verwendung von
ungeraden Wortadressen zu einer Doppelbelegung kommen kann. Deshalb
unterstützen die Wortfunktionen (ES7RdW und ES7WrW) nur den Zugriff auf gerade
Wortadressen. Dies bedeutet, dass die Start-Wort-Nr im Treiber immer mit 2
multipliziert wird. Diese Methode erlaubt zu dem ein einfaches Abbild des
SPS-Speichers in den PC. Also ein Wortschritt im PC sind 16 Bit im PC und 16
Bit in der SPS
Beispiel:
WORD
Buf[64];                 
Der
Aufruf  ES7RdW (Ref, Typ, DBNr, 0, 5, Buf) hat
folgende Wirkung:
| 
   PC  | 
  
   SPS   | 
 
| 
   Buf[0]  | 
  
   DW 0  | 
 
| 
   Buf[1]  | 
  
   DW 2
    | 
 
| 
   Buf[2]  | 
  
   DW 4
    | 
 
Sie
müssen also die Start-Wortnummer halbieren, um im PC richtig zugreifen zu
können. Dies gilt auch für 
Datenbausteine !! --> Ungerade Wortadressen der SPS können nicht
wortweise gelesen oder geschrieben werden.
Programmbeispiele:
a) Aufruf von C oder C++ aus:
                   unsigned char ByteBuffer[512];
                   unsigned short int
WordBuffer[512];
                   // Aufruf der
Bytefunktion z.B. Lese DB 10, ab DW0, 10 Worte
                   ES7RdW (Ref, ´D´, 10, 0, 10, WordBuffer);
                   // Aufruf
der Bytefunktion z.B. Lese MB 0 , 10 Bytes
                   ES7RdB (Ref, ´M´, 0, 0, 10, ByteBuffer);
Nach erfolgreichem Aufruf gilt:
| 
   PC  | 
  
   =  | 
  
   SPS  | 
 
| 
   WordBuffer[0]  | 
  
   =  | 
  
   DB10.DBW0  | 
 
| 
   WordBuffer[1]  | 
  
   =  | 
  
   DB10.DBW2  | 
 
| 
   WordBuffer[2]  | 
  
   =  | 
  
   DW10.DBW4  | 
 
| 
   ByteBuffer[0]  | 
  
   =  | 
  
   MB 0  | 
 
| 
   ByteBuffer[1]  | 
  
   =  | 
  
   MB 1  | 
 
 
 
b) Aufruf von Delphi aus:
                   ByteBuffer array [0..511] of Byte;
                   WordBuffer
array [0..511] of Word;
                   // Aufruf der
Wortfunktion z.B. Lese DB 10, ab DW0, 10 Worte
                   ES7RdW (Ref, LongWord (´D´), 10, 0, 10,
@WordBuffer[0]);
                   // Aufruf der
Bytefunktion z.B. Lese MB 0 , 10 Bytes
                   ES7RdB (Ref, ´M´, 0, 0, 10, @ByteBuffer[0]);
 
c) Aufruf von Visual
Basic aus:
                   Dim ByteBuffer (0 to 511)
as  Byte;
                   Dim WordBuffer (0..511)
as  Word;
                   // Aufruf der
Wortfunktion z.B. Lese DB 10, ab DW0, 10 Worte
                   ES7RdW (Ref, 68, 10, 0, 10, WordBuffer(0))
                   // Aufruf der
Bytefunktion z.B. Lese MB 0 , 10 Bytes
                   ES7RdB (Ref, 77, 0, 0, 10, ByteBuffer(0));
Nach erfolgreichem Aufruf gilt:
| 
   PC  | 
  
   =  | 
  
   SPS  | 
 
| 
   WordBuffer[0]  | 
  
   =  | 
  
   DB10.DBW0  | 
 
| 
   WordBuffer[1]  | 
  
   =  | 
  
   DB10.DBW2  | 
 
| 
   WordBuffer[2]  | 
  
   =  | 
  
   DW10.DBW4  | 
 
| 
   ByteBuffer[0]  | 
  
   =  | 
  
   MB 0  | 
 
| 
   ByteBuffer[1]  | 
  
   =  | 
  
   MB 1  | 
 
 
 
Funktionsdeklarationen:
C-Header:
long WINAPI
ES7Open (DWORD 
Com, DWORD SPSMPIAdr, DWORD LocalMPIAdr, DWORD Baud, DWORD SPSTyp);
 //---------------------------
long WINAPI
ES7Close (long Ref);
//---------------------------
long WINAPI
ES7RdW (long Ref, DWORD Typ, DWORD DBNr, DWORD
AbWort, DWORD WortAnz, 
     LPWORD Buffer) ;
//---------------------------
long WINAPI
ES7RdB
(long Ref, DWORD Typ, DWORD DBNr, DWORD Ab, DWORD Anz, LPBYTE Buffer);
//---------------------------
long
WINAPI
ES7WrW
(long Ref, DWORD Typ, DWORD DBNr, DWORD Ab, DWORD Anz, LPWORD Buffer);
//---------------------------
long
WINAPI
ES7WrB
(long Ref, DWORD Typ, DWORD DBNr, DWORD Ab, DWORD Anz, LPBYTE Buffer);
//---------------------------
 
long WINAPI
ES7GetMPIMembers (long Ref, LPWORD Teiln) ;
//---------------------------
long WINAPI
ES7RdBit (long Ref, 
DWORD Typ, DWORD DBNr, DWORD Byte, DWORD Bit, LPBYTE Buffer);
 
long WINAPI
ES7SetBit (long Ref, DWORD Typ, DWORD DBNr, DWORD
Byte, DWORD Bit); 
 
long WINAPI
ES7ResetBit (long Ref, DWORD Typ, DWORD DBNr, DWORD
Byte, DWORD Bit);
 
long WINAPI
ES7RdReal (long Ref, DWORD Typ, DWORD DBNr, DWORD Ab,
DWORD Anz, double *Buffer);
 
long WINAPI
ES7WrReal (long Ref, DWORD Typ, DWORD DBNr, DWORD Ab,
DWORD Anz, double *Buffer);
 
long WINAPI
ES7RdDW (long Ref, DWORD Typ, DWORD DBNr, DWORD Ab,
DWORD Anz, LPDWORD Buffer);
 
long WINAPI
ES7WrDW (long Ref, DWORD
Typ, DWORD DBNr, DWORD Ab, DWORD Anz, LPDWORD Buffer);
 
 
Visual Basic – Header:
Declare Function 
ES7Open& Lib
"PCS7EASY.dll" (ByVal Com&, ByVal SPSMPIAdr&, _
                                              ByVal LocalMPIAdr&, ByVal Baud&,
ByVal SPSTyp&)
‘---------------------------
Declare Function 
ES7Close& Lib
"PCS7EASY.dll" (ByVal Ref&)
‘---------------------------
Declare Function 
ES7RdW& Lib
"PCS7EASY.dll" (ByVal Ref&, ByVal Typ&, ByVal DBNr&,
ByVal AbWort&, _
 ByVal WortAnz&, Wert As Integer)
‘---------------------------
Declare Function 
ES7RdB& Lib
"PCS7EASY.dll" (ByVal Ref&, ByVal Typ&, ByVal DBNr&,
ByVal AbWort&, _
                                                  
ByVal WortAnz&, Wert As Byte)
‘---------------------------
Declare Function 
ES7WrW& Lib
"PCS7EASY.dll" (ByVal Ref&, ByVal Typ&, ByVal DBNr&,
ByVal AbWort&, _
                                                   
ByVal WortAnz&, Wert As Integer)
‘---------------------------
Declare Function 
ES7WrB& Lib
"PCS7EASY.dll" (ByVal Ref&, ByVal Typ&, ByVal DBNr&,
ByVal AbWort&, _
                                                 
ByVal WortAnz&, Wert As Byte)
‘---------------------------
Declare Function ES7RdBit& Lib
"PCS7EASY.DLL" (ByVal Ref&, ByVal Typ&, ByVal DBNr&,
ByVal ByteNr&, ByVal BitNr&, Wert As Byte)
‘---------------------------
 
Declare Function ES7SetBit& Lib
"PCS7EASY.DLL" (ByVal Ref&, ByVal Typ&, ByVal DBNr&,
ByVal ByteNr&, ByVal BitNr&)
‘---------------------------
 
Declare Function ES7ResetBit& Lib
"PCS7EASY.DLL" (ByVal Ref&, ByVal Typ&, ByVal DBNr&, ByVal
ByteNr&, ByVal BitNr&)
‘---------------------------
 
Declare Function ES7RdReal& Lib
"PCS7EASY.DLL" (ByVal Ref&, ByVal Typ&, ByVal DBNr&,
ByVal AbWort&, ByVal WortAnz&, Wert As Double)
‘---------------------------
 
Declare Function ES7WrReal& Lib "PCS7EASY.DLL"
(ByVal Ref&, ByVal Typ&, ByVal DBNr&, ByVal AbWort&, ByVal
WortAnz&, Wert As Double)
‘---------------------------
 
Declare Function ES7RdDW& Lib
"PCS7EASY.DLL" (ByVal Ref&, ByVal Typ&, ByVal DBNr&,
ByVal AbWort&, ByVal WortAnz&, Wert As Long)
‘---------------------------
 
Declare Function ES7WrDW& Lib
"PCS7EASY.DLL" (ByVal Ref&, ByVal Typ&, ByVal DBNr&,
ByVal AbWort&, ByVal WortAnz&, Wert As Long)
‘---------------------------
 
 
Delphi-Header:
unit PCS7EASY;
 
TYPE PWORD = 
^WORD;
TYPE PBYTE = 
^BYTE;
 
FUNCTION
ES7Open (Com :LongWord; SPSMPIAdr : LongWord;
LocalMPIAdr : LongWord; Baud : LongWord; 
SPSTyp : LongWord) : LongInt; stdcall; external
'PCS7EASY.DLL';      
(* ------------------------- *)  
FUNCTION
ES7Close (Ref : LongInt) : LongInt; stdcall; external
'PCS7EASY.DLL';      
(* ------------------------- *)
FUNCTION
ES7RdW (Ref : LongInt; Typ : Longword; DBNr :
Longword; AbWort : Longword; 
WortAnz : Longword; 
Buffer : PWORD)  : LongInt;
stdcall; external 'PCS7EASY.DLL';
(* ------------------------- *)
 
FUNCTION
ES7RdrB (Ref : LongInt; Typ : Longword;  DBNr: Longword;
          Ab :
Longword;  Anz : Longword; Buffer:
PBYTE) : LongInt; stdcall; external 'PCS7EASY.DLL';
(* -------------------------
*)
 
FUNCTION
ES7WrW (Ref : LongInt; Typ : Longword; DBNr :
Longword; AbWort : Longword; 
WortAnz : Longword; Buffer : PWORD)  : LongInt; stdcall; external 'PCS7EASY.DLL';
(* ------------------------- *)
FUNCTION
ES7WrB (Ref : LongInt; Typ : Longword;  DBNr: Longword;
         Ab :
Longword;  Anz : Longword; Buffer:
PBYTE) : LongInt; stdcall; external 'PCS7EASY.DLL';
 
FUNCTION
EPS7RdBit (Ref : LongInt; Typ : Longword;  DBNr: Longword;
          
ByteNr : Longword;  BitNr :
Longword; Buffer: PBYTE) : LongInt; stdcall; external 'PCS7EASY.DLL';
 
FUNCTION
ES7SetBit (Ref : LongInt; Typ : Longword;  DBNr: Longword;
           
ByteNr : Longword;  BitNr :
Longword) : LongInt; stdcall; external 'PCS7EASY.DLL';
 
FUNCTION
ES7ResetBit (Ref : LongInt; Typ : Longword;  DBNr: Longword;
           
ByteNr : Longword;  BitNr :
Longword) : LongInt; stdcall; external 'PCS7EASY.DLL';
FUNCTION
ES7RdDW (Ref : LongInt; Typ : Longword; DBNr :
Longword; AbWort : Longword; WortAnz : Longword;  Buffer : PDWORD)  :
LongInt; stdcall; external 'PCS7EASY.DLL';
 
FUNCTION
ES7WrDW (Ref : LongInt; Typ : Longword; DBNr :
Longword; AbWort : Longword; WortAnz : Longword;  Buffer : PDWORD)  :
LongInt; stdcall; external 'PCS7EASY.DLL';
 
FUNCTION
ES7RdReal (Ref : LongInt; Typ : Longword; DBNr :
Longword; AbWort : Longword; WortAnz : Longword;  Buffer : PDOUBLE)  :
LongInt; stdcall; external 'PCS7EASY.DLL';
 
FUNCTION
ES7WrReal (Ref : LongInt; Typ : Longword; DBNr :
Longword; AbWort : Longword; WortAnz : Longword;  Buffer : PDOUBLE)  :
LongInt; stdcall; external 'PCS7EASY.DLL';
 
 
implementation
 
begin
end.
 
Beispiel für Visual-Basic im
Excel-Demoprogramm
 
Dim Ref As Long
Dim Buf(0 To 512) As Integer
Dim Res As Long
Dim Com As Long
Dim LocalMPIAdr As Long
Dim SPSMPIAdr As Long
Dim Baud As Long
Dim SPSTyp As Long
Dim DBNr As Long
 
 
 
Private Sub CommandButton1_Click()
DBNr = Tabelle1.Cells(14, 3)
'DBNr aus Tabelle übernehmen
Com = Tabelle1.Cells(11, 3) -
1 'ComNr übernehmen
Baud = Tabelle1.Cells(11, 5)
'Baudrate übernehmen
LocalMPIAdr =
Tabelle1.Cells(12, 3) 'lokale MPI-Adresse übernehmen
SPSMPIAdr = Tabelle1.Cells(12,
5) 'SPS MPI-Adresse übernehmen
SPSTyp = Tabelle1.Cells(13, 3) 'SPS-Typ
 
Ref = ES7Open(Com, SPSMPIAdr, LocalMPIAdr, Baud,
SPSTyp)
 
If Ref >= 0 Then ' Ref muß
>= 0 sein
Res = ES7RdW(ByVal Ref, 68,
DBNr, 0, 10, Buf(0))
  If Res = 0 Then
  Tabelle1.Cells(13,
5) = "Lesen OK"
     For i = 0
To 9
      Tabelle1.Cells(i + 16, 3) = Buf(i)
    Next i
  Else
  
Tabelle1.Cells(13, 5) = Res
   If Res
= -1 Then
     Tabelle1.Cells(13, 5) = "Kabel oder SPS nicht
vorhanden"
   End
If
   If Res = -2
Then
     Tabelle1.Cells(13,
5) = "Keine Resourcen mehr frei"
   End
If
   If Res = -3
Then
     Tabelle1.Cells(13,
5) = "Referenz war nicht geöffnet"
   End
If
   If Res = 2
Then
     Tabelle1.Cells(13,
5) = "DB zu klein oder nicht vorhanden"
   End
If
   If Res = -5
Then
     Tabelle1.Cells(13,
5) = "allgemeiner Fehler"
   End
If
   If Res = -10
Then
     Tabelle1.Cells(13,
5) = "Datentyp falsch"
   End
If
   If Res = -99
Then
     Tabelle1.Cells(13,
5) = "Referenznummer falsch"
   End
If
   If Res =
4660 Then
     Tabelle1.Cells(13,
5) = "Demozeit abgelaufen"
   End
If
    For i = 0
To 9
     
Tabelle1.Cells(i + 16, 3) = "Fehler"
    Next i
  End If
  Res =
ES7Close(Ref)
 
  Ref = -1
Else
 
Tabelle1.Cells(13, 5) = Ref
  If Ref = -1
Then
    Tabelle1.Cells(13,
5) = "keine Resourcen frei!"
  End If
  If Ref = -2
Then
    Tabelle1.Cells(13,
5) = "falsche Baudrate"
  End If
  If Ref = -3
Then
    Tabelle1.Cells(13,
5) = "lokale MPI-Adr falsch"
  End If
  If Ref = -4
Then
    Tabelle1.Cells(13,
5) = "COM nicht vorhanden"
  End If
 
PC-S7-MPI-LINK
 
data link
 
PC –
SIMATIC 
 
S7
200/300/400
 
with
PC-MPI-Adapter
or 
PC-PPI-Adapter
 
 
Version 1.26
Requirement:
Operating system: MS-Windows 95,98
, 2000 or NT 4.0
Hardware: PC-MPI-Adapter on RS232 of
the PC
PLC: Simatic S7 300/400 with  MPI-Interface
 
Requirement
/ restriction of demo version and school version:
The demo version
runs about 10 minutes, then the error 4660 is returned by the functionsd.
In the version for
school  there is only reading and
writing to flags and DB 10 permitted.
The demo programs
have been generated with the following development kits:
MSVC 6.0 , Excel 2000,  Delphi 5.0 ,
Visual Basic 6.0
 
Files on disk / directory structure:
| 
   Main directory  | 
  
      | 
 
| 
   PCS7EASY.htm  | 
  
   documentation in german / english  | 
 
| 
   Changes.Txt  | 
  
   documentation about changes   | 
 
 
| 
   Directory ´C´  | 
  
   Files for C / C++  | 
 
| 
   PCS7EASY.H  | 
  
   header-filei for C / C++  | 
 
| 
   PCS7EASY.DLL  | 
  
   driver DLL  | 
 
| 
   PCS7EASY.LIB  | 
  
   lib-file for linking with C/C++  | 
 
| 
   ES7DEMO.DSP  | 
  
   project file for Visual C++ V 6.00  | 
 
| 
   ES7DEMO.C  | 
  
   example program for ´C´ of 
  console application  | 
 
| 
   ES7DEMO.EXE  | 
  
   EXE-file of C-demo  | 
 
 
| 
   Directory ´Delphi´  | 
  
   Files for Delphi  | 
 
| 
   PCS7EASY.PAS  | 
  
   Delphi-Header TPU in source code  | 
 
| 
   PCS7EASY.DLL  | 
  
   driver DLL  | 
 
| 
   ES7DEMO.exe  | 
  
   EXE-file for Delphi demo  | 
 
| 
   ES7DEMO.cfg ES7DEMO.dof ES7DEMO.dpr ES7DEMO.res PCS7EASY.dcu main.dcu main.dfm main.pas OEM.BMP  | 
  
   Delphi – project files  | 
 
 
| 
   Directory VisualBasic  | 
  
   Files for Visual Basic  | 
 
| 
   PCS7EASY.DLL  | 
  
   Driver DLL, ATTENTION: for Visual
  Basic und Excel, please copy this file to the  Windows system directory!  | 
 
| 
   PCS7EASY.BAS  | 
  
   header / modul file for Visual Basic  | 
 
| 
   ES7DEMO.EXE  | 
  
   EXE-File for VB 
  demo  | 
 
| 
   ES7DEMO.FRM  | 
  
   Visual Basic project files  | 
 
 
| 
   Directory Excel  | 
  
   files for Excel  | 
 
| 
   PCS7EASY.DLL  | 
  
   Driver DLL, ATTENTION: for Visual
  Basic und Excel, please copy this file to the  Windows system directory!  | 
 
| 
   ES7DEMO.XLS  | 
  
   Excel file with VB script code  | 
 
 
 
Mode of operation:
PC-S7-LINK
is a DLL for MS-Windows (95/98/200 or NT 4.0), which allows a PC to communicate
with a SIMATIC-S7 (200/300/400) over the PC-MPI adapter cable over the RS232
interface of the PC. 
The
way is: PC --à PC-MPI-Adapter à
MPI-BUS
With
Very simple functions the user is able to use the DLL in C, C++, Delphi, Visual
Basic, Excel or any othe program language for Windows. For the connection with the
PLC you only need the  MPI-address of
the PLC. Now you can read and write flags, inputs, outputs and also datablocks.
 
The
functions in detail:
Please consider: the functions take use of the
standard Windows-RS232-interface routines. The consequence is that the function
returns only after completion to the caller. for asynchronious operation you
have to call the DLL-functions from a separate thread, which handles the
communictaion for your application.
The following functions ar part of the DLL:
 
Functions
for initializing:
 
| 
   Function  | 
  
   Description
  / Purpose  | 
 
| 
   ES7Open ES7OpenEx  | 
  
   Is used to initialize the serial interface.
  Note: No check is made wether the PLC ist here. This check is made by the
  read/write-funtions. ES7Open ckecks wethter the baudrate and local
  MPI-address witha called „ES7Open“ before is the same. To connect with more than one PLC ind the same
  MPI-bus, ther must be called 
  „ES7Open“ for every PLC with the the MPI-address of the PLC.  | 
 
 
Calling
parameter:
| 
   No.  | 
  
   Memory
  width  | 
  
   Designation  | 
  
   Function  | 
 
| 
   1  | 
  
   32-bit value unsigned  | 
  
   Com  | 
  
   number of serial interface: 0 = COM1 1 = COM2 ..  | 
 
| 
   2  | 
  
   32-bit value unsigned  | 
  
   PLCMPIAdr  | 
  
   MPI-address of the PLC, with which should be
  communicate with this connection  | 
 
| 
   3  | 
  
   32-bit value unsigned  | 
  
   LocalMPIAdr  | 
  
   MPI-Address of the PC-MPI-adapter at the PC  | 
 
| 
   4  | 
  
   32-bit value unsigned  | 
  
   Baud  | 
  
   daudrate between PC an PC/MPI-adapter,
  supported rates: 9600 (only S7 200), 19200, 38400, 57600 and
  115200  | 
 
| 
   5  | 
  
   32-bit value unsigned  | 
  
   PLCTyp  | 
  
   200 = S7 200 (please use PPI-cable or our own
  PC/MPI-Adapter) not equal 200 -> PLC is S7 300 or S7 400   | 
 
| 
   6  | 
  
   32-bit value unsigned  | 
  
   MPIBaud only for ES7OpenEx  | 
  
   Baudrate on 
  MPI-Bus (  V 1.25) 0 = 187,5 kBit/s 1 = 19,2 kBit/s 2 = 1,5 Mbit/s other values = 187 kBit/s  | 
 
 
 
| 
   Function  | 
  
   Description
  / Purpose  | 
 
| 
   ES7OpenMPILan  | 
  
   Take connection with MPI-LAN (ethernet
  adapter) over TCP/IP. The operations are quiet the same as with function
  ‚ES7Open’. But note the calling parameters are different. An there are
  addional return values.  | 
 
 
Calling
parameter:
| 
   No.  | 
  
   Memory
  width  | 
  
   Designation  | 
  
   Function  | 
 |
| 
   1  | 
  
   pointer to a null terminated string  | 
  
   IPAddr  | 
  
   IP-address of the MPI-LAN- adapter in the
  format x.x.x.x. e.g.: 192.169.0.100  | 
 |
| 
   2  | 
  
   32-bit value unsigned.  | 
  
   RxTimeout  | 
  
   Timeout in milliseconds for waiting on the
  TCP/IP receiving packages.  0 means
  the default value of  5000 ms  | 
 |
| 
   3  | 
  
   32-bit value unsigned  | 
  
   TxTimeout  | 
  
   Timeout in milliseconds for waiting on the
  TCP/IP sedningpackages.  0 means the
  default value of  5000 ms  | 
 |
| 
   4  | 
  
   32-bit value unsigned  | 
  
   ConnectTimeout  | 
  
   Timeout in milliseconds for waiting on the
  TCP/IP connection.  0 means the
  default value of  5000 ms  | 
 |
| 
   1  | 
  
   32-bit value unsigned  | 
  
   Com  | 
  
   number of serial interface: 0 = COM1 1 = COM2 ..  | 
 |
| 
   2  | 
  
   32-bit value unsigned  | 
  
   PLCMPIAdr  | 
  
   MPI-address of the PLC, with which should be
  communicate with this connection  | 
 |
| 
   2  | 
  
   32-bit value unsigned  | 
  
   PLCMPIAdr  | 
  
   MPI-address of the PLC, with which should be
  communicate with this connection  | 
 |
| 
   3  | 
  
   32-bit value unsigned  | 
  
   LocalMPIAdr  | 
  
   MPI-Address of the PC-MPI-adapter at the PC  | 
 |
| 
   4  | 
  
   32-bit value unsigned  | 
  
   Baud  | 
  
   daudrate between PC an PC/MPI-adapter,
  supported rates: 9600 (only S7 200), 19200, 38400, 57600 and
  115200  | 
 |
| 
   5  | 
  
   32-bit value unsigned  | 
  
   PLCTyp  | 
  
   200 = S7 200 (please use PPI-cable or our own
  PC/MPI-Adapter) not equal 200 -> PLC is S7 300 or S7 400   | 
 |
| 
   6  | 
  
   32-bit value unsigned  | 
  
   MPIBaud only for ES7OpenEx  | 
  
   Baudrate on 
  MPI-Bus (  V 1.25) 0 = 187,5 kBit/s 1 = 19,2 kBit/s 2 = 1,5 Mbit/s other values = 187 kBit/s  | 
 |
Return value:
The functions return a 32-bit signed value with
following meaning:
| 
   Value  | 
  
   error description  | 
  
   meaning  | 
 
| 
   > 0  | 
  
   everything is 
  Okay   | 
  
   The return is the reference number for this
  connection and must be used with all other functions for the parameter Ref.   | 
 
| 
   -1  | 
  
   No more resources free.    | 
  
   Max. number of available connections achieves.  | 
 
| 
   -2  | 
  
   Bad baudrate indicated  | 
  
   The interface is already opened, however
  another baudrate was indicated than for an earlier call of ES7Open.  | 
 
| 
   -3  | 
  
   bad local MPI-Address indicated  | 
  
   The interface is already opened, however
  another local MPI-address was indicated than for an earlier call of ES7Open.  | 
 
| 
   -4  | 
  
   interface not available  | 
  
   The indicated interface is either missing in
  the system or is already used by another application.  | 
 
| 
   -5  | 
  
   general error  | 
  
      | 
 
| 
   -6  | 
  
    no memory for internal IP pool available  | 
  
   The maximize count of available
  MPI-LAN-connection has been reached before.  | 
 
| 
   -7  | 
  
   IP address bad  | 
  
   The format of the IP address is bad.  | 
 
 
 
| 
   Function  | 
  
   Description
  / Purpose  | 
 
| 
   ES7Close  | 
  
   The connection indicated by Ref closes, here
  also the serial interface is closed if necessary  | 
 
 
Calling
parameter:
| 
   No.  | 
  
   Memory
  width  | 
  
   Designation  | 
  
   Function  | 
 
| 
   1  | 
  
   32-bit value unsigned   | 
  
   Ref  | 
  
   The reference of the connection, which was
  generated with ES7Open. Serves the connection for the internal
  identification.  | 
 
 
Return value:
The functions return a 32-bit signed value with
following meaning:
| 
   Value  | 
  
   error
  description  | 
  
   Meaning /
  reaction  | 
 
| 
   0  | 
  
   everything is 
  Okay   | 
  
   Memory again approved and connection, if
  available closed  | 
 
| 
   -1  | 
  
   With the indicated reference number no ES7Open
  was executed  | 
  
   You called ES7Open?  | 
 
| 
   -99  | 
  
   The reference number is invalid  | 
  
   ------------------------  | 
 
 
Functions for reading and writing
| 
   Function  | 
  
   Description
  / Purpose  | 
 
| 
   ES7RdW  | 
  
   word orientated read from the PLC (I, O,F,DB, C)  | 
 
| 
   ES7RdB  | 
  
   byte orientated read from the PLC (I, O,F,DB, C)  | 
 
| 
   ES7WrW  | 
  
   word orientated write from the PLC (I, O,F,DB, C)  | 
 
| 
   ES7WrB  | 
  
   byte orientated write from the PLC (I, O,F,DB, C)  | 
 
| 
   ES7RdDW  | 
  
   double word orientated read from the PLC (T, O, F, DB)  | 
 
| 
   ES7WrDW  | 
  
   double word orientated write to PLC (T, O,F, DB)  | 
 
| 
   ES7RdReal  | 
  
   real (floating pointl) read from PLC (I, O, F, DB)  | 
 
| 
   ES7WrReal  | 
  
   real (floating point) write to PLC (I, O, F, DB)  | 
 
 
Calling
parameter:
The reading and
writeing functions possess the same input parameters:
| 
   No.  | 
  
   Memory
  width  | 
  
   Designation  | 
  
   Function  | 
 
| 
   1  | 
  
   32-bit value unsigned   | 
  
   Ref  | 
  
   The reference of the connection, which was
  generated with ES7Open. Serves the connection for the internal identification  | 
 
| 
   2  | 
  
   32-bit value unsigned  | 
  
   Typ  | 
  
   Select the memory area of the  PLC (DB, I, O, F, T, C), welcher
  bearbeitet werden soll:  ´D´ = 68 dec. means Datablock ´I´ = 73 dec, or ‘E’ = 69 dec., dec. means
  inputs ´O´ = 79 dec. or ‘A’ = 65dec. means outputs ‘C’ = 67 dec. means counter only with word functions . The counters ar
  BCD-coded in the PLC. But the driver takes the conversion in binary format
  for you. So you can user values from 0 .. 999 (binary reading and writing) ‘T’  =
  84 dec. means timer (only double word functions) The timer are stored as BCD-values in the PLC
  including the base of time. The driver converts this value to a binary format
  in milliseconds.  The
  smallest timebase is 10 ms. If writing timers the driver chooses itself the best base of time.
  Note: there could be rounding problems! Look at your PLC-guide the timer
  format. The range of the time is 0 to 9990000 ms  | 
 
| 
   3  | 
  
   32-bit value unsigned  | 
  
   DBNo  | 
  
   Datablock number, this is used only with the
  type ‘D’.  Otherwise there is the
  value 0?  | 
 
| 
   4  | 
  
   32-bit value unsigned  | 
  
   Start  | 
  
   With word operations start word, with byte
  functions start byte. With double word or floating point operations this is
  the start byte ! For timer and counter this is the number of
  the first element to be read  | 
 
| 
   5  | 
  
   32-bit value unsigned  | 
  
   Cnt  | 
  
   Number of units (byte or words, dwords or
  reals), which should be read or written.  | 
 
| 
   6  | 
  
   32-bit Address   | 
  
   Buffer  | 
  
   The Address on the source or target memory in
  the PC.  With the word functions this
  is a pointer on a field of 16-Bit broad words, with the byte functions is an
  address on a field with 8-bits spreads bytes.  | 
 
 
functions to read set and reset a
single bit (BOOLEAN) 
| 
   Name  | 
  
   function  | 
 
| 
   ES7RdBit  | 
  
   read one bit from PLC (I,O,F,DB)  | 
 
| 
   ES7SetBit  | 
  
   set one bit in the PLC (I,O,F,DB)  | 
 
| 
   ES7ResetBit  | 
  
   reset one bit in the PLC (I,O,F,DB)  | 
 
 
Calling
parameter:
The reading and
writeing functions possess the same input parameters:
| 
   No.  | 
  
   Memory
  width  | 
  
   Designation  | 
  
   Function  | 
 
| 
   1  | 
  
   32-bit value unsigned   | 
  
   Ref  | 
  
   The reference of the connection, which was
  generated with ES7Open. Serves the connection for the internal identification  | 
 
| 
   2  | 
  
   32-bit value unsigned  | 
  
   Typ  | 
  
   Select the memory area of the  PLC (DB, I, O, F), welcher bearbeitet
  werden soll:  ´D´ = 68 dec. means Datablock ´I´ = 73 dec, or ‘E’ = 69 dec., dec. means
  inputs ´O´ = 79 dec. or ‘A’ = 65dec. means outputs  | 
 
| 
   3  | 
  
   32-bit value unsigned  | 
  
   DBNo  | 
  
   Datablock number, this is used only with the
  type ‘D’.  Otherwise there is the
  value 0?  | 
 
| 
   4  | 
  
   32-bit value unsigned  | 
  
   ByteAddr  | 
  
   address of the byte  e.g. F 10.0 the value is 10 in this case.  | 
 
| 
   5  | 
  
   32-bit value unsigned  | 
  
   Bit  | 
  
   Bit number must be between 0 and 7 e.g. F 5.4
  the value is 4 in this case.  | 
 
| 
   6  | 
  
   32-Bit address Adresse   | 
  
   Buffer  | 
  
   This Parameter is onyl
  required for EPS7RdBit. This is adresse to the destination memory in the PC a pointer to a
  BYTE.  Ait this point you get the
  vylue of the Bit 1 or 0. e.g.: read 
  F 6.5 BYTE W; EPS7RdBit (Ref, ´F, 0, 6,5, & W);  | 
 
 
 
Return value:
The function supplies a 32-Bit signed value as
return value with he following meaning:
| 
   Value  | 
  
   error
  description  | 
  
   reaction  | 
 
| 
   0  | 
  
   all Okay  | 
  
   Data analyse  | 
 
| 
   -1  | 
  
   Timeout, desired PLC obviously not or no
  longer available  | 
  
   Simply further writing and reading jobs issued
  the driver build the connection automatically on.   | 
 
 
| 
   Value  | 
  
   error
  description  | 
  
   reaction  | 
 
| 
   2  | 
  
   Data block or data area does not exist, e.g.
  to access to "DB", which are too small or missing.  | 
  
   check if the requested data exists in PLC                                    | 
 
| 
   -10  | 
  
   Desired data type illegally or is not
  supported.                                  
    | 
  
   check if code for datatype is okay. Are you yousing the school version of the DLL
  ? You can only use Flag or DB 10.                                      | 
 
| 
   -5  | 
  
   General error                                  | 
  
   ----------------------------  | 
 
| 
   -8  | 
  
   memory allocation error  | 
  
   requested memory in PC is not available  | 
 
| 
   -9  | 
  
   data range 
  error  | 
  
   e.g. 
  Timer > 9990000 ms Counter > 999  | 
 
| 
   -99  | 
  
   With the indicated reference number no ES7Open
  was executed  | 
  
   You called ES7Open?  | 
 
| 
   4660  | 
  
   demo time is over  | 
  
   please order the full version  | 
 
 
Consider with word operations!!!
Example for flags. This applies also to inputs
of outputs and data block items the word
addressing into the PLC occupied the following
in each case bytes.                 
| 
   word
  address  | 
  
   assigned
  bytes  | 
 
| 
   FW0  | 
  
   FB 0
  und FB 1  | 
 
| 
   FW1  | 
  
   FB 1
  und FB 2  | 
 
| 
   FW2  | 
  
   FB 2
  und FB 3   | 
 
You see that it can come when using odd word addresses to a duplicate.
Therefore the word functions (ES7RdW and ES7WrW)
supports only the
access to even word addresses. This means that
the start word number in the
driver is always multiplied by 2.  This method allaows to a simple image of
the PLC memory into the PC thus a word step in
the PC 16 bits in the
PC and 16 bits are permitted in the PLC.
Example:
WORD Buf[64];                 
The call 
ES7RdW (Ref, Typ,
DBNr, 0, 5, Buf) has the following effect:
| 
   PC  | 
  
   PLC   | 
 
| 
   Buf[0]  | 
  
   DW 0  | 
 
| 
   Buf[1]  | 
  
   DW 2   | 
 
| 
   Buf[2]  | 
  
   DW 4   | 
 
You must bisect thus the start word number, in
order to be able to
access in the PC correctly.  This applies also to data blocks !!  --> odd word addresses  of the PLC cannot be read or written word
orientated.
program
examles:
a) call from
C oor C++ :
                   unsigned char
ByteBuffer[512];
                   unsigned short int
WordBuffer[512];
                   // call of the word function e.g. read DB 10, from
DW0, 10 words
                   ES7RdW (Ref, ´D´, 10, 0, 10, WordBuffer);
                   // call of
the byte function e.g. read MB , from MB0, 10 bytes
                   ES7RdB (Ref, ´M´, 0, 0, 10, ByteBuffer);
After the successfully
call it applies:
| 
   PC  | 
  
   =  | 
  
   PLC  | 
 
| 
   WordBuffer[0]  | 
  
   =  | 
  
   DB10.DBW0  | 
 
| 
   WordBuffer[1]  | 
  
   =  | 
  
   DB10.DBW2  | 
 
| 
   WordBuffer[2]  | 
  
   =  | 
  
   DW10.DBW4  | 
 
| 
   ByteBuffer[0]  | 
  
   =  | 
  
   MB 0  | 
 
| 
   ByteBuffer[1]  | 
  
   =  | 
  
   MB 1  | 
 
 
b) call form
Delphi:
                   ByteBuffer array
[0..511] of Byte;
                   WordBuffer array [0..511] of
Word;
                   // call of the word function e.g. read DB 10, from
DW0, 10 words
                   ES7RdW (Ref, LongWord (´D´), 10, 0, 10,
@WordBuffer[0]);
                   // call of the byte
function e.g. read MB , from MB0, 10 bytes
                   ES7RdB (Ref, ´M´, 0, 0, 10, @ByteBuffer[0]);
c) call from Visual
Basic:
                   Dim ByteBuffer (0 to 511)
as  Byte;
                   Dim WordBuffer (0..511)
as  Word;
                   // call of the word function e.g. read DB 10, from
DW0, 10 words
                   ES7RdW (Ref, 68, 10, 0, 10, WordBuffer(0))
                   // call of the byte
function e.g. read MB , from MB0, 10 bytes
                   ES7RdB (Ref, 77, 0, 0, 10, ByteBuffer(0));
After the successfully
call it applies:
| 
   PC  | 
  
   =  | 
  
   PLC  | 
 
| 
   WordBuffer[0]  | 
  
   =  | 
  
   DB10.DBW0  | 
 
| 
   WordBuffer[1]  | 
  
   =  | 
  
   DB10.DBW2  | 
 
| 
   WordBuffer[2]  | 
  
   =  | 
  
   DW10.DBW4  | 
 
| 
   ByteBuffer[0]  | 
  
   =  | 
  
   MB 0  | 
 
| 
   ByteBuffer[1]  | 
  
   =  | 
  
   MB 1  | 
 
 
 
Function
declarations:
C-Header:
long WINAPI
ES7Open (DWORD 
Com, DWORD SPSMPIAdr, DWORD LocalMPIAdr, DWORD Baud, DWORD SPSTyp);
//---------------------------
 
long WINAPI
ES7OpenEx (DWORD  Com, DWORD SPSMPIAdr, DWORD LocalMPIAdr, DWORD Baud, DWORD
SPSTyp, DWORD MPIBaud);
 
 //---------------------------
long WINAPI
ES7Close (long Ref);
//---------------------------
long WINAPI
ES7RdW (long Ref, DWORD Typ, DWORD DBNr, DWORD
AbWort, DWORD WortAnz, 
     LPWORD Buffer) ;
//---------------------------
long WINAPI
ES7RdB (long Ref, DWORD Typ, DWORD DBNr, DWORD
Ab, DWORD Anz, LPBYTE Buffer);
//---------------------------
long WINAPI
ES7WrW (long Ref, DWORD Typ, DWORD DBNr, DWORD
Ab, DWORD Anz, LPWORD Buffer);
//---------------------------
long WINAPI
ES7WrB (long Ref, DWORD Typ, DWORD DBNr, DWORD
Ab, DWORD Anz, LPBYTE Buffer);
//---------------------------
 
long WINAPI
ES7GetMPIMembers (long Ref, LPWORD Teiln) ;
//---------------------------
long WINAPI
ES7RdBit (long Ref, 
DWORD Typ, DWORD DBNr, DWORD Byte, DWORD Bit, LPBYTE Buffer);
 
long WINAPI
ES7SetBit (long Ref, DWORD Typ, DWORD DBNr, DWORD
Byte, DWORD Bit); 
 
long WINAPI
ES7ResetBit (long Ref, DWORD Typ, DWORD DBNr, DWORD
Byte, DWORD Bit);
 
long WINAPI
ES7RdReal (long Ref, DWORD Typ, DWORD DBNr, DWORD Ab,
DWORD Anz, double *Buffer);
 
long WINAPI
ES7WrReal (long Ref, DWORD Typ, DWORD DBNr, DWORD Ab,
DWORD Anz, double *Buffer);
 
long WINAPI
ES7RdDW (long Ref, DWORD Typ, DWORD DBNr, DWORD Ab,
DWORD Anz, LPDWORD Buffer);
 
long WINAPI
ES7WrDW (long Ref, DWORD Typ, DWORD DBNr, DWORD Ab,
DWORD Anz, LPDWORD Buffer);
 
 
Visual Basic – Header:
Declare Function 
ES7Open& Lib
"PCS7EASY.dll" (ByVal Com&, ByVal SPSMPIAdr&, _
                                              ByVal LocalMPIAdr&, ByVal Baud&,
ByVal SPSTyp&)
‘---------------------------
Declare Function 
ES7OpenEx& Lib
"PCS7EASY.dll" (ByVal Com&, ByVal SPSMPIAdr&, _
                                              ByVal LocalMPIAdr&, ByVal Baud&,
ByVal SPSTyp&, _
                                              ByVal MPIBaud&)
‘---------------------------
Declare Function 
ES7Close& Lib
"PCS7EASY.dll" (ByVal Ref&)
‘---------------------------
Declare Function 
ES7RdW& Lib
"PCS7EASY.dll" (ByVal Ref&, ByVal Typ&, ByVal DBNr&,
ByVal AbWort&, _
 ByVal WortAnz&, Wert As Integer)
‘---------------------------
Declare Function 
ES7RdB& Lib
"PCS7EASY.dll" (ByVal Ref&, ByVal Typ&, ByVal DBNr&,
ByVal AbWort&, _
                                                  
ByVal WortAnz&, Wert As Byte)
‘---------------------------
Declare Function 
ES7WrW& Lib
"PCS7EASY.dll" (ByVal Ref&, ByVal Typ&, ByVal DBNr&,
ByVal AbWort&, _
                                                   
ByVal WortAnz&, Wert As Integer)
‘---------------------------
Declare Function 
ES7WrB& Lib
"PCS7EASY.dll" (ByVal Ref&, ByVal Typ&, ByVal DBNr&,
ByVal AbWort&, _
                                                 
ByVal WortAnz&, Wert As Byte)
‘---------------------------
Declare Function ES7RdBit& Lib
"PCS7EASY.DLL" (ByVal Ref&, ByVal Typ&, ByVal DBNr&,
ByVal ByteNr&, ByVal BitNr&, Wert As Byte)
‘---------------------------
 
Declare Function ES7SetBit& Lib
"PCS7EASY.DLL" (ByVal Ref&, ByVal Typ&, ByVal DBNr&,
ByVal ByteNr&, ByVal BitNr&)
‘---------------------------
 
Declare Function ES7ResetBit& Lib
"PCS7EASY.DLL" (ByVal Ref&, ByVal Typ&, ByVal DBNr&,
ByVal ByteNr&, ByVal BitNr&)
‘---------------------------
 
Declare Function ES7RdReal& Lib
"PCS7EASY.DLL" (ByVal Ref&, ByVal Typ&, ByVal DBNr&,
ByVal AbWort&, ByVal WortAnz&, Wert As Double)
‘---------------------------
 
Declare Function ES7WrReal& Lib
"PCS7EASY.DLL" (ByVal Ref&, ByVal Typ&, ByVal DBNr&,
ByVal AbWort&, ByVal WortAnz&, Wert As Double)
‘---------------------------
 
Declare Function ES7RdDW& Lib
"PCS7EASY.DLL" (ByVal Ref&, ByVal Typ&, ByVal DBNr&,
ByVal AbWort&, ByVal WortAnz&, Wert As Long)
‘---------------------------
 
Declare Function ES7WrDW& Lib
"PCS7EASY.DLL" (ByVal Ref&, ByVal Typ&, ByVal DBNr&,
ByVal AbWort&, ByVal WortAnz&, Wert As Long)
‘---------------------------
 
 
Delphi-Header:
unit PCS7EASY;
 
TYPE PWORD = 
^WORD;
TYPE PBYTE = 
^BYTE;
 
FUNCTION
ES7Open (Com :LongWord; SPSMPIAdr : LongWord;
LocalMPIAdr : LongWord; Baud : LongWord; 
SPSTyp : LongWord) : LongInt; stdcall; external
'PCS7EASY.DLL';      
(* ------------------------- *)  
FUNCTION
ES7OpenEx (Com :LongWord; SPSMPIAdr : LongWord;
LocalMPIAdr : LongWord; Baud : LongWord; 
SPSTyp : LongWord; MPIBaud : LongWord) : LongInt;
stdcall; external 'PCS7EASY.DLL';      
(* ------------------------- *)  
 
FUNCTION
ES7Close (Ref : LongInt) : LongInt; stdcall; external
'PCS7EASY.DLL';      
(* ------------------------- *)
FUNCTION
ES7RdW (Ref : LongInt; Typ : Longword; DBNr :
Longword; AbWort : Longword; 
WortAnz : Longword; 
Buffer : PWORD)  : LongInt;
stdcall; external 'PCS7EASY.DLL';
(* ------------------------- *)
 
FUNCTION
ES7RdrB (Ref : LongInt; Typ : Longword;  DBNr: Longword;
          Ab :
Longword;  Anz : Longword; Buffer:
PBYTE) : LongInt; stdcall; external 'PCS7EASY.DLL';
(* ------------------------- *)
 
FUNCTION
ES7WrW (Ref : LongInt; Typ : Longword; DBNr : Longword;
AbWort : Longword; 
WortAnz : Longword; Buffer : PWORD)  : LongInt; stdcall; external 'PCS7EASY.DLL';
(* ------------------------- *)
FUNCTION
ES7WrB (Ref : LongInt; Typ : Longword;  DBNr: Longword;
         Ab :
Longword;  Anz : Longword; Buffer:
PBYTE) : LongInt; stdcall; external 'PCS7EASY.DLL';
 
FUNCTION
EPS7RdBit (Ref : LongInt; Typ : Longword;  DBNr: Longword;
          
ByteNr : Longword;  BitNr :
Longword; Buffer: PBYTE) : LongInt; stdcall; external 'PCS7EASY.DLL';
 
FUNCTION
ES7SetBit (Ref : LongInt; Typ : Longword;  DBNr: Longword;
           
ByteNr : Longword;  BitNr :
Longword) : LongInt; stdcall; external 'PCS7EASY.DLL';
 
FUNCTION
ES7ResetBit (Ref : LongInt; Typ : Longword;  DBNr: Longword;
           
ByteNr : Longword;  BitNr : Longword)
: LongInt; stdcall; external 'PCS7EASY.DLL';
FUNCTION
ES7RdDW (Ref : LongInt; Typ : Longword; DBNr :
Longword; AbWort : Longword; WortAnz : Longword;  Buffer : PDWORD)  :
LongInt; stdcall; external 'PCS7EASY.DLL';
 
FUNCTION
ES7WrDW (Ref : LongInt; Typ : Longword; DBNr :
Longword; AbWort : Longword; WortAnz : Longword;  Buffer : PDWORD)  :
LongInt; stdcall; external 'PCS7EASY.DLL';
 
FUNCTION
ES7RdReal (Ref : LongInt; Typ : Longword; DBNr :
Longword; AbWort : Longword; WortAnz : Longword;  Buffer : PDOUBLE)  :
LongInt; stdcall; external 'PCS7EASY.DLL';
 
FUNCTION
ES7WrReal (Ref : LongInt; Typ : Longword; DBNr :
Longword; AbWort : Longword; WortAnz : Longword;  Buffer : PDOUBLE)  :
LongInt; stdcall; external 'PCS7EASY.DLL';
 
 
implementation
 
begin
end.