V2/Cet/IO/Cet.IO.DemoModbus/Cet.IO.DemoModbusNetduino_WP7/MainPage.xaml.cs
/// <summary>
/// Handle the btnEcho_Click event by sending text to the echo server and outputting the response
/// </summary>
Handle the btnEcho_Click event by sending text to the echo server and outputting the response
Handle the btnEcho_Click event by sending text to the echo server and outputting the response
private async void btnConnect_Click(object sender, RoutedEventArgs e)
        {
            if (ValidateRemoteHost())
            {
                this.txtRemoteHost.IsEnabled = false;
                this.btnConnect.IsEnabled = false;
                this.btnDisconnect.IsEnabled = true;
                this.pbarConnect.Value = 0;
                this.pbarConnect.Visibility = System.Windows.Visibility.Visible;
                this.pbarConnect.IsIndeterminate = true;
                this.txtStatus.Text = "Connecting...";
                var connected = await this.ConnectAsync(
                    txtRemoteHost.Text,
                    502);
                this.pbarConnect.Visibility = System.Windows.Visibility.Collapsed;
                if (connected)
                {
                    this.txtStatus.Text = "Connection succeeded.";
                    App.Modbus = new Protocols.ModbusClient(new ModbusTcpCodec());
                    App.Modbus.Address = 1;
                    await TaskEx.Delay(1000);
                    NavigationService.Navigate(new Uri("/BoardLayoutPage.xaml", UriKind.Relative));
                }
                else
                {
                    this.txtStatus.Text = App.Client.LastError;
                    this.btnDisconnect.IsEnabled = false;
                }
                this.txtRemoteHost.IsEnabled = true;
                this.btnConnect.IsEnabled = true;
#if false
                Log(String.Format("Connecting to server '{0}' over port {1} (echo) ...", txtRemoteHost.Text, ECHO_PORT), true);
                string result = client.Connect(txtRemoteHost.Text, ECHO_PORT);
                Log(result, false);
                Log(String.Format("Sending '{0}' to server ...", txtInput.Text), true);
                result = client.Send(txtInput.Text);
                Log(result, false);
                Log("Requesting Receive ...", true);
                result = client.Receive();
                Log(result, false);
                client.Close();
#endif
            }
        }
private async void btnConnect_Click ( object sender , RoutedEventArgs e ) { if ( ValidateRemoteHost ( ) ) { this . txtRemoteHost . IsEnabled = false ; this . btnConnect . IsEnabled = false ; this . btnDisconnect . IsEnabled = true ; this . pbarConnect . Value = 0 ; this . pbarConnect . Visibility = System . Windows . Visibility . Visible ; this . pbarConnect . IsIndeterminate = true ; this . txtStatus . Text = " " ; var connected = await this . ConnectAsync ( txtRemoteHost . Text , 502 ) ; this . pbarConnect . Visibility = System . Windows . Visibility . Collapsed ; if ( connected ) { this . txtStatus . Text = " " ; App . Modbus = new Protocols . ModbusClient ( new ModbusTcpCodec ( ) ) ; App . Modbus . Address = 1 ; await TaskEx . Delay ( 1000 ) ; NavigationService . Navigate ( new Uri ( " " , UriKind . Relative ) ) ; } else { this . txtStatus . Text = App . Client . LastError ; this . btnDisconnect . IsEnabled = false ; } this . txtRemoteHost . IsEnabled = true ; this . btnConnect . IsEnabled = true ; if false Log ( String . Format ( " " , txtRemoteHost . Text , ECHO_PORT ) , true ) ; string result = client . Connect ( txtRemoteHost . Text , ECHO_PORT ) ; Log ( result , false ) ; Log ( String . Format ( " " , txtInput . Text ) , true ) ; result = client . Send ( txtInput . Text ) ; Log ( result , false ) ; Log ( " " , true ) ; result = client . Receive ( ) ; Log ( result , false ) ; client . Close ( ) ; endif } }
Handle the btnEcho_Click event by sending text to the echo server and outputting the response
Handle the btnEcho_Click event by sending text to the echo server and outputting the response
// Make sure we can perform this action with valid data //disable UI //show progression status // Instantiate the SocketClient //hide the progress bar //enable UI // Attempt to connect to the echo server // Attempt to send our message to be echoed to the echo server // Receive a response from the echo server // Close the socket connection explicitly
sender
object
e
RoutedEventArgs