Git Product home page Git Product logo

simpleusbterminal's Introduction

Codacy Badge

SimpleUsbTerminal

This Android app provides a line-oriented terminal / console for devices with a serial / UART interface connected with a USB-to-serial-converter.

It supports USB to serial converters based on

  • FTDI FT232, FT2232, ...
  • Prolific PL2303
  • Silabs CP2102, CP2105, ...
  • Qinheng CH340, CH341

and devices implementing the USB CDC protocol like

  • Arduino using ATmega32U4
  • Digispark using V-USB software USB
  • BBC micro:bit using ARM mbed DAPLink firmware
  • Pi Pico
  • ...

Features

  • permission handling on device connection
  • foreground service to buffer receive data while the app is rotating, in background, ...
  • send BREAK
  • show control lines
  • RTS/CTS, DTR/DSR, XON/XOFF flow control

Credits

The app uses the usb-serial-for-android library.

Motivation

I got various requests asking for help with Android development or source code for my Serial USB Terminal app. Here you find a simplified version of my app.

simpleusbterminal's People

Contributors

kai-morich avatar phcoder 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  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  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

simpleusbterminal's Issues

feature request: add network based api for serial port access automation

hello

please add function to start, when connected, server on localhost or abstract unix socket which will give access to this port for there clients.

with this server it will be possible to access such port from apps like termux, in which it is difficult to use your backend library directly.

registrator mode

It would be great to implement a data stream transfer mode from the device over the network. I have a compatible device - an emg sensor, I want to make a script on the server for signal processing, and when certain events occur, play an audio file. Although, probably, I will have to master java programming for android)))

Strange characters on terminal after sending command

Hello. I am using the app and can connect to the PL2303 device. I have set the baud rate to 115200.

When I send my hex commands F6 30 01 0A 31 6F the terminal prints strange characters. Ex: ?^A^A^@?o

Any ideas what I am doing wrong? Thanks.

Serial USB Terminal displays unknown device on USB Devices page

Screenshot_20200713_111356_de kai_morich serial_usb_terminal
Hi, there is no problem in using the Serial USB Terminal, but I failed to use the Simple Usb Terminal.
Can you tell me what the OK button do in Serial USB Terminal?
If you can give me some codes about OK button's operation to refer to is better.
Thank you.

unable to set setReadTimeout and setWriteTimeout

I am using mik3y/usb-serial-for-android library

but the data I am receiving is in single characters I tried to set setReadTimeout like this but its not working.

mSerialIoManager = new SerialInputOutputManager(port, mListener);
mSerialIoManager.setReadTimeout(200);

Error: "Connection failed: Setting baudrate failed: result=‑1" ESP32

I am no longer to connect Serial USB Terminal to my ESP32 DevKitC-V4 using my Samsung Galaxy S9 running Android 10.0. My ESP32 uses a CP2102N UART module. I am positive it worked before but now I can't get it connected. I get the following error:
Connection failed: Setting baudrate failed: result=‑1
I don't remember when it last worked, but my ESP8266 which uses a CP2102 UART module works fine. I also tried a couple other USB Terminal Apps from the Google Play store such as "Pytool USB Serial" which work fine but aren't as nice as your app. I've tried different cables and adapters, but nothing works. I have the baud rate and other serial settings set correctly as 115200, 8-N-1.

[guidance] Garbage data received from device

I'm trying to use your code in a project of mine.
I'm able to connect to my device but unable to receive data. I have no clue of what is going wrong:

Here is my Listener:


private final ExecutorService mExecutor = Executors.newSingleThreadExecutor();
private SerialInputOutputManager mSerialIoManager;

private final SerialInputOutputManager.Listener mListener = new SerialInputOutputManager.Listener() {
        @Override
        public void onRunError(Exception e) {
            Log.d(TAG, "Runner stopped.");
        }

        @Override
        public void onNewData(final byte[] data) {
            Log.d(TAG, "received " + data.length +" bytes of data from usb device");
            if (data.length > 0) {
                ReactUsbSerialModule.this.emitNewData(data);
            }
        }
    };

This is how I trigger the read after being connected:

public void readDeviceAsync(String deviceId) {

        try {
            UsbSerialDevice usd = usbSerialDriverDict.get(deviceId);

            if (usd == null) {
                throw new Exception(String.format("No device opened for the id '%s'", deviceId));
            }

            mSerialIoManager = new SerialInputOutputManager(usd.port, mListener);
            mExecutor.submit(mSerialIoManager);
        } catch (Exception e) {
        }
    }

I don't know why but I'm receiving big arrays of garbage data.
The device is supposed to send me 20 bytes every second.

What could be the root cause of the problem?

