kandi X-RAY | SerialPortUtil Summary
kandi X-RAY | SerialPortUtil Summary
Top functions reviewed by kandi - BETA
- Initializes the tv_hello
- Sets the device path
- Returns output stream
- Gets an InputStream for this object
- Send an error message
- Set whether to output to output
- Send data to the serial port
- Sets the time out in milliseconds
- Sets the Baudrate for the serial port
- Creates the SerialPortService
- Reads all available drivers from the terminal
- Get the names of all the devices in the system
- Convert a byte array to a hex string
- Get the names of all devices
- Closes the serial port
- Close the port
- Main entry point
- Converts a hex string to a byte array
- Converts an array of strings to a hex string
SerialPortUtil Key Features
SerialPortUtil Examples and Code Snippets
Trending Discussions on SerialPortUtil
I've a small android library which handles a serial port, it has basic functionality like open, read, write and close.
I have made an applications that uses this library to write on the serial port and read the responses, within this application there is a thread that periodically opens the serial port asks for the status get the response and close the serial port.
I want to protect the serial communication in a way that if the main thread opens the communication the secondary thread that only checks the status can not open it and wait for the main thread to finish....
ANSWERAnswered 2019-Feb-21 at 14:56
How can I tell the checker thread that the communication is already opened and make him wait until the main thread finish.
I don't fully understand your code but the critical thing with threads and locking is to make sure that all threads are calling code that is
synchronized on the same object instance.
If I synchronize an object, there still is a window when the object is not synchronized.
Not if you use the same instance of the object. Making each of the
public methods in
synchronized will make sure that only 1 thread can be using the object at once.
I suspect that your real problem is not about protecting the
SerialChannel object but more about race-conditions between the threads. They need to make multiple calls to the methods and they can block each other or interleave in an improper manner.
You can get around this with a couple of changes. You can make the
receive(...) methods auto-opening. Threads would just call
receive() which in turn would internally call
open() if the
null. The thread would be inside of a
synchronized so this would not be interrupted by another thread.
Another completely different model to consider would be to have one thread reading from the serial port and another writing to it that are dedicated to that task -- they would be built into the
SerialChannel object. They would share data with the external threads using a read
BlockingQueue and a write
BlockingQueue. Then the serial port is opened early in your application which starts the IO threads and the external threads never worry about the IO. They just
take() from the queues. I typically do this (for example) when reading and writing to the console.
Hope something here helps.
No vulnerabilities reported
You can use SerialPortUtil 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 SerialPortUtil 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 .
Reuse Trending Solutions
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page