PHP + Siemens PLC

Zuviel Werbung?
-> Hier kostenlos registrieren
Hello,

Thank for you website :p

I need to connect s7plc.php to my siemens S7 1200 and it currently does not work :x

The solution that works is this one :

Code:
<?php$host    = "192.168.1.201";
$port    = 2000;
$messages = "Hello Server";


// create socket
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
// connect to server
$result = socket_connect($socket, $host, $port) or die("Could not connect to server\n");  
// send string to server
socket_write($socket, $message, strlen($message)) or die("Could not send data to server\n");
// get server response
$result = socket_read ($socket, 1024) or die("Could not read server response\n");
echo "Reply From Server  :".$result;
// close socket
socket_close($socket);
?>

With this code how to write and read just one value in a DB ?

DBNAME = Data_rcv [DB11]
LINE 2 = R_No
DATA TYPE = Char
VALUE = A

Thank you and sorry I speak french in belgium :p
 
Hi,

if you want to use this php class to connect to a S7-1200, you have to set in the connection parameters rack=0 and slot=1.
In the hardware configuration of the 1200 you have to enable put/get communication if you are using a 1200 with a new Firmware (V4). And you can only get access to not-optimized datablocks.
 
Zuviel Werbung?
-> Hier kostenlos registrieren
Is on the S7-1200 a TCP-Server (passive TCP-Connection) running on port 2000?

If you want connect for S7-Protokoll (put/get) then I guess you have to connect to port 102.

Harald
 
Hallo Thomas_v2.1,

Das ist ja echt eine geile Klasse, Respekt. Habe da aber mal eine Frage, ist es möglich auch einen String zu übertragen, in der Klasse sind nur Typen bis 4 Byte angegeben.

Gruß Marvin
 
Prinzipiell ja, du musst dir nur eine eigene Funktion schreiben welche das Längenbyte im S7-Stringkopf ausliest, und die Anzahl an Bytes dann als String interpretiert.

Problematisch könnten nur lange Strings werden, z.B. welche mit 254 Zeichen (256 Bytes gesamt). Mit dieser php-Klasse aus diesem Thread kannst du nur Blockgrößen bis zu einer maximalen Größe lesen, und dieser hängt von der CPU ab. Bei einer 300er CPU mit einer PDU von 240 Bytes, kannst du höchstens 222 Bytes am Stück lesen. Das Aufteilen auf mehrere Anfragen und zusammenfügen der Antworten musst du darum selber machen.

Beispielsweise hast du einen String[254] in DB1 ab Adresse 0.0.
Abfrage 1 liest 222 Bytes ab DB1.DBB0, Abfrage 2 liest die restlichen 34 (256-222) ab DB1.DBB222.
 
Zuviel Werbung?
-> Hier kostenlos registrieren
Klingt ja schon mal super, gibt es irgendwo eine freie Doku wie so ein Telegramm auszusehen hat? Hast DU was dagegen, wenn ich ein wenig an Deinen Script weiterbaue? Würde gerne die Konfigs aus einer MYSql DB holen und nicht aus den cdv Dateien.

Gruß Marvin
 
Die eigentliche Kommunikation steckt in der s7plc.php. Wenn du mit ReadBytes einen Bereich liest, kannst du mit dem ergebnis[0] auf das erste Byte zugreifen usw. Du musst dich überhaupt nicht darum kümmern wie die Kommunikation funktioniert. Du musst nur wissen wie ein String in der S7 abgelegt wird, und wie du in php dir einen php-String aus einzelnen Bytes zusammensetzen kannst.
Du kannst mit der Klasse machen was du willst, ich verwende die sowieso nicht.
 
Zuviel Werbung?
-> Hier kostenlos registrieren
Hi,
I'm trying to toggle an ausgang (in stead of toggle a datablock bit, which works perfectly btw :)) for at least one cycle.
In my plc I have 48 ausgangen (Q0.0 to Q5.7)

for example I want to change the value of Q0.4

I have added a line to config_blocks.csv: "Plc1Ausgangen;Plc1;A;0,0;6" (Blockname;Station;Bereich;DbNummer;Startadresse;Anzahl)
and to config_tags.csv: "LichtKeukenEiland;Plc1Ausgangen;bool;0;4" (Tagname;Blockname;Datentyp;Byteoffset;Bitoffset)
(without the quotes off course)

What am I doing wrong here?
 
In general it works to write an output (tested).

This line should have a semicolon as separator, and not a comma
From:
"Plc1Ausgangen;Plc1;A;0,0;6"
to:
"Plc1Ausgangen;Plc1;A;0;0;6"


Have you checked the cross reference to A0.4 / AB0 / AW0 / AD0 if they are accessed from anywhere else in your program?
What type of CPU are you using, and what type of output card is at the first 6 output bytes?

In my opinion it's not a good style to write directly to outputs from a visualisation. I would write to a defined datablock, and then assign the datablock bits to the output bits.
 
You are right I didn't notice that comma :rolleyes:
What's the problem with straight away setting the outputs? Working with a datablock seems one step extra for the same result?
 
Zuviel Werbung?
-> Hier kostenlos registrieren
What's the problem with straight away setting the outputs? Working with a datablock seems one step extra for the same result?
problems are:
- you cannot find the accesses to the outputs in reference list. Another programmer will wonder, from where in plc program or network the control commands for the outputs come... and after he found, then he want kill you...
- you cannot watch online the switch conditions
- the process cannot switch (-off) an plc output, if the HMI is not online
- for new arrangement of outputs must be changed the runtime of all HMIs
- ...

Harald
 
...
- if your plc restarts due to a power failure or something else, then your lights will start off, as all outputs are set to false. If you are using a datablock or remanent merker, then they'll keep their last state.
 
runs perfectly on openwrt router with php 5.6 (when packages php5, php5-cgi, php5-mod-json, php5-mod-socktets, php5-mod-session & zoneinfo-europe are installed)

php 7 doesn't seem to work here (openwrt and easyphp on windows) but it could be my mistake i don't know much of php
 
Zuletzt bearbeitet:
Hallo
Habe mit der s7plc.php Klasse (Danke an Thomas) ein bisschen rum gespielt. Bits lesen geht schon mal. Ich habe in meiner Logo8 einen Timer den ich gern auslesen möchte.
Wie komme ich aber an diesen ran? Wie finde ich seine Adresse?
 
Zuviel Werbung?
-> Hier kostenlos registrieren
Hi,
mit der Logo kenne ich mich nicht aus, aber hier im Forum wurde mal erwähnt, dass es in der Online-Hilfe eine Art Übersetzungstabelle gibt. Wenn du dort Infos zu WinCC flexible findest kannst du diese auch verwenden.
In meiner php Klasse ist aber bisher kein Zugriff auf den VW-Bereich einer 200 realisiert, falls du eine solche Info findet solltest.
Das müsste dann ggf. ergänzt werden.
 
Das Lesen von Timer und Counter zumindest aus einer S7 sollte aber vorhanden sein und hoffentlich auch funktionieren, kann mir das weil unterwegs grad nicht näher ansehen. Ob das bei der Logo auch so funktioniert kann ich nicht sagen.
Du könntest mal bei libnodave oder snap7 nach Informationen zur Logo suchen, ob dort schonmal jemand auf die Bereiche zugegriffen hat, bzw. damit erstmal testen.
 
Zurück
Oben