Control_AGV

mail@pastecode.io avatar
unknown
plain_text
3 years ago
9.5 kB
4
Indexable
Never
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace NavigationDrawerPopUpMenu2
{
    /// <summary>
    /// Interação lógica para UserControlCreate.xam
    /// </summary>
    public partial class Machine_connect : UserControl
    {
        public Machine_connect()
        {
            InitializeComponent();


         }

         void runCommand()
        {
            
        }


         void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
        {
            //* Do your stuff with the output (write to console/log/StringBuilder)
           /* try
            {
                if(outLine.Data.Count() >0)
                {
                   Console.WriteLine(outLine.Data +" count "+ outLine.Data.Count().ToString());
                    //Console.WriteLine(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames());
                   
                    this.Dispatcher.Invoke((Action)(() =>
                    {
                        Ra_proce.IsChecked = false;
                        Ra_proce.IsEnabled = true;
                        Ra_proce.Content = "開始預測";
                        Res.Content = "表面粗糙預測值(Ra):" + outLine.Data.ToString().Substring(0, 4) + " um";
                    }));
                    
                    //MessageBox.Show("表面粗糙預測值(Ra):" + outLine.Data);
                }
                
            }
            catch
            {

            }*/
                

        }


        private void Ra_proce_Checked(object sender, RoutedEventArgs e)
        {

            var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://163.17.137.234:50200/AGV/SendAgvCmd");
            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method = "POST";


            string content = (sender as Button).Name.ToString();
            Console.WriteLine(content);

            if (content.Equals("N_L90") == true)
            {
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = "{\"Name\":\"ITRI_3-3\"," + "\"Cmd\":\"30210\"}";
                    streamWriter.Write(json);
                }
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

                httpResponse.Close();
            }
            else if (content.Equals("N_R90") == true)
            {
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = "{\"Name\":\"ITRI_3-3\"," + "\"Cmd\":\"30208\"}";
                    streamWriter.Write(json);
                }
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                httpResponse.Close();
            }
            else if (content.Equals("N_L180") == true)
            {
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = "{\"Name\":\"ITRI_3-3\"," + "\"Cmd\":\"30211\"}";
                    streamWriter.Write(json);
                }
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                httpResponse.Close();
            }
            else if (content.Equals("N_R180") == true)
            {
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = "{\"Name\":\"ITRI_3-3\"," + "\"Cmd\":\"30209\"}";
                    streamWriter.Write(json);
                }
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                httpResponse.Close();
            }
            else if (content.Equals("L_90") == true)
            {
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = "{\"Name\":\"ITRI_3-3\"," + "\"Cmd\":\"30110\"}";
                    streamWriter.Write(json);
                }
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                httpResponse.Close();
            }
            else if (content.Equals("R_90") == true)
            {
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = "{\"Name\":\"ITRI_3-3\"," + "\"Cmd\":\"30108\"}";
                    streamWriter.Write(json);
                }
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                httpResponse.Close();
            }
            else if (content.Equals("L_180") == true)
            {
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = "{\"Name\":\"ITRI_3-3\"," + "\"Cmd\":\"30111\"}";
                    streamWriter.Write(json);
                }
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                httpResponse.Close();
            }
            else if (content.Equals("R_180") == true)
            {
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = "{\"Name\":\"ITRI_3-3\"," + "\"Cmd\":\"30109\"}";
                    streamWriter.Write(json);
                }
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                httpResponse.Close();
            }

        }

        private void R2(object sender, RoutedEventArgs e)
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://163.17.137.234:50200/AGV/SendAgvCmd");
            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method = "POST";


            string content = (sender as Button).Name.ToString();
            Console.WriteLine(content);

            if (content.Equals("C_1") == true)
            {
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = "{\"Name\":\"ITRI_3-3\"," + "\"Cmd\":\"30218\"}";
                    streamWriter.Write(json);
                }
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

                httpResponse.Close();
            }
            else if (content.Equals("C_2") == true)
            {
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = "{\"Name\":\"ITRI_3-3\"," + "\"Cmd\":\"30219\"}";
                    streamWriter.Write(json);
                }
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                httpResponse.Close();
            }
            else if (content.Equals("C_L90") == true)
            {
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = "{\"Name\":\"ITRI_3-3\"," + "\"Cmd\":\"30216\"}";
                    streamWriter.Write(json);
                }
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                httpResponse.Close();
            }
            else if (content.Equals("C_R90") == true)
            {
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = "{\"Name\":\"ITRI_3-3\"," + "\"Cmd\":\"30214\"}";
                    streamWriter.Write(json);
                }
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                httpResponse.Close();
            }
            else if (content.Equals("C_L180") == true)
            {
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = "{\"Name\":\"ITRI_3-3\"," + "\"Cmd\":\"30217\"}";
                    streamWriter.Write(json);
                }
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                httpResponse.Close();
            }
            else if (content.Equals("C_R180") == true)
            {
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = "{\"Name\":\"ITRI_3-3\"," + "\"Cmd\":\"30215\"}";
                    streamWriter.Write(json);
                }
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                httpResponse.Close();
            }
           
    }
    }
}