示例#1
0
        void MakeSureClientIsConnected()
        {
            if (_client != null && !_client.Connected)
            {
                _client.Dispose();
                _client = null;
                _adapter.Dispose();
                _adapter = null;
                _master.Dispose();
                _master = null;
            }

            if (_client == null)
            {
                _client  = new TcpClient(_configuration.Ip, _configuration.Port);
                _adapter = new TcpClientAdapter(_client);
                var factory = new ModbusFactory();
                if (_configuration.UseASCII)
                {
                    _master = factory.CreateAsciiMaster(_adapter);
                }
                else if (_configuration.Protocol == Protocol.Tcp)
                {
                    _master = factory.CreateMaster(_client);
                }
                else
                {
                    _master = factory.CreateRtuMaster(_adapter);
                }
            }
        }
示例#2
0
 /// <inheritdoc/>
 public void Dispose()
 {
     _client?.Dispose();
     _client = null;
     _adapter?.Dispose();
     _adapter = null;
     _master?.Dispose();
     _master = null;
 }
        public void DisposesTcpClient()
        {
            // Arrange
            var tcpClient = new TcpClient();
            var target    = new TcpClientAdapter <TcpClient>(tcpClient);

            // Act
            target.Dispose();

            // Assert
            Assert.Null(tcpClient.Client);
        }
 internal void CloseSocket()
 {
     _client.Dispose();
 }
示例#5
0
 internal void CloseSocket()
 {
     _needDispose = false;
     client.Dispose();
 }