SerialPortExample | yet complete example of an Android app | Android library

 by   felHR85 Java Version: Current License: MIT

kandi X-RAY | SerialPortExample Summary

kandi X-RAY | SerialPortExample Summary

SerialPortExample is a Java library typically used in Mobile, Android applications. SerialPortExample has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has low support. You can download it from GitHub.

A simple, yet complete example of an Android app using UsbSerial library
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              SerialPortExample has a low active ecosystem.
              It has 62 star(s) with 39 fork(s). There are 9 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              There are 4 open issues and 4 have been closed. On average issues are closed in 5 days. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of SerialPortExample is current.

            kandi-Quality Quality

              SerialPortExample has no bugs reported.

            kandi-Security Security

              SerialPortExample has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.

            kandi-License License

              SerialPortExample is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              SerialPortExample releases are not available. You will need to build from source code and install.
              Build file is available. You can build the component from source.

            Top functions reviewed by kandi - BETA

            kandi has reviewed SerialPortExample and discovered the below as its top functions. This is intended to give you an instant insight into SerialPortExample implemented functionality, and help decide if they suit your requirements.
            • Called when the service is created
            • Find the first USB device connected to the device
            • Creates and registers the VISIBLE filter for the USB device
            • Request user permission
            • Start the RestbService
            • Setup the filters for the USB device
            • Start service
            • Initializes the Activity
            • Writes data through the serial port
            Get all kandi verified functions for this library.

            SerialPortExample Key Features

            No Key Features are available at this moment for SerialPortExample.

            SerialPortExample Examples and Code Snippets

            No Code Snippets are available at this moment for SerialPortExample.

            Community Discussions

            QUESTION

            avoiding static view references but enabling a different activity to modify the views
            Asked 2019-May-08 at 23:19

            I am using UsbSerial (com.github.felHR85:UsbSerial:4.5) to stream Serial data to my app from the virtual serial port(over USB). The MainActivity has a a handler that handles the messages from the from the USB Service, similar to the example provided: https://github.com/felHR85/UsbSerial/blob/master/example/src/main/java/com/felhr/serialportexample/MainActivity.java

            My App has several Activities, and many of them have views that should change if certain data comes across the serial port. E.g., a TextView may need to update the text shown, a Button should be enabled or disabled.

            In order to manipulate the views outside of the onCreate method in each activity, the easiest thing I have tried is to declare the views as private static but I have seen in many places that this is a bad practice. I am setting the View references back to null as described here (under "2. Static Views") to, I think, avoid potential memory leaks: https://blog.nimbledroid.com/2016/09/06/stop-memory-leaks.html
            I still don't like the fact that Lint in Android Studio indicates "Do not place Android context classes in static fields." and that this practice seems generally frowned upon.

            Each activity has a public static boolean isActive that gets set true in onResume and false in onPause

            The handler from the MainActivity decides what to do with the incoming serial data depending on which activity is currently running (e.g. SecondActivity.isActive==true). It then calls a public static method from the current running activity (e.g. SecondActivity.updateViews(serialdata)) which has access to the static View reference in order to do what it needs (e.g. myTextView.setText(serialdata))

            If I shouldn't keep a static reference to a view, what are alternatives to achieving what I need, i.e. updating a view element in a SecondActivity from the handler in the MainActivity, while the SecondActivity is already running?

            ...

            ANSWER

            Answered 2019-May-08 at 23:19

            The MainActivity has a a handler that handles the messages from the from the USB Service

            This is not a good plan.

            My App has several Activities, and many of them have views that should change if certain data comes across the serial port.

            This illustrates why the not-good plan is not good. The data come from the serial port is not tied exclusively to MainActivity... so why would MainActivity be handling the USB service messages?

            (it is also fairly likely that you should not have multiple activities here and instead have one activity with multiple fragments, but I'll leave that aside for now)

            what are alternatives to achieving what I need

            I don't know what is on the other end of the serial port that is causing the messages to be sent. For the purposes of this answer, I will call it a "thingy".

            Step #1: Create a ThingyRepository. This will be a class (with a singleton instance) that manages the USB serial connection and receive the messages. It will hold onto some representation of the current state based on past messages (ThingyState) and it will update that state as new messages come in.

            Step #2: Have ThingyRepository expose some sort of "reactive API". That could be something modern, such as LiveData or RxJava. It could be something older, like a callback-based API. Either way, you want ThingyRepository to deliver updated ThingyState objects to interested parties ("observers") when the state changes. So, ThingyRepository converts USB serial messages into updated states, and it emits those states as needed.

            Step #3: Have your UI observe ThingyRepository, receive the ThingyState objects, and update the UI based on those states. Ideally, you would use ViewModel to mediate those communications, to deal with Android's configuration changes (screen rotations, etc.). But, if you wanted to stay "old-school", the activity could register a callback with your ThingyRepository, where ThingyRepository can call the callback with a fresh ThingyState as the data changes based on the USB messages.

            Now, you have decoupled the state changes from any single activity. Each activity can be responsible for figuring out what needs to change in its own UI based on the new state. And, you no longer need static views.

            Source https://stackoverflow.com/questions/56049491

            QUESTION

            How to let the program wait to receive the serial port data?
            Asked 2018-Jan-06 at 00:50

            Edited:

            I am working on a program that will receive data from serial port, the data will end in "\r\n". I am using Data_Received event to receive the data from the serial port.

            Below is my program, I am try to avoid to use Thread.Sleep and use thread to wait for the data fully receive, but the step always jump to the return "Error" step.

            I would like to know how to let the program to wait for the data fully receive before it jump to the return "Error" step?

            It will be fine if don't use thread and if someone have a better method to do.

            ...

            ANSWER

            Answered 2018-Jan-04 at 11:38

            Please read:

            If you must use .NET System.IO.Ports.SerialPort.

            That is a blog post from Ben Voigt written 2014 on sparxeng.com.

            Excerpt:

            To put it mildly, System.IO.Ports.SerialPort was designed by computer scientists operating far outside their area of core competence. They neither understood the characteristics of serial communication, nor common use cases, and it shows. Nor could it have been tested in any real world scenario prior to shipping, without finding flaws that litter both the documented interface and the undocumented behavior and make reliable communication using System.IO.Ports.SerialPort (henceforth IOPSP) a real nightmare.

            and

            The worst offending System.IO.Ports.SerialPort members, ones that not only should not be used but are signs of a deep code smell and the need to rearchitect all IOPSP usage:

            • The DataReceived event (100% redundant, also completely unreliable)
            • The BytesToRead property (completely unreliable)
            • The Read, ReadExisting, ReadLine methods (handle errors completely wrong, and are synchronous)
            • The PinChanged event (delivered out of order with respect to every interesting thing you might want to know about it)

            and

            And the one member that no one uses because MSDN gives no example, but is absolutely essential to your sanity:

            • The BaseStream property

            Despite that blame from Ben Voigt, we are using the BytesToRead property and the ReadExisting() including Thread.Sleep(). We avoid DataReceived() and ReadLine(). That was our workaround, we didn't know the BaseStream property as well.

            For new projects I would recommend to use the BaseStream property.

            Source https://stackoverflow.com/questions/48092727

            QUESTION

            Reading ftdi to show string
            Asked 2017-Feb-22 at 08:35

            I use this code to read the RFID chip SN through ftdi usb reader. I want to use the RFID SN (0DBFFC21) later in SQL queries.

            My problem is that I get the SN many times splited in two rows... How should I put there a delay or something, so I can get full string everytime?

            ...

            ANSWER

            Answered 2017-Feb-22 at 08:35

            The correct approach may vary, but here is one simple to read data of known size:

            Source https://stackoverflow.com/questions/42370315

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install SerialPortExample

            You can download it from GitHub.
            You can use SerialPortExample like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the SerialPortExample component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/felHR85/SerialPortExample.git

          • CLI

            gh repo clone felHR85/SerialPortExample

          • sshUrl

            git@github.com:felHR85/SerialPortExample.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link