Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no permission to read or write this serial port #20

Open
SArrueLorca opened this issue Oct 18, 2021 · 8 comments
Open

no permission to read or write this serial port #20

SArrueLorca opened this issue Oct 18, 2021 · 8 comments

Comments

@SArrueLorca
Copy link

SArrueLorca commented Oct 18, 2021

Hi. I'm trying to create an app that uses a COM port to send strings to a laptop. So, i was compiling my app on react native with a Windows OS and everytime that i want to use an specific port (COM3 in this case) in the function "const serialPort = await SerialPortAPI.open("/dev/ttyS4", { baudRate: 9600 });" i get the "no permission to read or write this serial port" error message.

I tried to mitigate the error putting the following permissions in my android manifest: INTERNET, WRITE_EXTERNAL_STORAGE", READ_EXTERNAL_STORAGE and USE_PERIPHERAL_IO"

And the following static function in my "App.js", considering the closed issue #9, to no avail
static setSuPath(suPath) {
SerialPortAPI.setSuPath("/system/bin/su");
}

I would like some help on how to fix this error please

@SArrueLorca
Copy link
Author

Also. Considering this similar package: https://github.com/licheedev/Android-SerialPort-API/blob/master/README.md
Do i have to root my phone/tablet to make it work?

@bastengao
Copy link
Owner

You could just call SerialPortAPI.setSuPath("/system/bin/su") if su path is /system/bin/su, don't need to define static function setSuPath.

@SArrueLorca
Copy link
Author

Great, i called setSuPath and open in a function called by the constructor. Now about the su path, how do i get it if the default one (/system/bin/su) didn't work?. Do i have to root my phone to do so?

@bastengao
Copy link
Owner

https://developer.android.com/studio/command-line/adb#shellcommands

Go into shell on Android phone, then execute which su, you will get su path.

@alisaya10
Copy link

alisaya10 commented Apr 16, 2022

hi dear i have the same issue too i do some stuff like bellow but still give me the no permission to read or write this serial port

i put this lines to androidManifest.xml

<uses-permission android:name="android.things.permission.USE_PERIPHERAL_IO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

get /system/xbin/su from command ( which su ) and put this to following code

 async function example() {

        SerialPortAPI.setSuPath("/system/xbin/su");
        console.log("tp1")
       
        const serialPort = await SerialPortAPI.open("/dev/ttyS2", { baudRate: 38400 });

        // subscribe received data
        serialPort.onReceived(buff => {
            console.log(buff.toString('hex').toUpperCase());
        })

        

        // unsubscribe
        // sub.remove();

        // send data with hex format
        await serialPort.send('00FF');

        // close
        serlialPort.close();
    }
    example()

please help thanks

@rinshadkk
Copy link

i am still getting the permission error. @alisaya10 Did you get it resolved?

@Ranjit8298
Copy link

Hii @rinshadkk , Did you get it resolved the issue?

@MelihaDuman
Copy link

hey any update on this issue? I am facing the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants