Production example
Sample 7 (production example)
This section describes an example for a production order. Production data such as component length, component width, etc. are read in a structure for initialization (XML read), the production takes place with a corresponding quantity, and the production order is completed with an entry in the XML file (write). To start the program, the XML file first has to be saved in the location that matches the file path, and in the PLC program the variable bStart has to be set to TRUE.
The PLC project containing the examples can be downloaded from here: TC3_XmlSrv_Samples.zip
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_STRUCT
END_TYPE
PLC program
(* 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 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
Development environment |
Target system type |
PLC libraries to be linked |
---|---|---|
TwinCAT v3.1 Build 4011 |
PC or CX (x86, x64, ARM) |
Tc2_XmlDataSrv |