Giter VIP home page Giter VIP logo

serial-monitor's Introduction

serial-monitor

A serial monitor for USB Serial devices, written in rust.

serial-monitor is a command line program which will connect to, and allow you to interact with USB serial devices connected to your host computer. It has been tested on Mac OSX, Linux and Windows.

You can use the --list option to display all of the detected USB serial devices, and you can use the --vid, --pid, --port, --serial, --manufacturer, or --product options to filter your list.

serial-monitor will open the first USB serial port which satifies the filtering criteria.

Once connected, you can use Control-X (or Control-Y if started with the -y option) to exit from serial-monitor and return you to your prompt.

Installation

Install rust. The recommended way is to use rustup.

Once rust is installed you can install directly from crates.io by using:

cargo install serial-monitor

This installs serial-monitor into ~/.cargo/bin

If you want to build and install from source locally, then clone the repository:

git clone https://github.com/dhylands/serial-monitor.git
cd serial-monitor

You can then build and install serial-monitor using:

cargo install --path .

This will build serial-monitor and install it into ~/.cargo/bin

Usage

$ serial-monitor --help
serial-monitor 0.0.5

USAGE:
    serial-monitor.exe [FLAGS] [OPTIONS]

FLAGS:
    -y               Exit using Control-Y rather than Control-X
    -d, --debug      Turn on debugging
    -e, --echo
    -f, --find       Like list, but only prints the name of the port that was found. This is 
                     useful for using from scripts or makefiles
    -h, --help       Prints help information
    -l, --list       List USB serial devices which are currently connected
    -V, --version    Prints version information
    -v, --verbose    Turn on verbose messages

OPTIONS:
    -b, --baud <baud>                    Baud rate to use [default: 115200]
        --databits <databits>            Data bits (5, 6, 7, 8) [default: 8]
        --enter <enter>                  Enter character to send (cr, lf, crlf) [default: cr]
        --flow <flow>                    Flow control (none, software, hardware) [default: none]
        --index <index>                  Return the index'th result
    -m, --manufacturer <manufacturer>    Filter based on manufacturer name
        --parity <parity>                Parity checking (none, odd, even) [default: none]
        --pid <pid>                      Filter based on Product ID (PID)
    -p, --port <port>                    Filter based on name of port
        --product <product>              Filter based on product name
    -s, --serial <serial>                Filter based on serial number
        --stopbits <stopbits>            Stop bits (1, 2) [default: 1]
        --vid <vid>                      Filter based on Vendor ID (VID)

The --list (or -l) option will list all of the connected USB Serial Adapters, for example:

$ serial-monitor --list
USB Serial Device f055:9800 with manufacturer 'MicroPython' serial '336F338F3433' product 'Pyboard Virtual Comm Port in FS Mode' found @/dev/cu.usbmodem336F338F34332
USB Serial Device 0403:6001 with manufacturer 'FTDI' serial 'A700e6Lr' product 'FT232R USB UART' found @/dev/cu.usbserial-A700e6Lr

Monitoring the serial port

To connect to the MicroPython board (assuming the list shown above), you might do: serial-monitor -m Micro or perhaps serial-monitor --vid f055. You can experiment with filtering options by combining with the --list option which will only show you the USB Serial Adapters which match the filter criteria.

Once you're connected you should see something like the following:

Connected to /dev/cu.usbmodem336F338F34332
Press Control-X to exit
MicroPython v1.11-47-g1a51fc9dd on 2019-06-18; PYBv1.1 with STM32F405RG
Type "help()" for more information.
>>> 

To exit from serial-monitor use Control-X (or Control-Y if you started with the -y option). Using Control-X allows characters like Control-C and Control-D to be passed on to the device on the serial port.

Filtering ports

You can use the --vid, --pid, --port, --serial, --manufacturer, or --product options to filter the selection of the serial ports. All of these options allow the use of * or ? wildcards. Note that you'll probably need to quote these to prevent your shell from expanding them. * means to match 0 or more characters and ? means to match one character. If you don't specify any wildcards then it is assumed that there is a * at the beginning and the end of the string. So --product FS will behave as if you had typed --product '*FS*'.

