Giter VIP home page Giter VIP logo

Comments (23)

npat-efault avatar npat-efault commented on August 15, 2024 5

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.

npat-efault avatar npat-efault commented on August 15, 2024 3

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.

ElectricRCAircraftGuy avatar ElectricRCAircraftGuy commented on August 15, 2024 1

@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.

npat-efault avatar npat-efault commented on August 15, 2024

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.

npat-efault avatar npat-efault commented on August 15, 2024

Also, picocom does not "execute commands". Picocom configures serial ports, sends stuff to them, and receives stuff from them...

from picocom.

npat-efault avatar npat-efault commented on August 15, 2024

I hope I answered your question...

from picocom.

alexzaitsev avatar alexzaitsev commented on August 15, 2024

@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.

npat-efault avatar npat-efault commented on August 15, 2024

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.

alexzaitsev avatar alexzaitsev commented on August 15, 2024

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.

npat-efault avatar npat-efault commented on August 15, 2024

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.

alexzaitsev avatar alexzaitsev commented on August 15, 2024

@npat-efault got it! Thanks again

from picocom.

alexzaitsev avatar alexzaitsev commented on August 15, 2024

@npat-efault yeah, it works! Could I grab terminal output also in some way?

from picocom.

alexzaitsev avatar alexzaitsev commented on August 15, 2024

and one more question: what 'q' option means? cannot find it in the help

from picocom.

npat-efault avatar npat-efault commented on August 15, 2024

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.

npat-efault avatar npat-efault commented on August 15, 2024

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.

alexzaitsev avatar alexzaitsev commented on August 15, 2024

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.

npat-efault avatar npat-efault commented on August 15, 2024

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.

alexzaitsev avatar alexzaitsev commented on August 15, 2024

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.

npat-efault avatar npat-efault commented on August 15, 2024

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") in cmd.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.

bbatten1 avatar bbatten1 commented on August 15, 2024

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.

bakhretdino avatar bakhretdino commented on August 15, 2024

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.

omkumar1979 avatar omkumar1979 commented on August 15, 2024

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.

armtir avatar armtir commented on August 15, 2024

For AT commands use:

echo -ne "$ln\r" 

from picocom.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.