Example #1
0
        /// <summary>
        /// Try to connect/communicate with NETIO device.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void onConnectClick(object sender, RoutedEventArgs e)
        {
            // init driver
            netIoDriver = new NetIoDriver(guiIpAddress.Text, guiUsername.Text, guiPassword.Text);

            // test communication with NETIO, read out Agent info
            var agent = netIoDriver.GetAgent();

            // show result
            if (agent is null)
            {
                MessageBox.Show($"Could not find/connect to NETIO device.\r\nMake sure IP address, username and/or password is correct.", "Connect error", MessageBoxButton.OK, MessageBoxImage.Error);
                enableControls(false);
                return;
            }
            else
            {
                guiModel.Text        = agent.Model;
                guiModelVersion.Text = agent.Version;
                guiJsonVersion.Text  = agent.JSONVer;
                guiDeviceName.Text   = agent.DeviceName;
                guiOemId.Text        = agent.OemID.ToString();
                guiSerialNumber.Text = agent.SerialNumber;
                guiNoOfOutputs.Text  = agent.NumOutputs.ToString();

                enableControls(true);
                updateGuiWithCurrentPowerswitchStatus();
                await startPowerIntervalReaderAsync().ConfigureAwait(false);
            }
        }
        /// <summary>
        /// Try to connect/communicate with NETIO device.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void onConnectClick(object sender, RoutedEventArgs e)
        {
            // init driver
            netIoDriver = new NetIoDriver(guiIpAddress.Text, guiUsername.Text, guiPassword.Text);

            // test communication with NETIO, read out Agent info
            var agent = netIoDriver.GetAgent();

            // show result
            if ("Error" != agent.Model)
            {
                enableControls(true);
                guiModel.Text        = agent.Model;
                guiModelVersion.Text = agent.Version;
                guiJsonVersion.Text  = agent.JSONVer;
                guiDeviceName.Text   = agent.DeviceName;
                guiOemId.Text        = agent.OemID.ToString();
                guiSerialNumber.Text = agent.SerialNumber;
                guiNoOfOutputs.Text  = agent.NumOutputs.ToString();
            }
            else
            {
                MessageBox.Show($"Could not find/connect to NETIO device.\r\nMake sure IP address, username and/or password is correct.", "Connect error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }