S
S
Sergey Karbivnichy2019-10-15 19:55:46
linux
Sergey Karbivnichy, 2019-10-15 19:55:46

Is it possible to use name patterns in ProcessStartInfo in the Arguments method?

Good evening. I need to get the names of com ports through a c# program using the ls utility. Here is an example:

textBox.Clear();
            ProcessStartInfo psi = new ProcessStartInfo();
            psi.FileName = "/bin/ls";
            psi.UseShellExecute = false;
            psi.Arguments = "/dev/tt*";
           // psi.Arguments = textBox1.Text;
            psi.RedirectStandardOutput = true;
            Process p = Process.Start(psi);
            textBox.Text += (p.StandardOutput.ReadToEnd() + Environment.NewLine);
            p.WaitForExit();
            p.Close();

if I pass "/dev/" to psi.Arguments, then I get the full list of devices, but if I pass "/dev/ttyUSB*", I get an empty list. Wang that the list of names is a feature of bash, probably. So how do I get a list of /dev/ttyUSB0, /dev/ttyUSB1, /dev/tty2, etc. (if there are any of course).
PS: Can grep somehow add?
PS1: Although you can use the standard mono tools to parse the list for the presence of ttyUSB*...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2019-10-15
@MechanID

If there is a com port on the board (not via a usb adapter), then usually it will be / dev / ttyS *
Also in the dmesg log there will be lines when the OS starts, something like:
[ 0.860340] 00:02: ttyS0 at I / O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[ 0.880928] 00:03: ttyS1 at I/O 0x2f8 (irq = 3, base_baud = 115200) is a 16550A
[ 0.901518] 00:05: ttyS2 at I/O 0x3e8 (irq = 5, base_baud = 115200) is a 16550A
If USB adapter, then yes it should be /dev/ttyUSB*
and the corresponding entries in the dmesg log:
[ 6.968929] usb 3-3: FTDI USB Serial Device converter now attached to ttyUSB0
about ls and grep
commands " ls /dev/ttyUSB*" should be enough to get all ttyUSB
if there is no shell then try "ls /dev/|grep ttyUSB"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question