Detecting serial (uart) ports with Java

Peter Valencic


Recommended Posts



In my project I want to use UART on GPIO pin (8,10). I wrote a simple Java app to decet serial ports on my orange PC but it return only /dev/ttyS0 - Serial


Here is simple java code using rxtxlibrary..

package org.mbp;


 * @author Peter
public class TestCom {

     * @param args the command line arguments
    public static void main(String[] args) {

        java.util.Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers();
        while (portEnum.hasMoreElements()) {
            CommPortIdentifier portIdentifier = portEnum.nextElement();
            System.out.println(portIdentifier.getName() + " - " + getPortTypeName(portIdentifier.getPortType()));


    static String getPortTypeName(int portType) {
        switch (portType) {
            case CommPortIdentifier.PORT_I2C:
                return "I2C";
            case CommPortIdentifier.PORT_PARALLEL:
                return "Parallel";
            case CommPortIdentifier.PORT_RAW:
                return "Raw";
            case CommPortIdentifier.PORT_RS485:
                return "RS485";
            case CommPortIdentifier.PORT_SERIAL:
                return "Serial";
                return "unknown type";


Whe I run the code on orangepiPC I get only one UART which is /dev/ttyS0


/dev/ttyS0 - Serial
Is there some configuration file to enable / disable UARTS? 
thank you.
Link to post
Share on other sites

Armbian is a community driven open source project. Do you like to contribute your code?


Does this means that it could be possible to change the use of the GPIO pins "on the fly"

I mean without rebooting.


Sure.  Just write a driver module that manipulates the proper bits in the setup registers, read the data sheet for your CPU and the kernel source code.  The "confidential" H3 data sheet is on the sunxi web site.  Apparently the H2 used on the opi zero is very close, but I have not found it's data sheet.  This is not something I would recommend for beginner programmers.

Link to post
Share on other sites

This topic is now closed to further replies.