Example #1
0
        /// <summary>
        /// Constructor of Dacs7Client
        /// </summary>
        /// <param name="address">The address of the plc  [IP or Hostname]:[Rack],[Slot]  where as rack and slot ar optional  default is Rack = 0, Slot = 2</param>
        /// <param name="connectionType">The <see cref="PlcConnectionType"/> for the connection.</param>
        public Dacs7Client(string address, PlcConnectionType connectionType = PlcConnectionType.Pg)
        {
            var addressPort  = address.Split(':');
            var portRackSlot = addressPort.Length > 1 ?
                               addressPort[1].Split(',').Select(x => Int32.Parse(x)).ToArray() :
                               new int[] { 102, 0, 2 };

            _config = new ClientSocketConfiguration
            {
                Hostname    = addressPort[0],
                ServiceName = portRackSlot.Length > 0 ? portRackSlot[0] : 102
            };



            _context = new Rfc1006ProtocolContext
            {
                DestTsap = Rfc1006ProtocolContext.CalcRemoteTsap((ushort)connectionType,
                                                                 portRackSlot.Length > 1 ? portRackSlot[1] : 0,
                                                                 portRackSlot.Length > 2 ? portRackSlot[2] : 2)
            };

            _s7Context = new SiemensPlcProtocolContext
            {
            };

            _protocolHandler = new ProtocolHandler(_config, _context, _s7Context, UpdateConnectionState);
        }
Example #2
0
        public ProtocolHandler(ClientSocketConfiguration config, Rfc1006ProtocolContext rfcContext, SiemensPlcProtocolContext s7Context, Action <ConnectionState> connectionStateChanged)
        {
            _context   = rfcContext;
            _s7Context = s7Context;
            _connectionStateChanged = connectionStateChanged;

            _socket = new ClientSocket(config)
            {
                OnRawDataReceived        = OnRawDataReceived,
                OnConnectionStateChanged = OnConnectionStateChanged
            };
        }
Example #3
0
 public TcpTransport(Rfc1006ProtocolContext context, ServerSocketConfiguration config) : base(context, config) => _context = context;
Example #4
0
 public TcpTransport(Rfc1006ProtocolContext context, ClientSocketConfiguration config, System.Net.Sockets.Socket usedSocket = null) : base(context, config)
 {
     _context = context;
     _socket  = usedSocket;
 }