Exemplo n.º 1
0
        private void connectBtn_Click(object sender, EventArgs e)
        {
            if (_connected)
            {
                Disconnect();
                ResetPorts();
                return;
            }
            _logger.WriteMessage("Pressed Connect button.", DebugLevel.VERBOSE);
            try
            {
                var ipAddress      = IPAddress.Parse(deviceIPTB.Text);
                var readCommunity  = readCommunityTB.Text;
                var writeCommunity = writeCommunityTB.Text;
                var port           = int.Parse(portTB.Text);
                var retry          = int.Parse(retryTB.Text);
                _timeout = int.Parse(timeoutTB.Text);
                var updateInterval = int.Parse(updateIntervalTB.Text);
                _device = Lbc4000.GetDevice(ipAddress, writeCommunity, readCommunity, port, retry, _timeout, updateInterval);
                if (_device.Connect())
                {
                    _device.Run();
                    InitPorts();
                    _connected           = true;
                    connectBtn.BackColor = Color.Green;
                    connectBtn.Text      = "Disconnect";
                    Text = "DCController - Connected";
                    getStateBtn.Enabled       = true;
                    downloadConfigBtn.Enabled = true;
                    getStateBtn_Click(sender, e);
                }

                else
                {
                    _logger.WriteMessage("Couldn't connect to device", DebugLevel.ERROR);
                    _connected = false;
                    Disconnect();
                    MessageBox.Show("Couldn't connect to specified IP address", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                _logger.WriteMessage(ex.Message, DebugLevel.ERROR);
                _connected = false;
                Disconnect();
                MessageBox.Show("Thrown exception: " + ex.Message, "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
 private void Disconnect()
 {
     _connected           = false;
     connectBtn.Text      = "Connect";
     connectBtn.BackColor = _defaultColor;
     connectBtn.UseVisualStyleBackColor = true;
     if (_device != null)
     {
         _device.Dispose();
         _device = null;
     }
     alarmsDataGrid.Rows.Clear();
     getStateBtn.Enabled       = false;
     downloadConfigBtn.Enabled = false;
     ResetPorts();
     this.Text = "DCController - Disconnected";
 }
Exemplo n.º 3
0
 public DownConverterDevice(IPAddress ipAddress, Uri webSocketServer, IguiInterface gui)
     : base(webSocketServer, gui)
 {
     _device = Lbc4000.GetDevice(ipAddress);
 }