using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace Common
{
    public class Adb_Common
    {
        private Process process = new Process();
        public bool i=true;
        public string Send_Command(string command,bool result = true)
        {
            if (i)
            {
                process.StartInfo.FileName = "cmd.exe";
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.RedirectStandardInput = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError = true;
                process.StartInfo.CreateNoWindow = true;
                i = false;
            }
            
            //string command = "adb shell";
            //process.StandardInput.WriteLine(command);
            //command = "echo 255 > /sys/class/leds/red/brightness";
            //process.StandardInput.WriteLine(command);
            //command = "echo 0 > /sys/class/leds/blue/brightness";
            //process.StandardInput.WriteLine(command);
            //command = "echo 0 > /sys/class/leds/green/brightness";
            //process.StandardInput.WriteLine(command);
            process.StartInfo.Arguments = "/c " + command;//“/C”表示执行完命令后马上退出
            process.Start();
            if (result)
            {
                string data1 = process.StandardOutput.ReadToEnd();
                //process.WaitForExit();
                //process.Close();
                string Text = "执行结果： " + data1;
                return Text;
            }
            return "执行成功";
        }

        public string Send_Command_CameraTool(string command, bool result = true)
        {
            if (i)
            {
                process.StartInfo.FileName = "cmd.exe";
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.RedirectStandardInput = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError = true;
                process.StartInfo.CreateNoWindow = true;
                i = false;
            }
            process.StartInfo.Arguments = "/c " + command;//“/C”表示执行完命令后马上退出
            process.Start();
            if (result)
            {
                string data1 = process.StandardOutput.ReadLine();
                Console.WriteLine(data1);
                Thread.Sleep(5000);
                //process.WaitForExit();
                //process.Close();
                string Text = "执行结果： " + data1;
                return Text;
            }
            return "执行成功";
        }

        public string Serial_Command(string pyth,int type)
        {
            if (i)
            {
                process.StartInfo.FileName = "cmd.exe";
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.RedirectStandardInput = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError = true;
                process.StartInfo.CreateNoWindow = true;
                i = false;
            }

            //string command = "adb shell";
            //process.StandardInput.WriteLine(command);
            //command = "echo 255 > /sys/class/leds/red/brightness";
            //process.StandardInput.WriteLine(command);
            //command = "echo 0 > /sys/class/leds/blue/brightness";
            //process.StandardInput.WriteLine(command);
            //command = "echo 0 > /sys/class/leds/green/brightness";
            //process.StandardInput.WriteLine(command);
            pyth = ""+pyth +" "+ type;
            process.StartInfo.Arguments = "/c " + pyth;//“/C”表示执行完命令后马上退出
            process.Start();
            string data1 = process.StandardOutput.ReadToEnd();
            //process.WaitForExit();
            //process.Close();
            string Text = "执行结果： " + data1;
            return Text;
        
        }

        public void Able_COM(string com,string pyte)
        {
            string Command = string.Format(@"D:\EurekaQT\EurekaQT\bin\Debug\Debug\PortMangmenTool.exe {0} {1}", com, pyte);
            Send_Command(Command);
        }
        
    }
}
