Exemple #1
0
        public static arduino info(string search)
        {
            arduino info = new arduino();

            string[] ports = SerialPort.GetPortNames();
            try {
                //ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_SerialPort");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_PnPEntity WHERE ClassGuid=\"{4d36e978-e325-11ce-bfc1-08002be10318}\"");
                foreach (ManagementObject queryObj in searcher.Get())
                {
                    //Console.WriteLine("-----------------------------------");
                    //Console.WriteLine("Win32_SerialPort instance");
                    //Console.WriteLine("-----------------------------------");
                    //Console.WriteLine("DeviceID: {0}", queryObj["DeviceID"]);
                    //Console.WriteLine("Name: {0}", queryObj["Name"]);

                    if (queryObj["Name"].ToString().Contains(search))
                    {
                        string arduinoVID = HelperClass.regex("VID_([0-9a-fA-F]+)", queryObj["DeviceID"].ToString());
                        string arduinoPID = HelperClass.regex("PID_([0-9a-fA-F]+)", queryObj["DeviceID"].ToString());
                        arduinoVID = arduinoVID.Remove(0, 4);
                        arduinoPID = arduinoPID.Remove(0, 4);

                        info.vid  = arduinoVID;
                        info.pid  = arduinoPID;
                        info.name = queryObj["Name"].ToString();
                    }
                }
                if (searcher.Get().Count == 0)
                {
                    MessageBox.Show("No arduino was found.");
                    info.error = true;
                }
            } catch (ManagementException e) {
                MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
                info.error = true;
            }

            foreach (string port in ports)
            {
                //System.Windows.Forms.MessageBox.Show(port);
                if (info.name.Contains(port))
                {
                    info.com = port;
                }
            }

            if (info.vid == "" || info.pid == "" || info.com == "")
            {
                info.error = true;
            }

            return(info);
        }
Exemple #2
0
        public static bool CompileHex(arduino a)
        {
            try {
                string command1;
                string command2;
                if (a.nano)
                {
                    command1 = "arduino-builder -dump-prefs -logger=machine -hardware ./hardware -tools ./tools-builder -tools ./hardware/tools/avr -built-in-libraries ./builtinlibraries -libraries ./libraries -fqbn=arduino:avr:nano:cpu=atmega328 -vid-pid=" + a.vid + "_" + a.pid + " -ide-version=10813 -build-path ./build -warnings=none -build-cache ./buildcache -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=./hardware/tools/avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=./hardware/tools/avr -prefs=runtime.tools.avrdude.path=./hardware/tools/avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=./hardware/tools/avr -prefs=runtime.tools.avr-gcc.path=./hardware/tools/avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=./hardware/tools/avr -verbose macro.ino";
                    command2 = "arduino-builder -compile -logger=machine -hardware ./hardware -tools ./tools-builder -tools ./hardware/tools/avr -built-in-libraries ./builtinlibraries -libraries ./libraries -fqbn=arduino:avr:nano:cpu=atmega328 -vid-pid=" + a.vid + "_" + a.pid + " -ide-version=10813 -build-path ./build -warnings=none -build-cache ./buildcache -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=./hardware/tools/avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=./hardware/tools/avr -prefs=runtime.tools.avrdude.path=./hardware/tools/avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=./hardware/tools/avr -prefs=runtime.tools.avr-gcc.path=./hardware/tools/avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=./hardware/tools/avr -verbose macro.ino";
                }
                else
                {
                    //command1 = "arduino-builder -dump-prefs -logger=machine -hardware ./hardware -tools ./tools-builder -tools ./hardware/tools/avr -built-in-libraries ./builtinlibraries -libraries ./libraries -fqbn=arduino:avr:nano:cpu=atmega328 -vid-pid=" + a.vid + "_" + a.pid + " -ide-version=10813 -build-path ./build -warnings=none -build-cache ./buildcache -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=./hardware/tools/avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=./hardware/tools/avr -prefs=runtime.tools.avrdude.path=./hardware/tools/avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=./hardware/tools/avr -prefs=runtime.tools.avr-gcc.path=./hardware/tools/avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=./hardware/tools/avr -verbose macro.ino";
                    //command2 = "arduino-builder -compile -logger=machine -hardware ./hardware -tools ./tools-builder -tools ./hardware/tools/avr -built-in-libraries ./builtinlibraries -libraries ./libraries -fqbn=arduino:avr:nano:cpu=atmega328 -vid-pid=" + a.vid + "_" + a.pid + " -ide-version=10813 -build-path ./build -warnings=none -build-cache ./buildcache -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=./hardware/tools/avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=./hardware/tools/avr -prefs=runtime.tools.avrdude.path=./hardware/tools/avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=./hardware/tools/avr -prefs=runtime.tools.avr-gcc.path=./hardware/tools/avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=./hardware/tools/avr -verbose macro.ino";
                    command1 = "";
                    command2 = "";
                }

                Process          p1  = new Process();
                ProcessStartInfo SI1 = new ProcessStartInfo();
                SI1.UseShellExecute = true;
                SI1.WindowStyle     = ProcessWindowStyle.Hidden;
                SI1.FileName        = "cmd.exe";
                SI1.Arguments       = ("/C " + command1);
                p1.StartInfo        = SI1;
                p1.Start();
                p1.WaitForExit();

                Process          p2  = new Process();
                ProcessStartInfo SI2 = new ProcessStartInfo();
                SI2.UseShellExecute = true;
                SI2.WindowStyle     = ProcessWindowStyle.Hidden;
                SI2.FileName        = "cmd.exe";
                SI2.Arguments       = ("/C " + command2);
                p2.StartInfo        = SI2;
                p2.Start();
                p2.WaitForExit();
            } catch (Exception e) {
                return(false);
            }
            return(true);
        }