Any help appreciated.

F-Droid Support

Would it possible for this application to be packaged and released on F-Droid? To the best of my knowledge, it fits with their inclusion policy, it's possible I missed something though. If you intended this as more of a proof of concept for those asking how you made it work, that's completely understandable and you can close this issue. Thank you!

Enhancement: Character based mode

Line based mode precludes interacting in important ways with many terminals. This is especially evident when using a USB keyboard. Actions such as tab completion, history search, up arrow to scroll through command history, interaction with programs that need one character at a time such as less, etc.

Asynchronous Data Reception Code

Hello Kai Morich,
Can you please tell me in which file exactly in the USB-Serial library is the asynchronous data reception code? I tried to figure out but was unable to do so. Thanks in Advance.

Problems running on android 31+

I just tried to compile this app with Android Studio 2021.2.1. The app runs however when connecting to a device it crashes with a few permissions errors:

Not sure exactly what causing this. Your app should request permissions properly from reading android documentation.

java.lang.SecurityException: User has not given 10452/de.kai_morich.simple_usb_terminal permission to access device /dev/bus/usb/001/002
        at android.os.Parcel.createExceptionOrNull(Parcel.java:2426)
        at android.os.Parcel.createException(Parcel.java:2410)
        at android.os.Parcel.readException(Parcel.java:2393)
        at android.os.Parcel.readException(Parcel.java:2335)
        at android.hardware.usb.IUsbManager$Stub$Proxy.openDevice(IUsbManager.java:1022)
        at android.hardware.usb.UsbManager.openDevice(UsbManager.java:719)
...
    java.lang.IllegalArgumentException: de.kai_morich.simple_usb_terminal: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
    Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
        at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
        at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
        at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
        at de.kai_morich.simple_usb_terminal.TerminalFragment.connect(TerminalFragment.java:275)

[Guidance] How to send 1 byte to the USB device

I need to send a command to the device that is just one byte.

For instance, I need to send 0xf2, which is supposed to tell the device to send me data at 200Hz. By default the device sends me 20 bytes at 1Hz.

I've tried \xf2 in the app, but this does nothing, meaning I'm still receiving 20 bytes à 1Hz.

Avoid restart of app without asking user for usb permission?

Hi @kai-morich
I am getting references from your library code and I must say it is a pretty awesome lightweight app. I am stuck on one change and seeking help from your side. I want to avoid the restart of the app every time whenever a device is connected. At the start of the application, a dialog appears which contains that allows the USB terminal app to always open for this device with a checkbox. I want to avoid restarting of the app every time when the app is in the foreground already. Any help will be appreciable.

Terminal is not polling

I'm connected to a device by uart using your app the communiction works but the app doesn't poll meaning the device is meant to send me a character every 10 seconds and I can't see them I can only see direct output

How to convert rs232 data to string

I have tried your applications and it works great with my weighbridge machine its shows weight in mobile device using rs232 to usb cable

I have implemented the Library mik3y/usb-serial-for-android in my flutter app and trying to receive data I am getting the data but when I try to convert the data to string it shows me random string not the weight

I tried using TextUtil file and used TextUtil.toHexString(data) function but still shows random strings not the weight of weighbridge

private final SerialInputOutputManager.Listener mListener = new SerialInputOutputManager.Listener() {

    @Override
    public void onRunError(Exception e) {
        Log.d(TAG, "Runner stopped.");
    }

    @Override
    public void onNewData(byte[] data) {
        runOnUiThread(() -> {
            if (m_EventSink != null) {
                // String msg = new String(data);
                m_EventSink.success(TextUtil.toHexString(data) + '\n');
            }
        });
    }
};

when I am using
var msg = String(data)
it stops the app how can I solve this issue please let me know.

[Feature Suggestion] store buffer before clearing when filled

Hey, thanks for building a pretty good software, it really works with the USB otg device and a serial converter on my phone.

I would like to leave the phone connected to an appliance that's continuously sending information, in a csv file like output, with a new "row" being output each five seconds, unattended. For this, a minimal implementation I can think is once a buffer is filled it would write a file to the phone storage and start a new buffer. I would use it to leave the phone connected to it for two or more days, and pick it up later.

Android 10-11 does not recognize USB

The driver does not work for a FTDI RS232 cable. I've tries in Android 10 and 11 in some differents terminals and does not work.

I've also tried with Simple USB Terminal with no luck.

Is there any new driver or something to use it with the new Android Version?

Cannot find symbol variable APPLICATION_ID

Hi there,
Thanks a lot for this app source code, much appreciated.
I was wondering if this app can read and show serial data from a serial device like the Serial USB Terminal app.

I tried to open the app source code package on Mac OS X based Android Studio 4.1.2 and have got this classpath set in the build.gradle for the project: com.android.tools.build:gradle:4.1.2

But The Constants.java file returns this build failed error

/SimpleUsbTerminal-master/app/src/main/java/de/kai_morich/simple_usb_terminal/Constants.java:8: error: cannot find symbol
static final String INTENT_ACTION_GRANT_USB = BuildConfig.APPLICATION_ID + ".GRANT_USB";
^
symbol: variable APPLICATION_ID
location: class BuildConfig

This occurs for the Constants.java file lines 9-11 also.

What should be the gradle plugin version to use? It seems some solutions stated online by others for other projects states to downgrade the gradle version. But does not help, same issue occurs.

Would be grateful if there is a solution for this as I would like to run and edit the app using Android Studio or any other IDE.

Thanks, Pratik

Arduino UNO R3 not detected on Samsung S20 and S8

The Serial USB Terminal app seems to work on my Lenovo TB8504F (Android 7.1.1). But both Samsung S20 (Android 11) and Samsung S8 (Android 9) are not able to see the device. The device is Arduino UNO R3 in CDC ACM mode. How can I make the app to work on S8 and S20? Is there some kind of permission I need to know? Thank you

permission handling on device connection

If the phone is rebooted, but the cable remains plugged in, and then the app is opened, the pop up will come back.
If the USB cable is unplugged, upon replugging the pop up does not come back.
However, if the app is closed, but the cable remains plugged in, and then the app is reopened, the pop up does not come back.

Newline error

Hi,
Ive been using your Android app SerialUSBTerminal for a while and had a few thoughts on how I would like to use it so I came here. So far this repo is good enough for what I need, theres just one problem that maybe you can help me with. When I send a message longer than one line of an Android screen, it then cuts the message into pieces. For example, if two lines are sent then two separate messages are sent. The index of the messages are changed when this happens too.
example=
msg ="hello world,hello world,hello world,hello world,hello world,hello man"
name = msg[0]= h //for first line
name = msg[0] = m // for second line
Ive looked through all the code to fınd where this problem might be, but to no avail.
On the Android app, there is no problem like this, so Im wondering where the difference is here.
I would really appreciate any help. Thanks.

Ayuda. No Puedo correrlo en Android Studio.

De pronto suena muy básico pero no soy experto en el uso de este aplicativo android studio, alguien me puede colaborar con los pasos para poder correrlo y emularlo en android studio. lo he intentando y me sale un error "Error: Module not specified".

Apenas llevo 4 días usando android studio.

de antemano agradezco su atención.

No Device Recognize in Android 10

I am using Android 10. I am trying to attach the USB device using an OTG adapter to the app. No USB device message appears and no device shows in the list of USB devices.

The USB device shows When I run this app Below Android 10.

Tells that there is no driver

I'm surprised that this app says that there is no driver for my USB device.
It works well with the Serial Usb Terminal App:
Connected to CDC device
Data is received perfectly.

No Driver found for Cp210x

Hi I am Trying to connect Cp210x to my Android device when I install this app and tried to connect device it does detect USB but it says No Driver.

Start service from Activity

Hi,

I am trying to start the service from an Activity, but OnServiceConnected never gets called. Any idea?

PL230 - SerialUSB Gets Data Reply, SimpleUSB connects but fails to get Data reply

Playstore App SerialUsbTerminal with BaudRate 9600, HEX Mode and CR+LF connects to PL2303 USB device and sends data to our BMS device and receives output too. Attaching pics for reference.

However, the same SimpleUSB - We jus cloned the repo and built the app - set BaudRate to 9600 is connecting and sending but not able to receive the output. What could be the reason ? How can we test easily using emulator ?

WhatsApp Image 2020-07-29 at 6 33 26 AM
WhatsApp Image 2020-07-29 at 6 33 27 AM (1)
WhatsApp Image 2020-07-29 at 6 33 27 AM (2)
WhatsApp Image 2020-07-29 at 6 33 27 AM
WhatsApp Image 2020-07-29 at 6 30 28 AM
WhatsApp Image 2020-08-02 at 7 47 40 PM

application wont start issue when i deploy to my phone

I had downloaded your code and made clean build succesfully but when i tried to deploy to my device the apk , it was installed but there is error about it. When beginning the application crashes.

