class1_malo_koristeno

class 1 s useless connectionbuilderom i s iocontrolerom
 avatar
unknown
csharp
2 years ago
6.0 kB
1
Indexable
using Siemens.Engineering;
using Siemens.Engineering.Hmi.Communication;
using Siemens.Engineering.HW;
using Siemens.Engineering.SW;
using Siemens.Engineering.Connection;
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Siemens.Engineering.HW.Features;

namespace TIAManagement
{
    public class ConnectionBuilder
    {
        public string name;
        public ConnectionType connectionType;
        public Device sourceDevice;
        public int sourcePort;
        public Device destinationDevice;
        public int destinationPort;
        public static Connection connection;


        public static NetworkInterface networkInterface;
        public string connectionName;


        //public ConnectionBuilder Name( name)
        //{
        //    this.name = name;
        //    return name;
        //}

        public ConnectionBuilder WithConnectionType(ConnectionType connectionType)
        {
            this.connectionType = connectionType;
            return this;
        }

        public ConnectionBuilder WithSource(Device sourceDevice, int sourcePort)
        {
            this.sourceDevice = sourceDevice;
            this.sourcePort = sourcePort;
            return this;
        }

        public ConnectionBuilder WithDestination(Device destinationDevice, int destinationPort)
        {
            this.destinationDevice = destinationDevice;
            this.destinationPort = destinationPort;
            return this;
        }

        //public Connection Build()
        //{
        //    .WithConnectionType(ConnectionType.ProfinetIO)
        //    .WithSource(sourceDevice, sourcePort) // connect port 1 of device1
        //    .WithDestination(destinationDevice, destinationPort) // connect port 2 of device2
        //    .Build();

        //    networkInterface.SetAttribute("Connection", connection);       // umjesto "connectionName probat "Connection"
        //    return null;
        //}

    }

}
public enum ConnectionType
{
    ProfinetIO,
    IsoOnTcp,
    DeviceNet,
    Profibus, 

}
public class Controller
{
    public struct _Device
    {
        public string name;
        public string identifier;
        public string IP;
        public _Device(string _name, string _identifier, string _Ip)
        {
            name = _name;
            identifier = _identifier;
            IP = _Ip;
        }

    }
    public struct _IoCard
    {
        public string IoName;
        public string IoPosition;
        public string IoIdentifier;
        public _IoCard(string _name, string _position, string _identifier)
        {
            IoName = _name;
            IoPosition = _position;
            IoIdentifier = _identifier;
        }
        

    }
    public static IList<Tuple<_Device, IList<_IoCard>>> Devices;
    public static void ReadController(string path)
    {
        Devices = new List<Tuple<_Device, IList<_IoCard>>>();
        //streamreader4 ubacit da cita podatke za io
    }
}
























//class Program
//{
//    static void Main(string[] args)
//    {
//        ArrayList devices = new ArrayList();
//        string[] deviceNames = { "Device1", "Device2", "Device3", "Device4", "Device5", "Device6", "Device7", "Device8" };
//        string[] ipAddress = { "192.168.0.1", "192.168.0.2", "192.168.0.3", "192.168.0.4", "192.168.0.5", "192.168.0.6", "192.168.0.7", "192.168.0.8" };
//        string[] subnetMask = { "255.255.255.0", "255.255.255.0", "255.255.255.0", "255.255.255.0", "255.255.255.0", "255.255.255.0", "255.255.255.0", "255.255.255.0" };
//        string[] gateway = { "192.168.0.254", "192.168.0.254", "192.168.0.254", "192.168.0.254", "192.168.0.254", "192.168.0.254", "192.168.0.254", "192.168.0.254" };

//        for (int i = 0; i < deviceNames.Length; i++)
//        {
//            int index = i % 4;
//            if (index == 0)
//            {
//                Device device = new Device(deviceNames[i], ipAddress[i], subnetMask[i], gateway[i]);
//                devices.Add(device);
//            }
//            else
//            {
//                Device device = (Device)devices[devices.Count - 1];
//                device.AddInterface(ipAddress[i], subnetMask[i], gateway[i]);
//            }
//        }

//        foreach (Device device in devices)
//        {
//            Console.WriteLine(device);
//        }
//    }
//}

//class Device
//{
//    public string Name { get; set; }
//    public ArrayList Interfaces { get; set; }

//    public Device(string name, string ipAddress, string subnetMask, string gateway)
//    {
//        this.Name = name;
//        this.Interfaces = new ArrayList();
//        Interface @interface = new Interface(ipAddress, subnetMask, gateway);
//        this.Interfaces.Add(@interface);
//    }

//    public void AddInterface(string ipAddress, string subnetMask, string gateway)
//    {
//        Interface @interface = new Interface(ipAddress, subnetMask, gateway);
//        this.Interfaces.Add(@interface);
//    }

//    public override string ToString()
//    {
//        string result = "Device: " + this.Name + "\n";
//        foreach (Interface @interface in this.Interfaces)
//        {
//            result += "Interface: " + @interface.IpAddress + " " + @interface.SubnetMask + " " + @interface.Gateway + "\n";
//        }
//        return result;
//    }
//}

//class Interface
//{
//    public string IpAddress { get; set; }
//    public string SubnetMask { get; set; }
//    public string Gateway { get; set; }

//    public Interface(string ipAddress, string subnetMask, string gateway)
//    {
//        this.IpAddress = ipAddress;
//        this.SubnetMask = subnetMask;
//        this.Gateway = gateway;
//    }
//}