Permission denied when try connect on /dev/ttyTHS1

Got the “Permission denied” when I tried to use the port /dev/ttyTHS1, for both jetson pack 4.5 and 4.6.1 versions. Even though I followed some topic on the forum as issuing the commands:
systemctl stop nvgetty
systemctl disable nvgetty
udevadm trigger (or reboot)
It stilled showing the error: “Permission denied”
Please help
Thanks

hello chris_2022,

how about using sudo, is it able to access with the root permission?

Thanks JerryChang for reply the topic. Unfortunately, it did not work neither as the following commands:
sudo systemctl stop nvgetty
sudo systemctl disable nvgetty
sudo udevadm trigger (or reboot)

hello chris_2022,

I meant using the root permission to access tty from the host side.
i.e. $ sudo picocom -b 115200 /dev/ttyTHS1

I type exactly command:
sudo picocom -b 115200 /dev/ttyTHS1
and the display is:
sudo:picocom: command not found
so “picocom” is part of command or a name?
Thanks

hello chris_2022,

it’s serial port utility, such as… minicom and picocom.

Jerry,
the error msg “Permission denied” when I try to open fd as:

char* a_port = “/dev/ttyTHS1”;

int fd = open( a_port, O_RDWR | O_NOCTTY | O_SYNC );
//
it is simple app in C , linux
and after i compile, and run it , then the error come up: “Permission denied”

so my question is how to get rid off the error message
Thanks

hello chris_2022,

what’s the permission of your test program, could you please try adding the permission for checking this?

Jerry, here the source of the program, it’s very basic and simple, yes you have permission to test it.
int setting_serial(int fd, int speed, int parity)
{
int rc = 0;
struct termios a_term;
memset (&a_term, 0, sizeof a_term);
if ( tcgetattr (fd, &a_term) != 0 ) {
printf( “Error %d from tcgetattr”, errno );
return( -1 );
}
cfsetospeed( &a_term, speed );
cfsetispeed( &a_term, speed );

a_term.c_cflag = (a_term.c_cflag & ~CSIZE) | CS8;
a_term.c_iflag &= ~IGNBRK;
a_term.c_lflag = 0;
a_term.c_oflag = 0;
a_term.c_cc[VMIN] = 0;
a_term.c_cc[VTIME] = 5;
a_term.c_iflag &= ~(IXON | IXOFF | IXANY);
a_term.c_cflag |= (CLOCAL | CREAD);
a_term.c_cflag &= ~(PARENB | PARODD);
a_term.c_cflag |= parity;
a_term.c_cflag &= ~CSTOPB;
a_term.c_cflag &= ~CRTSCTS;

rc = tcsetattr( fd, TCSANOW, &a_term );
if( rc ) {
printf( “Error %d from tcsetattr”, errno );
return( rc );
}
return( rc );
}

int main( void )
{
int rc = -1;
int n_bytes = 0;
unsigned char ichar = 0;
unsigned char jchar = 0;
unsigned short int val2 = 0;

char* a_port = “/dev/ttyTHS1”;
char* a_prompt = “Enter S to start:\n”;

fd_set rd_set;
int fd = open( a_port, O_RDWR | O_NOCTTY | O_SYNC );
if( fd < 0 ){
printf(“Error: %d opening %s: %s”, errno, a_port, strerror (errno) );
return(rc);
}

setting_serial(fd, 115200, 0);
for( ;; ) { //#1
(void) memset( &END_str[0], 0x00, 256 );
printf("%s", a_prompt);
scanf("%s", &jchar);
if(jchar == ‘q’) {
printf( “quit …” );
break;
}
switch(jchar) {
case ‘w’:
printf(“Welcome…\n”);
write(fd, “welcome”, 6);
write(fd, “\n”, 1);
write(fd, “27”, 2);
break;
case ‘s’:
case ‘S’:
printf(“Start…\n”);
break;
default:
printf(“Invalid choice.”);
continue;
}
FD_ZERO( &rd_set );
FD_SET ( fd, &rd_set );

  printf( "Beginning read: \n" );
  for( ;; ) {
	  val2 = 0;
     n_bytes = read( fd, &ichar, 1 );
     if( n_bytes == 2 ) {
        printf("v2=0x%X\n", val2);
     } else if(n_bytes == 1)   {
	    printf("v1=0x%X\n", ichar);
     }
  }

} //for(;;)#1
return(rc);
}//main

Do examine the permissions of “ls -l /dev/ttyTHS1”. You don’t need to reissue the command for disabling nvgetty once you’ve run disable. However, if the group is “tty”, then nvgetty is still running. More likely it is ok now and group “dialout”. In that case adding your user to also be a member of dialout will fix permission denied. Example, if your user name is “nvidia”:
sudo usermod -aG dialout nvidia

If you then get an error it should be from some other cause. If it works, then you should not use sudo because your account would already have permission by being in supplemental group “dialout”.

Thanks linuxdev so much. It’s working now.