Jump to content


Photo

Detecting serial (uart) ports with Java


  • Please log in to reply
15 replies to this topic

#1 Peter Valencic

Peter Valencic

    Member

  • Senior Members
  • PipPip
  • 14 posts

Posted 17 February 2017 - 09:59 AM

Hi,

 

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;

import gnu.io.CommPortIdentifier;

/**
 *
 * @author Peter
 */
public class TestCom {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        System.out.println("-------------------------------");
        System.out.println(System.getProperty("java.version"));
        System.out.println(System.getProperty("os.name"));

        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";
            default:
                return "unknown type";
        }
    }

}

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

 

-------------------------------
1.7.0_121
Linux
/dev/ttyS0 - Serial
 
 
 
Is there some configuration file to enable / disable UARTS? 
 
 
thank you.


#2 martinayotte

martinayotte

    Advanced Member

  • Senior Members
  • PipPipPip
  • 442 posts

Posted 17 February 2017 - 02:55 PM

Other UARTs are not enabled by default.

For Legacy, you need to edit the FEX.

For Mainline, where we have now overlays, you need to add them in the /boot/armbianEnv.txt :

overlays=sun8i-h3-uart1 sun8i-h3-uart2 sun8i-h3-uart3


#3 Peter Valencic

Peter Valencic

    Member

  • Senior Members
  • PipPip
  • 14 posts

Posted 17 February 2017 - 04:34 PM

Ok!

 

will this be fine? will try.. thank you

verbosity=7
console=both
machid=1029
bootm_boot_mode=sec
rootdev=UUID=74434014-190f-406c-9b73-2c99c49383ba
rootfstype=ext4
overlays=sun8i-h3-uart1 sun8i-h3-uart2 sun8i-h3-uart3


#4 martinayotte

martinayotte

    Advanced Member

  • Senior Members
  • PipPipPip
  • 442 posts

Posted 17 February 2017 - 04:36 PM

Yes !



#5 Peter Valencic

Peter Valencic

    Member

  • Senior Members
  • PipPip
  • 14 posts

Posted 17 February 2017 - 04:40 PM

Hmm.. tryed but still get only one serial

cmd : cd '/home/projekt/NetBeansProjects//TestCom'; '/usr/bin/java'  -Dfile.encoding=UTF-8   -jar /home/projekt/NetBeansProjects//TestCom/dist/TestCom.jar 
-------------------------------
1.7.0_121
Linux
/dev/ttyS0 - Serial


#6 Peter Valencic

Peter Valencic

    Member

  • Senior Members
  • PipPip
  • 14 posts

Posted 17 February 2017 - 05:18 PM

Have tryed also with python but here I get nothing :)

 

Have installed Serial lib from https://pypi.python.org/pypi/pyserial

 

screenshot_193.jpg

 

screenshot_193.jpg



#7 martinayotte

martinayotte

    Advanced Member

  • Senior Members
  • PipPipPip
  • 442 posts

Posted 17 February 2017 - 05:30 PM

Are you sure you are using latest Mainline ?

Please, provide output of "uname -a" and "ls -l /boot/dtb/overlay" and "dmesg | grep serial" and "cat /proc/device-tree/soc/serial@01c28400/status"



#8 Peter Valencic

Peter Valencic

    Member

  • Senior Members
  • PipPip
  • 14 posts

Posted 17 February 2017 - 05:36 PM

Thank you for your help!

 

here is

screenshot_193.jpg

 

for: ls -l /boot/dtb/overlay  

I don't have subdirectory dtb

screenshot_193.jpg

 

dmesg | grep serial

screenshot_193.jpg

 

 

cat /proc/device-..... (I don't have this folder)

screenshot_193.jpg

 

 

thank you for your help. I don't have much experience in linux but must do a project for thesis ;) ;(



#9 Peter Valencic

Peter Valencic

    Member

  • Senior Members
  • PipPip
  • 14 posts

Posted 17 February 2017 - 07:06 PM

Will try to upgrade ...

sed -i "s/apt/beta/" /etc/apt/sources.list.d/armbian.list
apt-get update
apt-get upgrade


#10 Peter Valencic

Peter Valencic

    Member

  • Senior Members
  • PipPip
  • 14 posts

Posted 17 February 2017 - 07:27 PM

I get the same values:

 

screenshot_200.jpg

 

 

screenshot_200.jpg



#11 Nickb333

Nickb333

    Newbie

  • Senior Members
  • Pip
  • 4 posts

Posted 17 February 2017 - 08:22 PM

I get the same values:

 

screenshot_200.jpg

 

 

 

 

 

You have 3.4 kernel = LEGACY so you need to edit the FEX. See https://docs.armbian...#updating-a-fex

 

Once you have a fex file to edit after bin2fex you should refer to http://linux-sunxi.org/Fex_Guide

 

HTH.



#12 Peter Valencic

Peter Valencic

    Member

  • Senior Members
  • PipPip
  • 14 posts

Posted 17 February 2017 - 09:47 PM

uuu thank you... ;)

 

screenshot_204.jpg



#13 martinayotte

martinayotte

    Advanced Member

  • Senior Members
  • PipPipPip
  • 442 posts

Posted 17 February 2017 - 11:41 PM

Ahhh ! You are not using Mainline kernel ! ...

Since you are using Legacy kernel, it doesn't use DeviceTree, so no overlays too.

You need to tweak FEX file, in other word script.bin, you need to decompile it, tweak it, and recompile it.

 

Check this guide : http://linux-sunxi.o....5Buart_para.5D



#14 Peter Valencic

Peter Valencic

    Member

  • Senior Members
  • PipPip
  • 14 posts

Posted 18 February 2017 - 10:55 AM

Thank you will check..



#15 Ford Prefect

Ford Prefect

    Advanced Member

  • Senior Members
  • PipPipPip
  • 68 posts

Posted 18 February 2017 - 11:41 PM

 

Other UARTs are not enabled by default.

For Legacy, you need to edit the FEX.

For Mainline, where we have now overlays, you need to add them in the /boot/armbianEnv.txt :

Hi

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

I mean without rebooting.



#16 Blars

Blars

    Newbie

  • Senior Members
  • Pip
  • 7 posts

Posted Yesterday, 0:49

Hi

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.