Process interfacing via an automation system (PLC, PC)
10.8 Remote client
SIMATIC MV420 / SIMATIC MV440
Operating Instructions, 04/2013, A5E02371045-06
329
Pseudocode example
C# Pseudocode XML Restore
Stream newStream;
string xmlDoc = File.Read AllText("C:\\mv400para.xml");
ASCIIEncoding encoding = new ASCIIEncoding();
// Prepare POST data
string postData =
"[REMOTEXMLUPLOADPARA]\r\nContent-Disposition: for m-data; name=\"x mlfile\"\r\nContent-Type: text/xml\r\n\r\n" +
xmlDoc + "\r\n" +
// remove next line if TCP settings shall not be imported
"[REMOTEXMLUPLOADPARA]\r\nContent-Disposition: for m-data; na me=\"importtcp\"\r\n\r\non\r\n" +
// remove next line if PROFINET settings shall not be imported
"[R EMOTEXMLUPLOADPA R A]\r\nContent-Disposition: for m-d ata; na me=\"i m p ortd p\"\r\n\r\non\r\n" +
// remote next line if security settings shall not be imported
"[REMOTEXMLUPLOADPARA]\r\nContent-Disposition: form-data; name=\"importsec\"\r\n\r\non\r\n" +
// remote next line if codes shall not be imported
"[REMOTEXMLUPLOADPARA]\r\nContent-Disposition: form-data; name=\"importcodes\"\r\n\r\non\r\n" +
"[REMOTEXMLUPLOADPARA]\r\n";
buffer = encoding.GetBytes(postData);
// Create http request
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://192.168.0.42/xml/restore.cgi");
myRequest.Method = "POST";
myRequest.ContentType = "multipart/form-data; boundary=[REMOTEXMLUPLOADPARA]\r\n";
myRequest.ContentLength = buffer.Length;
// Send the data.
newStream = myRequest.GetRequestStream();
newStream.Write(buffer, 0, buffer.Length);
try
{
// Get response
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myRequest.GetResponse();
// Get response data
int response = myHttpWebResponse.GetResponseStream().ReadByte();
if (response != -1)
{
Char value = (Char)response;
if (value.Equals('1'))
Console.WriteLine("XML restore succeeded, device is restarting...");
else if (value.Equals('2'))
Console.WriteLine("XML restore succeeded only partially, not all codes could be imported.
Device is restarting. More information via graphical user interface.");
else
Console.WriteLine("XML restore failed. More information via graphical user interface.");
}
}
catch (System.Net.WebException we)
{
Console.
WriteLine("NO PERMISSION FOR XML RESTORE!");
}