Comments (23)
Another, slightly more elaborate, example could be something like this:
#!/bin/bash
# barf on error
set -e
# configure port, exit immediately, don't reset
picocom -qrX -b 115200 ... other settings ... /dev/ttyS0
# send contents of cmd.txt, line by line,
# waiting 1 sec in-between, after host sends reply
while read ln; do
echo "$ln" | picocom -qrix 1000 /dev/ttyS0
done < cmd.txt
Caveats mentioned above still apply here, of-course. So it may, or may-not, be what you want. Again, as things get more complicated, you may consider other, better suited, tools (possibly together with picocom)...
from picocom.
As a hypothetical example (and only as such): A simple thing you could do would be smth like:
cat cmd.txt | picocom -qrx 1000 /dev/ttyS0 > foo.txt
This will open and configure the port, write the contents of cmd.txt
to the port, write anything comming from the port to foo.txt
, until the line becomes idle for 1 sec... It will then close the port, without resetting it, and exit. You would of-course have to also think about line terminations (CR vs LF vs CRLF) and decide if some mapping is required, and so on...
Is this what you want? I have no idea...
from picocom.
@omkumar1979 , try my personal picocom
installation instructions here: https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/blob/master/useful_apps/serial_terminals_README.md#installation
Let me know if they work for you.
from picocom.
You have to think of exactly what you want to achieve, and see if it is possible or not (and how) using picocom and/or other commands. There are tools for scripting complex interactions with host systems, maybe better suited than picocom, or that could be used together with picocom...
What does it mean to send commands "line by line"? Wait a certain amount of time between lines? Wait for a response after each line? Check the response? What about remote echo? You can certainly blast the contents of the file to the port using picocom. You could maybe do it with multiple invocations of picocom, one per line. Maybe this is what you want, but maybe not. Depends on exactly what you want to achieve. There is detailed doc about how picocom behaves, so you should figure it out.
Keep in mind that picocom is primarily for interactive operations, and only very trivial non-interactive stuff. It is not a tool for scripting complex interactions (like "chat", or "expect", or others), though it could be used together with them (e.g. configure the port, possibly allow some manual interaction, and then hand over the scripted interaction to them)
from picocom.
Also, picocom does not "execute commands". Picocom configures serial ports, sends stuff to them, and receives stuff from them...
from picocom.
I hope I answered your question...
from picocom.
@npat-efault yep, thank you so much, that's exactly I what needed.
I've tried to run your script but got an error:
Unrecognized option(s)
Run with '--help'.
Could you help me a bit more?
from picocom.
Did you copy the script verbatim? There is a figurative ... other settings ...
in it, which you should obviously remove. If this is not the problem then make sure you are using the latest release of picocom (or the tip from git). Anything before 3.0 will not do.
from picocom.
I use this one:
#!/bin/bash
# barf on error
set -e
# configure port, exit immediately, don't reset
picocom -qrX -b115200 /dev/$(ls /dev | grep cu.wchusbserial)
# send contents of cmd.txt, line by line,
# waiting 1 sec in-between, after host sends reply
while read ln; do
echo "$ln" | picocom -qrix 1000 /dev/$(ls /dev | grep cu.wchusbserial)
done < cmd.txt
and picocom v2.2
from picocom.
Ah, picocom 2.2 will not do! Get 3.0, or the tip from git. The non-interactive options (like -x
and -q
and -X
) were added after 2.2.
from picocom.
@npat-efault got it! Thanks again
from picocom.
@npat-efault yeah, it works! Could I grab terminal output also in some way?
from picocom.
and one more question: what 'q' option means? cannot find it in the help
from picocom.
Sure, replace:
echo "$ln" | picocom -qrix 1000 /dev/ttyS0
with something like:
echo "$ln" | picocom -qrix 1000 /dev/ttyS0 >> output.txt
or (if you want to capture to a shell variable):
output=$(echo "$ln" | picocom -qrix 1000 /dev/ttyS0)
Keep in mind, though, that this will capture all output (incl. the remote echo)
from picocom.
Ooops, your right! Option -q
is missing from the help message. It is, though, in the manual. It means --quiet
(see man for details).
from picocom.
Thanks! Eventually i have
#!/bin/bash
# barf on error
set -e
# configure port, exit immediately, don't reset
picocom -qrX -b115200 /dev/$(ls /dev | grep cu.wchusbserial)
# send contents of cmd.txt, line by line,
# waiting 1 sec in-between, after host sends reply
while read ln; do
echo "$ln" | picocom -qrix 1000 /dev/$(ls /dev | grep cu.wchusbserial) >> output.txt
done < cmd.txt
cmd.txt:
print("hello")
It is executed smoothly but output.txt
is still empty..
from picocom.
It works fine with me, as it should. Even without the redirection to output.txt
you should see: the print("hello")
command (remote echo), the hello
output, and the next prompt. Are you sure the command is executed?
from picocom.
Finally I managed to find a 'right' way of copying a file. It's ampy.
Anyway thanks for a quick response, I wish such support to all open-sourced products!
from picocom.
I do this:
- Connect with picocom, interactively, to a logon serial port (running getty).
- Login, and get a shell prompt
- Start a python REPL
- Quit picocom (w/o reset) leaving python REPL running
- Run the script show above (with a single
print("hello")
incmd.txt
The contents of output.txt
are, exactly:
print("hello")
hello
>>>
without a newline at the end, as it should. I don't know what goes wrong in your case, but it is certainly not picocom-related. It probably has something to do with the specific python REPL running on your board and how it interprets input (e.g. CR vs LF issues, or something like that? I don't know...)
from picocom.
npat-efault:
Thanks for the script! It solves a problem I've been working on for most of this week. Just goes to show that four days experimenting is as good a a half hour in the library any day.
Thanks again,
from picocom.
Hello!
Thanks for the solution.
I faced one problem, not sure if it's related with this topic. echo into picocom terminal doesn't work properly.
For example, I run: echo "hello" | picocom -qrix 100 $PATH_TO_DEV
, and picocom terminal receives "hlo". So basically it swallows every other character. Any idea how to fix that?
Thank you!
from picocom.
Ah, picocom 2.2 will not do! Get 3.0, or the tip from git. The non-interactive options (like
-x
and-q
and-X
) were added after 2.2.
unable to upgrade picocom to v3.0. pl. let me know the alternate way (tip from git.) as mentioned above.
from picocom.
For AT commands use:
echo -ne "$ln\r"
from picocom.
Related Issues (20)
- automated scripts for picocom on VT10 modem but only first line is working
- Documentation should be more clear on "Escape" keys C-a is "Ctrl-a" HOT 1
- Changeable default options aka config file HOT 7
- How to exit help message HOT 2
- New feature proposal: cache input command & save them as history HOT 1
- Cycle through charge and off using picocom from command line
- Feature Request: Support Canonical Input Mode HOT 1
- Add ability to print lines with timestamp HOT 4
- Typo in man page for C-u (Baud up) HOT 1
- picocom fails HOT 2
- Maintainer disappeared, I'll collect fixes meanwhile HOT 1
- Picocom send/receive fails due to dependency. HOT 1
- Typo in --exit-after option error message HOT 1
- New upstream (until Nick comes back) HOT 1
- Toggle of DTR and RTS is swapped !
- Assertion failure always hit when using ignlf or igncr HOT 1
- how to intall on windows HOT 1
- picocom v3.1 c-a c-w closes file/window HOT 1
- picocom requires STDIN?
- Backspace key sends [DEL](127) instead of [BACKSPACE](8) HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from picocom.