示例#1
0
    public static void WakeUpRaspberryIfNeeded()
    {
        string        executable = "xset";
        List <string> parameters = new List <string>();

        parameters.Insert(0, "-q");
        ExecuteProcess.Result execute_result = ExecuteProcess.run(executable, parameters);

        bool on = screenIsOn(execute_result.stdout);

        LogB.Information("Screen is on?" + on.ToString());

        if (!on)
        {
            //xset -display :0 dpms force on
            parameters = new List <string>();
            parameters.Insert(0, "-display");
            parameters.Insert(1, ":0");
            parameters.Insert(2, "dpms");
            parameters.Insert(3, "force");
            parameters.Insert(4, "on");
        }

        execute_result = ExecuteProcess.run(executable, parameters);
        LogB.Information("Result = " + execute_result.stdout);
    }
    public override WebcamDeviceList GetDevices()
    {
        List <string> parameters = createParameters();

        ExecuteProcess.Result execute_result = ExecuteProcess.run(executable, parameters, true, true);

        LogB.Information("---- stdout: ----");
        LogB.Information(execute_result.stdout);
        LogB.Information("---- stderr: ----");
        LogB.Information(execute_result.stderr);
        LogB.Information("-----------------");

        LogB.Information("pre");
        if (!execute_result.success)
        {
            LogB.Information("no success");
            if (!executableExists())
            {
                LogB.Information(string.Format("File {0} does not exists, but note execuble can be on path", executable));
                wd_list.Error = Constants.FfmpegNotInstalled;
                return(wd_list);
            }

            /*
             * on Windows the -i dummy produces an error, so stderr exists and success is false
             * on Mac the -i "" produces an error, so stderr exists and success is false
             * stdout has the list of devices and stderr also
             * check if in stdout there's the: videoDevString and if not exists, really we have an error
             */
            if (execute_result.stdout != null && execute_result.stdout != "" &&
                execute_result.stdout.Contains(videoDevString))
            {
                LogB.Information("Calling parse with stdout");
                parse(execute_result.stdout);
                return(wd_list);
            }

            if (execute_result.stderr != null && execute_result.stderr != "" &&
                execute_result.stderr.Contains(videoDevString))
            {
                LogB.Information("Calling parse with stderr");
                parse(execute_result.stderr);
                return(wd_list);
            }

            wd_list.Error = Constants.CameraNotFound;
        }
        else
        {
            parse(execute_result.stdout);
        }

        return(wd_list);
    }
示例#3
0
    public override Result PlayPreviewNoBackground()      //experimental
    {
        List <string> parameters = createParametersPlayPreview();

        process = new Process();
        ExecuteProcess.Result execute_result = ExecuteProcess.run(executable, parameters, false, false);
        if (!execute_result.success)
        {
            return(new Result(false, "", programFfplayNotInstalled));
        }

        return(new Result(true, ""));
    }
示例#4
0
    private void on_button_video_debug_clicked(object o, EventArgs args)
    {
        string executable = "debug";

        if (UtilAll.GetOSEnum() == UtilAll.OperatingSystems.WINDOWS)
        {
            executable = System.IO.Path.Combine(Util.GetPrefixDir(), "bin/debug.bat");
        }

        LogB.Information("Calling debug: " + executable);
        ExecuteProcess.Result execute_result = ExecuteProcess.run(executable, true, true);
        LogB.Information("Called debug.");
    }
示例#5
0
    protected override ChronopicRegisterPort readFTDI(ChronopicRegisterPort crp)
    {
        /*
         * old:
         * /bin/udevadm info —name=/dev/ttyUSB0 |grep ID_SERIAL_SHORT|cut -d= -f2
         * error on some systems:
         * Unknown device, --name=, --path=, or absolute path in /dev/ or /sys expected.
         */
        //new: udevadm info -p $(udevadm info -q path -n /dev/ttyUSB0)
        //TODO: find a way to call this in only one process

        //1) get path
        List <string> parameters = new List <string> {
            "info", "-q", "path", "-n", crp.Port
        };

        ExecuteProcess.Result result = ExecuteProcess.runShowErrorIfNotStarted("udevadm", parameters);
        string path = result.stdout;

        if (result.stderr != "")
        {
            return(crp);
        }

        //2) read FTDI info
        parameters = new List <string> {
            "info", "-p", path
        };
        result = ExecuteProcess.runShowErrorIfNotStarted("udevadm", parameters);

        if (result.stderr != "")
        {
            return(crp);
        }

        foreach (string lineOut in result.stdout.Split('\n'))
        {
            if (lineOut.Contains("ID_VENDOR="))
            {
                string [] strFull = lineOut.Split(new char[] { '=' });
                crp.FTDI = (strFull[1] == "FTDI");
            }
            else if (lineOut.Contains("ID_SERIAL_SHORT="))
            {
                string [] strFull = lineOut.Split(new char[] { '=' });
                crp.SerialNumber = strFull[1];
            }
        }
        return(crp);
    }
示例#6
0
    public static List <string> GetDevices()
    {
        string executable = "ffmpeg";

        if (UtilAll.GetOSEnum() == UtilAll.OperatingSystems.WINDOWS)
        {
            executable = System.IO.Path.Combine(Util.GetPrefixDir(), "bin/ffmpeg.exe");
        }

        List <string> parameters = createParameters();

        ExecuteProcess.Result execute_result = ExecuteProcess.run(executable, parameters);

        Console.WriteLine("---- stdout: ----");
        Console.WriteLine(execute_result.stdout);
        Console.WriteLine("---- stderr: ----");
        Console.WriteLine(execute_result.stderr);
        Console.WriteLine("-----------------");

        if (!execute_result.success)
        {
            Console.WriteLine("WebcamFfmpegGetDevicesWindows error: " + execute_result.stderr);

            /*
             * on Windows the -i dummy produces an error, so stderr exists and success is false
             * stdout has the list of devices and stderr also
             * check if in stdout there's the: "DirectShow video devices" string and if not exists, really we have an error
             */
            if (execute_result.stdout != null && execute_result.stdout != "" &&
                execute_result.stdout.Contains("DirectShow video devices"))
            {
                Console.WriteLine("Calling parse with stdout");
                return(parse(execute_result.stdout));
            }

            if (execute_result.stderr != null && execute_result.stderr != "" &&
                execute_result.stderr.Contains("DirectShow video devices"))
            {
                Console.WriteLine("Calling parse with stderr");
                return(parse(execute_result.stderr));
            }

            return(new List <string>());
        }
        else
        {
            return(parse(execute_result.stdout));
        }
    }
示例#7
0
    private bool linuxUserHasDialout()
    {
        LogB.Information("Finding dialout:");
        string executable = "groups";

        ExecuteProcess.Result execute_result = ExecuteProcess.run(executable, true, true);
        if (execute_result.success)
        {
            LogB.Information(execute_result.stdout);
            return(execute_result.stdout.Contains("dialout"));
        }

        //if script has failed, don't bother the user
        return(true);
    }
示例#8
0
    private bool convertImagesToVideo()
    {
        executable = "ffmpeg";
        List <string> parameters = new List <string>();

        //ffmpeg -framerate 20 -y -i chronojump-last-photo%04d.png output.mp4
        parameters.Insert(0, "-framerate");
        parameters.Insert(1, "20");
        parameters.Insert(2, "-y");          //force overwrite without asking
        parameters.Insert(3, "-i");          //input files
        parameters.Insert(4, Util.GetWebcamPhotoTempFileNamePre(videoDeviceToFilename()) + "%04d.png");
        parameters.Insert(5, Util.GetVideoTempFileName());

        ExecuteProcess.Result execute_result = ExecuteProcess.run(executable, parameters, true, true);
        return(execute_result.success);
    }
    private static Result executeChronojumpImporter(List <string> parameters)
    {
        string importer_executable;

        if (UtilAll.IsWindows())
        {
            // On Windows we execute the .exe file (it's the Python with py2exe)
            importer_executable = System.IO.Path.Combine(Util.GetPrefixDir(), "bin\\chronojump-importer\\chronojump_importer.exe");
        }
        else
        {
            // On Linux and OSX we execute Python and we pass the path to the script as a first argument

            importer_executable = "python";                     // chronojump_importer.py works on Python 2 and Python 3

            string importer_script_path = System.IO.Path.Combine(Util.GetPrefixDir(), "bin/chronojump_importer.py");

            // first argument of the Python: the path to the script
            parameters.Insert(0, importer_script_path);
        }

        ExecuteProcess.Result execute_result = ExecuteProcess.run(importer_executable, parameters, true, true);

        if (execute_result.exitCode != 0)
        {
            // Python interpretar was executed but the Python file wasn't found or the script failed
            string errorMessage = "";

            if (execute_result.errorMessage == "")
            {
                // The Python script has been executed and failed (syntax error, crashed).
                // The error message will be in the output:
                errorMessage  = execute_result.allOutput;
                errorMessage += "\nArguments: " + String.Join(" ", parameters);
            }
            else
            {
                // The Python script has not been executed, return the error message from ExecuteProcess
                errorMessage = execute_result.errorMessage;
            }
            return(new Result(false, execute_result.allOutput, errorMessage));
        }

        // All good, returns the output
        return(new Result(true, execute_result.allOutput));
    }
示例#10
0
    //snapshot in 2 seconds
    public override bool Snapshot()
    {
        executable = "ffmpeg";
        if (os == UtilAll.OperatingSystems.WINDOWS)
        {
            executable = System.IO.Path.Combine(Util.GetPrefixDir(), "bin/ffmpeg.exe");
        }
        if (os == UtilAll.OperatingSystems.MACOSX)
        {
            executable = System.IO.Path.Combine(Util.GetPrefixDir(), "bin/ffmpeg");
        }

        List <string> parameters = createParametersSnapshot();

        process = new Process();
        ExecuteProcess.Result execute_result = ExecuteProcess.run(executable, parameters, false, false);
        return(execute_result.success);
    }
示例#11
0
    //used to know "Supported modes" on mac
    public override Result PlayPreviewNoBackgroundWantStdoutAndStderr()     //experimental
    {
        List <string> parameters = createParametersPlayPreview();

        process = new Process();
        ExecuteProcess.Result execute_result = ExecuteProcess.run(executable, parameters, true, true);
        //LogB.Information("Stdout: ", execute_result.stdout);
        //LogB.Information("Stderr: ", execute_result.stderr);
        LogB.Information("allOutput: ", execute_result.allOutput);

        string parsed = parseSupportedModes(execute_result.allOutput);

        //use this to test the parsing method
        //string parsed = parseSupportedModes(parseSupportedModesTestString);

        if (!execute_result.success)
        {
            return(new Result(false, parsed));
        }

        return(new Result(true, parsed));
    }