Получить список COM портов
Модератор: Модераторы
Получить список COM портов
Как получить список COM портов для Linux. GetSerialPortNames из synaser в Linux не работает, как и написано в исходнике.
Думаю проще всего через команду. Варианты, например:
Код: Выделить всё
a) grep serial /proc/ioports
b) cat /proc/tty/driver/serial
c) dmesg | grep ttyS
d) setserial -g /dev/ttyS[0-9] | grep -v unknownА как из команды получить результат в строку?
Код: Выделить всё
program launchprogram;
// Here we include files that have useful functions
// and procedures we will need.
uses
Classes, SysUtils, Process;
// This is defining the var "AProcess" as a variable
// of the type "TProcess"
// Also now we are adding a TStringList to store the
// data read from the programs output.
var
AProcess: TProcess;
AStringList: TStringList;
// This is where our program starts to run
begin
// Now we will create the TProcess object, and
// assign it to the var AProcess.
AProcess := TProcess.Create(nil);
// Tell the new AProcess what the command to execute is.
AProcess.Executable := '/usr/bin/ppc386';
AProcess.Parameters.Add('-h');
// We will define an option for when the program
// is run. This option will make sure that our program
// does not continue until the program we will launch
// has stopped running. Also now we will tell it that
// we want to read the output of the file.
AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
// Now that AProcess knows what the commandline is it can be run.
AProcess.Execute;
// After AProcess has finished, the rest of the program will be executed.
// Now read the output of the program we just ran into a TStringList.
AStringList := TStringList.Create;
AStringList.LoadFromStream(AProcess.Output);
// Save the output to a file and clean up the TStringList.
AStringList.SaveToFile('output.txt');
AStringList.Free;
// Now that the output from the process is processed, it can be freed.
AProcess.Free;
end.http://wiki.freepascal.org/Executing_Ex ... ect_yet.29
Спасибо, пригодится.
Сделал уже так:
Те порты которые мне надо показывает.
Сделал уже так:
Код: Выделить всё
{ for Linux }
procedure TForm1.Read_port_list;
var
Info : TSearchRec;
Count : Longint;
begin
ComboBox1.Items.Clear;
Count := 0;
if FindFirst('/dev/tty???*', faAnyFile, Info)=0 then
begin
repeat
inc(Count);
with Info do
begin
Memo1.Lines.Add(Name);
ComboBox1.Items.Add(Name);
end
until FindNext(Info)<>0 ;
end;
FindClose(Info);
end;Те порты которые мне надо показывает.
Ваш код неправильный.
Надо делать как вам подсказал tema.
На CentOS7 ваш код ничего не возвращает.
Надо делать как вам подсказал tema.
На CentOS7 ваш код ничего не возвращает.
Тогда, неправильный. Я ещё смотрю в сторону BaseUnix, там похоже много всего хорошего.
P. S. Вы ничего не видите, потому что Arduino не подсоединили! Так и задумано.
P. S. Вы ничего не видите, потому что Arduino не подсоединили! Так и задумано.
tema писал(а):Думаю проще всего через команду. Варианты, например:
Зачем вы так усложнили?
все три первые - решение через чтения файла..
Код: Выделить всё
Var
t:text;
begin
assign(t,'/proc/ioports');
..проще
Код: Выделить всё
Var s:TStringList;
begin
s:=TStringList.Create();
s.LoadFromFile('/proc/ioports');Спасибо. Простое и очевидное решение - признак мастерства.
olegy123 писал(а):tema писал(а):Думаю проще всего через команду. Варианты, например:
Зачем вы так усложнили?
все три первые - решение через чтения файла..Код: Выделить всё
Var
t:text;
begin
assign(t,'/proc/ioports');
..
прощеКод: Выделить всё
Var s:TStringList;
begin
s:=TStringList.Create();
s.LoadFromFile('/proc/ioports');
Самому парсить надо, а я ленивый
alien308 писал(а):P. S. Вы ничего не видите, потому что Arduino не подсоединили! Так и задумано.
Вы о Ардуино даже и не написали. Вы спрашивали о Линух и последовательных портах. Ваш код я тестировал на PC с последовательным портом на материнской плате.
