Produktionsbeispiel
Sample 7 (Produktionsbeispiel)
Hier finden Sie ein Beispiel für einen Produktionsauftrag. Dabei werden Produktionsdaten wie Bauteillänge, Bauteilbreite etc. in einer Struktur zur Initialisierung ausgelesen (XML Read), die Produktion mit einer entsprechenden Stückzahl durchgeführt und der Produktionsauftrag mit einem Eintrag in der XML-Datei (Write) beendet. Um das Programm zu starten, muss zuvor das XML File an die dem Datei-Pfad entsprechende Stelle gespeichert werden und im SPS-Programm die Variable bStart auf TRUE gesetzt werden.
Das SPS-Projekt, das die Beispiele enthält, können Sie hier herunterladen: TC3_XmlSrv_Samples.zip
Variablendeklaration
PROGRAM Sample7
VAR
fbXmlSrvReadByName : FB_XmlSrvReadByName;
fbXmlSrvWriteByName : FB_XmlSrvWriteByName;
value : ST_MyProductionStruct;
state : INT := 0;
R_Edge : R_TRIG;
bStart : BOOL;
bError : BOOL;
nErrId : UDINT;
END_VAR
Struktur ST_MyProductionStruct
TYPE ST_MyProductionStruct :
STRUCT
rLength : REAL;
rWidth : REAL;
rHeight : REAL;
iQuantity : INT;
iCounter : INT;
bReady : BOOL;
stInfo : STRING;
END_STRUCT
END_TYPE
SPS-Programm
(* The production data is read, the production is carried out and, according to the
quantity and the production order, completed with an entry in the XML file.
To start the program the XML file needs to be stored in the corresponding folder (sFilePath) and the variable bStart needs to be set TRUE in the PLC program. *)
R_Edge (CLK := bStart);
IF R_Edge.Q THEN
state := 1;
END_IF
CASE state OF
0: (* idle state *)
;
1: (* init state *)
fbXmlSrvReadByName( sNetId := '',
sSymName := 'Sample7.value',
sFilePath := 'C:\Production1.xml',
sXPath := '/dataentry/MAIN.value',
bExecute := TRUE,
tTimeout := t#10s,
bError => bError,
nErrId => nErrId);
state := 2;
2:
fbXmlSrvReadByName(bExecute := FALSE);
IF NOT fbXmlSrvReadByName.bBusy AND NOT fbXmlSrvReadByName.bError THEN
state := 3;
ELSIF fbXmlSrvReadByName.bError THEN
state := 100;
END_IF
3: (* working state *)
IF value.bReady = TRUE THEN
value.stInfo := 'The order was already processed!';
(* replace your production XML file! *)
state := 4;
RETURN;
END_IF
(* call production program with
new length, width and height here *)
value.iCounter := value.iCounter + 1;
IF value.iCounter = value.iQuantity THEN
value.bReady := TRUE;
state := 4;
END_IF
4: (* documentation state *)
fbXmlSrvWriteByName( sNetId := '',
nMode := XMLSRV_SKIPMISSING,
sSymName := 'Sample7.value',
sFilePath := 'C:\Production1.xml',
sXPath := '/dataentry/MAIN.value',
bExecute := TRUE,
tTimeout := t#10s,
bError => bError,
nErrId => nErrId);
state := 5;
5:
fbXmlSrvWriteByName(bExecute := FALSE);
IF NOT fbXmlSrvWriteByName.bBusy AND NOT fbXmlSrvWriteByName.bError THEN
state := 0;
ELSIF fbXmlSrvWriteByName.bError THEN
state := 100;
END_IF
100:(* error state *)
;
XML-Datei
<dataentry>
<MAIN.value>
<rLength>65.85</rLength>
<rWidth>30</rWidth>
<rHeight>2.5</rHeight>
<iQuantity>500</iQuantity>
<iCounter>0</iCounter>
<bReady>false</bReady>
<stInfo></stInfo>
</MAIN.value>
</dataentry>
Voraussetzungen
Entwicklungsumgebung | Zielplattform | Einzubindende SPS Bibliotheken |
---|---|---|
TwinCAT v3.1 Build 4011 | PC oder CX (x86, x64, ARM) | Tc2_XmlDataSrv |