The --index option can be used to return the index'th result. This is useful for devices like the Black Magic Probe which return multiple serial ports which all have identical attributes.

Finding ports from within a script

The --find option behaves very similary to the --list command, but it only displays the port name of the first port found.

For example, serial-monitor --list might show:

USB Serial Device 1d50:6018 with manufacturer 'Black Sphere Technologies' serial '7ABA4DC1' product 'Black Magic Probe' found @/dev/cu.usbmodem7ABA4DC11
USB Serial Device 1d50:6018 with manufacturer 'Black Sphere Technologies' serial '7ABA4DC1' product 'Black Magic Probe' found @/dev/cu.usbmodem7ABA4DC13

and the command serial-monitor --find --product 'Black Magic Probe' --index 0 would show:

/dev/cu.usbmodem7ABA4DC11

This can be quite useful from within a script:

GDB_PORT = $(serial-monitor --find --product 'Black Magic Probe' --index 0)
arm-none-eabi-gdb -ex 'target extended-remote ${GDB_PORT}' -x gdbinit myprogram.elf

Supporting Home/End keys on Mac OS

On the regular Mac keyboard Fn-Left generates ESC [ H (which corresponds to Home) and Fn-Right generates ESC [ F (which corresponds to End). For some reason, pressing the Home and End keys on an external keyboard are mapped to ESC O H and ESC O F and crossterm wasn't reporting any events when these keys were pressed. If you go into Terminal->Preferences, select your Profile and then the Keyboard tab, you can change Home from ESC O H to be ESC [ H and End from ESC O F to be ESC [ F then the Home and End keys are reported properly via crossterm. Here's a picture of what the Home and End keys look like in the Keyboard tab:

Home/End

This has the nice side-effect of making the Home/End keys work properly in bash in the Mac's Terminal window as well.

serial-monitor's People

Contributors

cr1901 avatar davehylands avatar dependabot[bot] avatar dhylands avatar n3xed avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

serial-monitor's Issues

Unable to read non-utf8 data on windows

❯ serial-monitor -e
Connected to COM14
Press Control-X to exit
thread 'main' panicked at 'failed printing to stdout: Windows stdio in console mode does not support writing non-UTF-8 
byte sequences', library\std\src\io\stdio.rs:1009:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I need to read non-utf8 data because I'm getting raw binary data from my serial device (it is printing defmt-encoded bytes) and then want to pipe that output to another program to decode the bytes.

How can I achieve this?

Plans for GitHub releases

Hi, is there any plans for GitHub releases? Thanks. I could probably help with some GitHub action workflows

Wait/loop mode

I'm using serial-monitor to do microcontroller development, and it's common for my serial device to appear and re-appear many times while I try different versions of my code. It would be useful to be able to start serial-monitor before my serial device is available, and have it attach to the next matching device.

Additionally, while in this "wait" mode, it would be useful to optionally go back to wait mode when the device disconnects. Then when the device re-connects, serial-monitor would automatically reconnect. This way I could leave serial-monitor running constantly while I reprogram and restart my microcontroller.

Out of Bounds Issues on Malformed Input

I recently tried to read a devices UART and did not get the settings right on the first try. This lead to following error

�thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/serial-monitor-0.0.7/src/string_decoder.rs:58:31

This lead to serial-monitor crashing. The right side of the assignment seems to cause the issue.

buf[*index] = src.split_to(1)[0];

Create releases on GitHub

This crate has versions published on crates.io but no tags/releases are created on GitHub. Do you mind adding them? It is required for distros to properly package elf2uf2-rs 🐻

Symlinks Unsupported

Passing a symlink path instead of the actual port return the error: No USB serial ports found.

A common occurrence of this would be using the /dev/serial/by-id or /dev/serial/by-path symlinks to always connect to the same device regardless of how they enumerate.

E.g. /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTAV1YOK-if00-port0 is a symlink pointing to /dev/ttyUSB1.

Invoking serial-monitor with the arguments -b 115200 -p /dev/ttyUSB1 works fine, where as with the arguments -b 115200 -p /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTAV1YOK-if00-port0, the error No USB serial ports found is returned.

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.