runShowErrorIfNotStarted() public static method

public static runShowErrorIfNotStarted ( string file_name, List parameters ) : Result
file_name string
parameters List
return Result
Exemplo n.º 1
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);
    }