TotalCross / totalcross

TotalCross is a Software Development Kit that helps cross platform application development. Currently supported platforms are: Windows, Wince, Android, iOS, Linux and Linux ARM for embedded systems.
https://www.totalcross.com
GNU Lesser General Public License v2.1
222 stars 40 forks source link

Only ttyS0 can be specified in the port connector #368

Open mxi02532 opened 3 years ago

mxi02532 commented 3 years ago

Issue Title

Only ttyS0 can be specified in the port connector

Describe the bug

Hi. I'm developing Totalcross on Toredex's Coribli-im x7 board.

Devices Toradex Coribli-imx7-emmc-1GB Carrierboard iris Linux-ARM(32bit) Totalcross SDK 7.1.0 Toradex Embedded Linux Reference Multimedia Image 5.0.0 build.1

I need to use the serial port. The iris carrier board has three serial ports. UART_A, UART_B, UART_C. Each of the three serial ports is assigned to a device file as shown below.

UART_A = /dev/ttymxc0 UART_B = /dev/ttymxc1 UART_C = /dev/ttymxc2

Since the Linux standard serial port device file is ttyS, not ttymxc, Set a symbolic link. The pins I use are UART_B and UART_C, so set them as follows.

# cd dev # ln -s ttymxc1 ttyS1 # ln -s ttymxc2 ttyS2

Then try serial communication using Totalcross's Port Connector library. The following is a part of the source code.


  @Override
        public void controlPressed(ControlEvent controlEvent) {

            int opflg = 0;
            PortConnector port = null;
            DataStream ds = null;          

            try{
                port = new PortConnector(1, 9600); //issue piont.
                opflg = 1;

            }
            catch(totalcross.io.IOException e) {
                opflg = 0;
                System.err.println("Port open error");
            }    

            if(opflg == 1){

                try{

                    ds = new DataStream(port);
                    ds.writeCString("Hello...\r\n");
                    ds.close();
                    port.close();
                    opflg = 0;
                }
                catch(totalcross.io.IOException e){

                    System.err.println("Serial write error");
                }

            }   

        }

When I run the above code, I get the following error:

/dev/ttyS0: No such file or directory

Additional context

PortNumber is specified as 1 in the code.

PortConnector port = new PortConnector(1, 9600);

I thought that setting PortNumber to 1 would set the device file to ttyS1. In fact, PortNumber was set to ttyS0 in all cases 0, 1, 2 and 3.

Reboot the board and make the symbolic link look like this:

# cd dev # ln -s ttymxc1 ttyS0

Then, the above error did not occur and serial communication was successful. However, this way, the device file can only use ttyS0 at any given time. Only one of UART_A, UART_B, and UART_C can be used as the serial port. Since I want to use two serial ports at the same time, I need to specify ttyS0, ttyS1 and ttyS2 from the source code. I thought the method was the code below, but it doesn't work.

PortConnector port = new PortConnector(, 9600); // is 0 or 1 or 2

Can anyone please tell me how to specify ttyS0, ttyS1 and ttyS2 from the Totalcross source code? Thank you.

mxi02532 commented 2 years ago

I've found a solution to the question I wrote here the other day, so I'll report it.

Same as before, My development environment is below.

Devices Toradex Coribli-imx7-emmc-1GB Carrierboard iris Linux-ARM(32bit) Totalcross SDK 7.1.0 Toradex Embedded Linux Reference Multimedia Image 5.0.0 build.1

I noticed the following in this environment.

port = new PortConnector (PortConnector.IRCOMM, 9600);

If I do the above, I will get the following error.

/ dev / ircomm0: No such file or directory

Also, regarding Bluetooth

port = new PortConnector (PortConnector.BLUETOOTH, 9600);

If I do the above, I will get the following error.

/dev/rfcomm0: No such file or directory

My purpose is to use multiple UARTs, so I set a symbolic link and created a rule file.

KERNEL=="ttymxc0", SYMLINK+="ttyS0" KERNEL=="ttymxc1", SYMLINK+="ircomm0" KERNEL=="ttymxc2", SYMLINK+="rfcomm0"

After setting this symbolic link If you want to use UART2, you can use it by specifying port = new PortConnector (PortConnector.IRCOMM, 9600) ;. If you want to use UART3, you can use it by specifying port = new PortConnector (PortConnector.BLUETOOTH, 9600) ;.

Since BLUETOOTH is assigned to UART, BLUETOOTH cannot be used, but I think that it is an effective means if it is still good.

Thank you very much.

brunoamuniz commented 2 years ago

Thanks for letting us know!! Please report the solution when you can

alvaroga91 commented 2 years ago

Hi guys, just a follow up on this issue, I think that this issue would be easily solvable with a new constructor that allows strings :)

port = new PortConnector("/dev/ttymxc0", 9600);

Whenever you can! Thanks!

mxi02532 commented 2 years ago

Hi alvaroga91.

Thank you for providing the solution information. I tried as you told me, but the results weren't ideal.

port = new PortConnector ("/ dev / ttymxc0", 9600);

I tried the above description, but when I debug with VScode

The constructor PortConnector (String, int) is undefined.

Error occurs. I can press Proceed to force debugging, but when I package and deploy, the program starts momentarily and exits immediately. Is it necessary to set in advance to use String as the first argument of PortConnector? I will do my best to find a good pass. Please continue to share information.