Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for waiting for the serial port and reconnecting after the device is closed #122

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

IsaacJT
Copy link

@IsaacJT IsaacJT commented Oct 21, 2020

If configured with inotify support in the Makefile, picocom will wait for the serial port to appear rather than immediately exiting.

As inotify is only available on Linux, this functionality will only be activated when running under Linux.

IsaacJT and others added 4 commits October 21, 2020 22:40
If configured with inotify support, picocom will wait for the serial
port to appear rather than immediately exiting.
- When tty device is lost, the application will now notice and try to reconnect.
Add support for reconnecting to lost tty device.
@IsaacJT IsaacJT changed the title Added support for waiting for the serial port Added support for waiting for the serial port and reconnecting after the device is closed Oct 26, 2020
5frank added a commit to 5frank/spcom that referenced this pull request Feb 10, 2021
wait similar to what was suggested here: npat-efault/picocom#122
@wsakernel
Copy link

Hmm, can't this be achieved outside picocom with 'inotifywait'? The added code is not small and not portable, so I'd like to keep the solution to this problem in the scripts calling picocom.

@s-light
Copy link

s-light commented Jan 1, 2024

@wsakernel can you give me a hint how to do something like this with inotifywait ?
i have no idea - the examples i found all seem very complex..

i tested with

#!/bin/bash
inotifywait -m /dev --include 'ttyACM0' |
    while read dir action file; do
        echo "The file '$file' appeared in directory '$dir' via '$action'"
        # do something with the file
        # picocom /dev/ttyACM0 --baud 115200; 
    done

and for my device get

$ pico_.sh 
Setting up watches.
Watches established.
The file 'ttyACM0' appeared in directory '/dev/' via 'ATTRIB'
The file 'ttyACM0' appeared in directory '/dev/' via 'DELETE'
The file 'ttyACM0' appeared in directory '/dev/' via 'CREATE'
The file 'ttyACM0' appeared in directory '/dev/' via 'ATTRIB'
The file 'ttyACM0' appeared in directory '/dev/' via 'ATTRIB'
The file 'ttyACM0' appeared in directory '/dev/' via 'CLOSE_NOWRITE,CLOSE'
The file 'ttyACM0' appeared in directory '/dev/' via 'ATTRIB'
The file 'ttyACM0' appeared in directory '/dev/' via 'DELETE'
The file 'ttyACM0' appeared in directory '/dev/' via 'CREATE'
The file 'ttyACM0' appeared in directory '/dev/' via 'ATTRIB'
The file 'ttyACM0' appeared in directory '/dev/' via 'ATTRIB'
The file 'ttyACM0' appeared in directory '/dev/' via 'CLOSE_NOWRITE,CLOSE'

so i would have no idea what event i should use...
maybe the CLOSE_NOWRITE,CLOSE...

@s-light
Copy link

s-light commented Jan 1, 2024

just found your example at
https://gitlab.com/wsakernel/picocom/-/issues/2

#!/bin/sh
port="${1:-/dev/ttyUSB0}"
while :; do
	picocom "$@"
	inotifywait -qq -e attrib --include="$(basename $port)" "$(dirname $port)"
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants