Sei sulla pagina 1di 3

using System;

using System.Collections.Generic;
using Siemens.Automation.AutomationTool.API;

namespace UploadDataLog
{
class Program
{
static void Main(string[] args)
{
Network myNetwork = new Network();
List<String> interfaces = new List<String>();
Result resultCallAPI = myNetwork.QueryNetworkInterfaceCards(out
interfaces);
if (resultCallAPI.Succeeded)
{
// listing all network interface cards
Console.WriteLine("
------------------------------------------------------------------");
Console.WriteLine(" " + interfaces.Count.ToString() + " network
cards are found:");
for (Int32 index = 0; index < interfaces.Count; index++)
{
String strInterfaceName = interfaces[index];
Console.WriteLine(" card[" + index + "] = " +
strInterfaceName);
}
Console.WriteLine("
------------------------------------------------------------------");
}
if (!((args.Length == 4) || (args.Length == 5)))
{
Console.WriteLine(" WRONG NUMBER OF ARGUMENTS !!!");
return;
}
Console.WriteLine(" arguments = " + args.Length.ToString());
int x = Int32.Parse(args[0]);
if ((x >= 0) && (x <= interfaces.Count - 1))
{
resultCallAPI =
myNetwork.SetCurrentNetworkInterface(interfaces[x]);
if (resultCallAPI.Succeeded)
{
// setting the network card (argument0)
IProfinetDeviceCollection devices; // definition "devices"
Console.WriteLine(" scan network card " + x.ToString());
resultCallAPI = myNetwork.ScanNetworkDevices(out devices); //
scan network
if (resultCallAPI.Succeeded)
{
// convert ip string to Uint
System.Net.IPAddress ip =
System.Net.IPAddress.Parse(args[1]);
byte[] bytes = ip.GetAddressBytes();
Array.Reverse(bytes);
uint encodedIp = BitConverter.ToUInt32(bytes, 0); //
encodedIP from argument1
Console.WriteLine(" search IP address " + ip.ToString());
IProfinetDevice dev = devices.FindDeviceByIP(encodedIp);
if (dev != null)
{
Console.WriteLine(" refresh status");
EncryptedString eStringPWD = new EncryptedString("");
if (args.Length == 5)
eStringPWD = new EncryptedString(args[4]);
resultCallAPI = dev.RefreshStatus(eStringPWD);
if (resultCallAPI.Succeeded)
{
// check if data log files are available on memory
card
ICPU devAsCpu = dev as ICPU; // definition
"devAsCpu"
Console.WriteLine(" check if device is CPU");
if (devAsCpu != null)
{
Console.WriteLine(" check if remote access on
data logs is allowed");
if (devAsCpu.RemoteDataLogsAllowed ==

Siemens.Automation.AutomationTool.API.FeatureSupport.RemoteDataLogsAllowed)
{
Console.WriteLine(" check if data logs
exist");
if (devAsCpu.DataLogFolder.Exists)
{
// searching for data log files
foreach (IRemoteFile datalog in
devAsCpu.DataLogFolder.Files) // definition "datalog"
{
Console.WriteLine(" check data log
name '" + datalog.Name + "'");
if ((args[2] == "ALL") ||
(datalog.Name == args[2]))
{
// copy all data logs if
argument2 = 'ALL' or
// check the given data log
name '*.csv'
Console.WriteLine(" upload
data log to destination " + args[3].ToString());
resultCallAPI =
devAsCpu.UploadDataLog(eStringPWD,
datalog.Name,
args[3]);
if (resultCallAPI.Failed)
{
Console.WriteLine("
ErrorCode = " + resultCallAPI.Code.ToString());
Console.WriteLine("
ErrorDescription = " + resultCallAPI.ErrorDescription.ToString());
}
if (datalog.Name == args[2])
break;
}
else
Console.WriteLine(" WRONG FILE
NAME !!!");
}
}
}
}
}
else
{
Console.WriteLine(" NOT Succeeded !!!");
Console.WriteLine(" ErrorCode = " +
resultCallAPI.Code.ToString());
Console.WriteLine(" ErrorDescription = " +
resultCallAPI.ErrorDescription.ToString());
}
}
else
Console.WriteLine(" IP ADDRESS NOT FOUND !!!");
}
if (resultCallAPI.Failed)
{
Console.WriteLine(" NOT Succeeded !!!");
Console.WriteLine(" ErrorCode = " +
resultCallAPI.Code.ToString());
Console.WriteLine(" ErrorDescription = " +
resultCallAPI.ErrorDescription.ToString());
}
}
}
else
Console.WriteLine(" INTERFACE CARD NUMBER DOESN'T EXIST !!!");
Console.WriteLine("
------------------------------------------------------------------");
}
}
}

Potrebbero piacerti anche