Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-07

How to detect serial/usb-serial ports.

10 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

P. vanderWal

Hello,

In my program I need to present the user with a list of available serial and usb-serial ports on the system they are using. How do I detect in my program these ports?. (something like GetPortList() in Delphi-7???).

One port is used by a milling-machine to receive its position and speed commands, the other port is used by a controller for switching the machine automaticaly on/off and start or end of the milling and measure and detect the roughness of the surface area of the material to be processed.

Thanks in advance,

grtjs Piet

Reply by email

John Lee
to P. vanderWal: In my program I need to present the user with a list of available serial and usb-serial…

I use the synaser unit - works for fpc 2.4, win and I think for other o/s too - google for info - it has the capability to look for serial ports, set baud rates, and to do character & block input & output.

hth John

P. vanderWal wrote 22 lines
** Hello, In my program I need to present the user with a list of available serial and usb-serial ports on the system they are using. How do I detect in my program these ports?. (something like GetPortList() in Delphi-7???). One port is used by a milling-machine to receive its position and speed commands, the other port is used by a controller for switching the machine automaticaly on/off and start or end of the milling and measure and detect the roughness of the surface area of the material to be processed. Thanks in advance, grtjs Piet _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Fabio Luis Girardi
to John Lee

Wich OS?

If Windows, you can use the function BuildCommDCB, and pass the following string as param:

COMx: baud=1200 parity=N data=8 stop=1

if COMx exists on your system, this function will return true.

See:

http://msdn.microsoft.com/en-us/library/aa363143(v=vs.85).aspx

On linux, i don't found any other way than check if exists /dev/ttyUSBx devices.

Regards,

Fabio

2011/7/27 John Lee :

Show quoted text 32 lines
I use the synaser unit - works for fpc 2.4, win and I think for other o/s too - google for info - it has the capability to look for serial ports, set baud rates, and to do character & block input & output. hth John On 27 July 2011 09:22, P. vanderWal wrote: > > Hello, > > In my program I need to present the user with a list of available serial > and usb-serial ports on the system they are using. > How do I detect in my program these ports?.  (something like GetPortList() > in Delphi-7???). > > One port is used by a milling-machine to receive its position and speed > commands, the other port is used by a controller for switching the machine > automaticaly on/off > and start or end of the milling and measure and detect the roughness of > the surface area of the material to be processed. > > Thanks in advance, > > grtjs Piet > _______________________________________________ > fpc-pascal maillist  -   > http://lists.freepascal.org/mailman/listinfo/fpc-pascal _______________________________________________ fpc-pascal maillist  -   http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Henry Vermaak
to P. vanderWal: In my program I need to present the user with a list of available serial and usb-serial…
P. vanderWal wrote 5 lines
Hello, In my program I need to present the user with a list of available serial and usb-serial ports on the system they are using. How do I detect in my program these ports?. (something like GetPortList() in Delphi-7???).

Look here for how synaser does it:

http://synalist.svn.sourceforge.net/viewvc/synalist/trunk/synaser.pas?revision=146&view=markup#l2280

For linux you can look for /dev/ttyS* and /dev/ttyUSB*, but they may be called anything in practice.

Henry

Reply by email

P.vanderWal
to Felipe Monteiro de Carvalho: For which operating system? Felipe Monteiro de Carvalho

Debian and Ubuntu

grtjs Piet

Earlier message 14 lines
----- Original Message ----- From: "Felipe Monteiro de Carvalho" To: "FPC-Pascal users discussions" Sent: Wednesday, July 27, 2011 10:39 AM Subject: Re: [fpc-pascal] How to detect serial/usb-serial ports. > For which operating system? > > -- > Felipe Monteiro de Carvalho > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Mark Morgan Lloyd
to P.vanderWal
P.vanderWal wrote 12 lines
Debian and Ubuntu grtjs Piet ----- Original Message ----- From: "Felipe Monteiro de Carvalho" To: "FPC-Pascal users discussions" Sent: Wednesday, July 27, 2011 10:39 AM Subject: Re: [fpc-pascal] How to detect serial/usb-serial ports. > For which operating system?

I'd expect (recent versions of) those to only create devices that were known to exist. I detect what's available by looking for up to 12 /dev/ttyS*, 8 /dev/ttyUSB* and 4 /dev/ttyI*, then later checking that they can actually be opened (bearing in mind that this might glitch a control line).

It's worth noting that a few weeks ago I was updating the standard serial.pp unit and noticed that Solaris designated serial ports as /dev/ttya and /dev/ttyb.

Windows of course is \COM1, or strictly \\.\COM1 etc.; I note Fabio's test but in the past have used the registry to find e.g. named ports simulated by an AVR box.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Fabio Luis Girardi
to Mark Morgan Lloyd

I'm a little curious to know how vmware workstation lists the serial ports on linux. It's the unique software that does this right that I know.

Regards,

Fabio

