I'm using the excellent Com port for Android to communicate using a serial connection between a UOODO Android board and a hardware device. My serial port as seen from the Delphi App is "/dev/ttymxc3".
When I run my app, it tells me that 'permission is denied'. From console access on another port if I execute the command
chmod 666 /dev/ttymxc3
and then run my app again, it works ok. So, I've tried to execute this command from within my app as follows based on this SO question and the "java.lang.Runtime" and "android.os.process" import from here on GitHub
uses
java.lang.Runtime,
Androidapi.Helpers;
procedure TForm1.Button1Click(Sender: TObject);
begin
TJRuntime.JavaClass.getRuntime.exec(StringToJString('chmod 666 /dev/ttymxc3'));
end;
where pressing the button I hoped to change the permission from code. I get an access violation though. As suggested in the comments, to find out where this is coming from (and because the Delphi debugger does not work with this device) I executed the following:
procedure TForm2.Button2Click(Sender: TObject);
var
RunTime : JRuntime;
S : JString;
begin
try
RunTime := TJRuntime.JavaClass.getRuntime;
if not Assigned( RunTime ) then
begin
ShowMessage( 'E1' );
Exit;
end;
except
on E:Exception do
ShowMessageFmt( 'E1A:%s', [E.Message] );
end;
try
S := StringToJString('chmod 666 /dev/ttymxc3');
if not Assigned( S ) then
begin
ShowMessage( 'E2' );
Exit;
end;
except
on E:Exception do
ShowMessageFmt( 'E2A:%s', [E.Message] );
end;
try
RunTime.exec( S );
except
on E:Exception do
ShowMessageFmt( 'E3A:%s', [E.Message] );
end;
end;
The AV is shown to trigger my 'E3A' error, ie use of 'exec'. My questions are: Why would I get this AV? Is what I'm doing fatally flawed? Ie should I even be able to set permissions on this device node from within a plain Delphi app? If so, can I change my app permissions to permit this?
i use nanopi2 with c++ builder rx10 seatel and booted android lolipop and winSoft comport component same as you i had same problem in c++ builder when i used your method(access violation) but i use another method to solve my problem that i suggest to use that i think it solves your problem
in delphi
uses
Posix.Stdlib
_system('su -c chmod 777 dev/ttyAMA0') ;
in c++ builder
#include <Posix.Stdlib.hpp>
system('su -c chmod 777 dev/ttyAMA0') ;
my serial port in nanopi2 is ttyAMA0
carefull for sucssesfully open port i had to set SELINUX to permission mode by
this instruction
_system('su -c setenforce 0');
http://www.fmxexpress.com/launch-a-url-or-document-on-ios-and-android-with-delphi-firemonkey/
i love embarcadero i love c++ builder
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.