2019-05-27 12:40:08.141 8725-8725/de.kai_morich.simple_usb_terminal E/AndroidRuntime: FATAL EXCEPTION: main
Process: de.kai_morich.simple_usb_terminal, PID: 8725
java.lang.RuntimeException: Unable to start activity ComponentInfo{de.kai_morich.simple_usb_terminal/de.kai_morich.simple_usb_terminal.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f080059
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3086)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3229)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6981)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f080059
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:228)
at android.content.res.Resources.getValue(Resources.java:1346)
at android.support.v7.widget.AppCompatDrawableManager.createDrawableIfNeeded(AppCompatDrawableManager.java:235)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:200)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191)
at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:753)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:196)
at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:86)
at android.support.v7.app.AppCompatDelegateImpl.(AppCompatDelegateImpl.java:260)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:182)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:520)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
at de.kai_morich.simple_usb_terminal.MainActivity.onCreate(MainActivity.java:12)
at android.app.Activity.performCreate(Activity.java:7326)
at android.app.Activity.performCreate(Activity.java:7317)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3066)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3229) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:214) 
at android.app.ActivityThread.main(ActivityThread.java:6981) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445) 

Can this APP work with the device running as a USB Device

Thank you for this project! I've tried this app with the device it is running on acting as a USB Host and it works great! However, when I run the app with the device it is running on acting as a USB device, it shows no device connected.

I was wondering if the app supports this use case?

the code is not upto date with the app

The code is not upto date with the app the newline names and newline values have 6 fields in app but here I can only see 3

can you update it or let me know what would be value for the rest of the fields

CR+LF LF <none> \u000d\u000a \u000a

the newline values in app are
CR+LF
CR
LF
STX/ETX
NUL
None

Incorrect hex values on reading

When I use Serial USB Terminal app I am receiving correct hex value, but when I use Simple USB Terminal app the values are differnt from what I expect.

baud rate: 115200
data bits: 8
stop bits: 1
parity: none

What can be the the issue and what can be the difference?

usbSerialPort?.open(usbConnection)
            usbSerialPort?.setParameters(
                baudRate,
                UsbSerialPort.DATABITS_8,
                UsbSerialPort.STOPBITS_1,
                UsbSerialPort.PARITY_NONE
            )

userspace driver

Hello

want to use serial adapter in chroot environment (Linux Deploy).

Is there a way to attach it as /dev/ttyUSBx that others can use the adapter to?
Means any chances to apply this to generic driver?

Open project in Android Studio?

Hi @kai-morich.
This will probably look silly but I'm unable to open the project in Android Studio.
Nothing Happens when I select the folder where I downloaded the code.

Any Help appreciated.

port.read() always returning len = 0.

Upon calling len = port.read(response, READ_WAIT_MILLIS); shown in the README I was getting len=0 for a simple arduino printing the char "A" every 1000ms. I could not for the life of me figure out why my other serial terminals like CoolTerm and Arduino's IDE terminal were having no issue reading this, but my Android code was. The connection, device, port, etc. all looked to have reasonable values when inspected with an inline debugger, and no errors were raised.

It wasn't until I dug REAL deep into SimpleUsbTerminal code to find this little hint. I dunno, maybe this is obvious to more experienced embedded engineers, but I wasted almost an entire day on this.

I saw reference to this setDTR method in the FAQ after finding it in the sample code mentioned above, but would never have thought it to be relevant based on what I was seeing. Not sure how large a percentage your user base is for Arduino, but I'd suggest adding at least a reference to this setDTR method in the README code as a requirement for any communication with an Arduino to work. So all I had to do was after the "Open Device" section of the README, add:

port.setDTR(true);

prior to writing/reading. Hopefully this issue helps others at the very least. Or maybe I've misunderstood something and this is not the approach I should even be taking?

Help to insert the values

Hello.
I am trying to use this app to send a command to a device connected to an USB port.
Thanks to the app i can see the device but i do not understand how i need to insert the byte to execute the command.
I need to send 186 2 1 185.
Could you please explain me how to do that?

Mobile app shutdown as soon as I remove the microusb

I am using rs232 to usb and receiving data from it.

sometimes when receiving the data and I remove the cable the mobile shutdown. I am facing it both with your app and the app that I am trying to develop how can I solve it.

Thanks

wrong data received about the newline

Hello, here when I send a command, I expect to receive related info from the USB, however, the result returns always "invalid command" which means the usb read invalid command.

image

but interesting thing is: I also tried the Serial Usb Terminal APP:
the first time I tried, it returned the same string "invalid command":
image

the I changed the receive newline value from CR+LF to CR
image

and the result was still invalid command
image

then I changed back the receive newline value from CR to CR+LF, tried it again, I got the correct response!

image

Can anyone help me to solve this issue ?

Thanks

Cannot connect to Arduino Leonardo

Trying to connect app to Arduino Leonardo through USB but getting the following error: "Could not clam control interface". What does this mean?

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.