2011/7/27 Mark Morgan Lloyd :

Show quoted text 37 lines
P.vanderWal wrote: > > Debian and Ubuntu > > grtjs Piet > > ----- Original Message ----- From: "Felipe Monteiro de Carvalho" > > To: "FPC-Pascal users discussions" > Sent: Wednesday, July 27, 2011 10:39 AM > Subject: Re: [fpc-pascal] How to detect serial/usb-serial ports. > > >> For which operating system? I'd expect (recent versions of) those to only create devices that were known to exist. I detect what's available by looking for up to 12 /dev/ttyS*, 8 /dev/ttyUSB* and 4 /dev/ttyI*, then later checking that they can actually be opened (bearing in mind that this might glitch a control line). It's worth noting that a few weeks ago I was updating the standard serial.pp unit and noticed that Solaris designated serial ports as /dev/ttya and /dev/ttyb. Windows of course is \COM1, or strictly \\.\COM1 etc.; I note Fabio's test but in the past have used the registry to find e.g. named ports simulated by an AVR box. -- Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues] _______________________________________________ fpc-pascal maillist  -   http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

P. vanderWal
to Mark Morgan Lloyd: I'd expect (recent versions of) those to only create devices that were known to exist. I…

----- Original Message -----

Earlier message 49 lines
From: "Mark Morgan Lloyd" To: Sent: Wednesday, July 27, 2011 10:36 PM Subject: Re: [fpc-pascal] How to detect serial/usb-serial ports. > P.vanderWal wrote: >> Debian and Ubuntu >> >> grtjs Piet >> >> ----- Original Message ----- From: "Felipe Monteiro de Carvalho" >> >> To: "FPC-Pascal users discussions" >> Sent: Wednesday, July 27, 2011 10:39 AM >> Subject: Re: [fpc-pascal] How to detect serial/usb-serial ports. >> >> >>> For which operating system? > > I'd expect (recent versions of) those to only create devices that were > known to exist. I detect what's available by looking for up to 12 > /dev/ttyS*, 8 /dev/ttyUSB* and 4 /dev/ttyI*, then later checking that they > can actually be opened (bearing in mind that this might glitch a control > line). > > It's worth noting that a few weeks ago I was updating the standard > serial.pp unit and noticed that Solaris designated serial ports as > /dev/ttya and /dev/ttyb. > > Windows of course is \COM1, or strictly \\.\COM1 etc.; I note Fabio's test > but in the past have used the registry to find e.g. named ports simulated > by an AVR box. > > -- > Mark Morgan Lloyd > markMLl .AT. telemetry.co .DOT. uk > > [Opinions above are the author's, not those of his employers or > colleagues] > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal I'll use Mark's method of com-port detection in my program under linux and GetComPorts under Windows. In a few days time I'll let you know the result. Mark thank for the suggestions. grtjs Piet

Reply by email

Mark Morgan Lloyd
to P. vanderWal
P. vanderWal wrote 48 lines
----- Original Message ----- From: "Mark Morgan Lloyd" To: Sent: Wednesday, July 27, 2011 10:36 PM Subject: Re: [fpc-pascal] How to detect serial/usb-serial ports. > P.vanderWal wrote: >> Debian and Ubuntu >> >> grtjs Piet >> >> ----- Original Message ----- From: "Felipe Monteiro de Carvalho" >> >> To: "FPC-Pascal users discussions" >> Sent: Wednesday, July 27, 2011 10:39 AM >> Subject: Re: [fpc-pascal] How to detect serial/usb-serial ports. >> >> >>> For which operating system? > > I'd expect (recent versions of) those to only create devices that were > known to exist. I detect what's available by looking for up to 12 > /dev/ttyS*, 8 /dev/ttyUSB* and 4 /dev/ttyI*, then later checking that > they can actually be opened (bearing in mind that this might glitch a > control line). > > It's worth noting that a few weeks ago I was updating the standard > serial.pp unit and noticed that Solaris designated serial ports as > /dev/ttya and /dev/ttyb. > > Windows of course is \COM1, or strictly \\.\COM1 etc.; I note Fabio's > test but in the past have used the registry to find e.g. named ports > simulated by an AVR box. > > -- > Mark Morgan Lloyd > markMLl .AT. telemetry.co .DOT. uk > > [Opinions above are the author's, not those of his employers or > colleagues] > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal I'll use Mark's method of com-port detection in my program under linux and GetComPorts under Windows. In a few days time I'll let you know the result. Mark thank for the suggestions.

I was discussing this elsewhere a few days ago and a Windows developer pointed out to me that the Windows COMn names are simply a convention, and that a driver writer can choose whatever he wants. A bit of Googling suggests that HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM is worth looking at, but I don't know how portable (i.e. over different versions and variants of Windows) that is.

Google also suggests that in some cases (Bluetooth?) the registry might append a garbage character, and that possibly reading it multiple times might improve things.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email