Sample 7 (Production Sample)
The production data are 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 at the corresponding place of the data path and the variable bStart needs to be set TRUE in the PLC program.
The PLC-projekt, which includes this sample, can be downloaded here.
Variable declaration
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
Structure ST_MyProductionStruct
TYPE ST_MyProductionStruct :
STRUCT
rLength : REAL;
rWidth : REAL;
rHeight : REAL;
iQuantity : INT;
iCounter : INT;
bReady : BOOL;
stInfo : STRING;
END_STRUCTEND_TYPE
PLC Program
(* The production data are 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 at the corresponding place
of the data path 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_IFCASE 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 *)
;
END_CASE
XML File
<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>
Requirements
Entwicklungsumgebung | Zielplattform | Einzubindende SPS Bibliotheken |
---|---|---|
TwinCAT v2.10.0 | PC or CX (x86, ARM) | TcXmlDataSrv.Lib |