Menu
JAQForum Ver 19.10.27

Forum Index : Microcontroller and PC projects : serial port watcher - linux 64-bit

Posted: 02:35pm
23 Apr 2020
Copy link to clipboard
robert.rozee
Guru

here's a handy little utility that linux should really have built in:

Serial Watcher (24-april-2020).zip

it is a 64-bit GUI program that creates a small window (about 150 pixels wide) on the desktop showing all the 'live' serial ports on the machine. these are serial ports that are real, working, with a device driver associated. as ports are plugged, they will be added to the window, as they are unplugged they will be removed.

it looks like this sitting on the empty desktop:


the executable is enormous (3mb) because of the lazarus GUI runtime engine. i shall ponder on how best to get around this in a future version. essentially, the only GUI component is a single TMemo sitting on an otherwise blank TForm. i feel it may well be possible to roll this in a more diy fashion for a considerably smaller executable!

please let me know how it works  

cheers,
rob   :-)
 
Posted: 03:43pm
23 Apr 2020
Copy link to clipboard
Volhout
Guru

Hi Robert,

yes, I like.... especially if it can be made universal and small.

I am curious, how do you get the status ?
For USB ports I usually do an ls /dev/ttyA* or ls /dev/ttyU*
But to find an active ttyS* from the zillions in the list is a bridge to far for me.

Regards,

Vollhout
If nothing goes right ... turn left
 
Posted: 09:51am
24 Apr 2020
Copy link to clipboard
cs41
Newbie

Hi Robert,

Great little program and just what I have needed for so  long.
Easy to use...  and gets results quickly.
Sure ..  we can use the command line, and often do, but this is simpler.
Runs well on my Mint 19.3  system.

Many thanks for that.  I'm sure it will be appreciated by many Linux users.

cs.
 
Posted: 09:52am
24 Apr 2020
Copy link to clipboard
cs41
Newbie

Hi Robert,

Great little program and just what I have needed for so  long.
Easy to use...  and gets results quickly.
Sure ..  we can use the command line, and often do, but this is simpler.
Runs well on my Mint 19.3  system.

Many thanks for that.  I'm sure it will be appreciated by many Linux users.

cs.
 
Posted: 02:11pm
24 Apr 2020
Copy link to clipboard
robert.rozee
Guru

the inner workings are, in principal, surprisingly simple.

for each entry in /dev that is a serial port (ie ttyXXXn), there exists a corresponding entry in /sys/class/tty with further directories existing below that entry. the one of interest is of the form:

/sys/class/tty/NAME/device/driver
where NAME is the device name from /dev

for example, for /dev/ttyACM0 there exists /sys/class/tty/ttyACM0/device/driver

now /sys/class/tty/NAME/device/driver is a symlink to the actual driver, and we use a kernel (?) call to extract from /sys/class/tty/NAME/device/driver the true name of the device driver.

if the true name is NOT "serial8250", we can assume that the entry in /dev is alive, and our work is done. we can move on to the next entry.

however, if the device driver name is "serial8250", we then need to do a fileopen on the entry in /dev and call ioCtl to check that the driver type is not 0 (PORT_UNKNOWN).


in the case of my desktop machine, there exists on the motherboard a serial port, which appears as /dev/ttyS0. however, the driver is NOT called "serial8250", with the port implemented by an I2C device. so we can't assume that every /dev/ttyS* is an old-style 8250/16550 serial port!


on startup, the "watcher" scans /sys/class/tty/tty*, and for each entry found that meets the above criteria adds the NAME to the TMemo displayed. it then sets up a watch on /dev for any changes (items added or removed).

when a change occurs:
1. if the NAME is in the TMemo, it is removed.
2. the above check is done on NAME, and if it passes then NAME is added back into the TMemo.


hopefully this makes it all as clear as mud! i'd suggest having a look at the file "unit1.pas" that contains all the code that implements this. while looking intimidating, it is a series of quite simple steps.


cheers,
rob   :-)
 
Posted: 02:15pm
24 Apr 2020
Copy link to clipboard
robert.rozee
Guru

cs41: am glad the program is useful for you     to be honest, i'm amazed that something similar doesn't already exist. i guess it comes down to the problem that the people who develop linux are just a little too involved in the technicalities of it all to appreciate the plight of the 'common user on the street', who really just wants simple solutions.


cheers,
rob   :-)
 
Posted: 02:58pm
24 Apr 2020
Copy link to clipboard
CircuitGizmos
Guru


This is my version for Windows. I usually keep it running.



It is great that you created one for Linux. Well done!
Micromites and Maximites! - Beginning Maximite
 
Posted: 02:59pm
24 Apr 2020
Copy link to clipboard
JohnS
Guru

rob,

Or the common user really doesn't use ttyACM0 etc :)

Hardly anyone plugs hardware in... sad, isn't it...

I tend to look at dmesg | tail when I plug anything in (usually get /dev/ttyUSB0).

John
Edited 2020-04-25 01:00 by JohnS
 
Posted: 03:09pm
24 Apr 2020
Copy link to clipboard
Volhout
Guru

Dear Rob,

Is this nice tool something that can be adapted to something that is permanently in the tray ? Like the volume control icon, or a network icon, that once you click/hover over opens to a list of options.
That would really make it into something permanent for all developers that use a linux as their platform.

I like it as is, (and it works on my systems) but this would be even better.

Regards,

Volhout
If nothing goes right ... turn left
 


To reply to this topic, you need to log in.

© JAQ Software 2022