Problem with opening tty from Application Framework

Hi,

I have written the below program to open “ttyHSL1” on my MangoH board and write something on it.

int fd;
fd = open("/dev/ttyHSL1",O_RDWR | O_NOCTTY);
if (fd < 0)
{
   printf("\n  Error! in Opening ttyHSL1 fd %d\n", fd);
   printf("\nerrno %d", errno);
   return;

}
else
   printf("\n  ttyHSL1 Opened Successfully fd %d\n", fd);

char write_buffer[] = "A";
int  bytes_written  =  0 ;

bytes_written = write(fd,write_buffer,sizeof(write_buffer));
printf("\n bytes_written to serial port %d\n", bytes_written );
close(fd);

}

This program runs correctly when I invoke it from inside my board (get a terminal by doing ssh into the board). But the same application throws following error when I try to run it from Legato Application Framework.

Jan 6 07:11:41 | helloworld[12378] | | Hello Hi
Jan 6 07:11:41 | helloworld[12378] | |
Jan 6 07:11:41 | avcDaemon[621]/avcDaemon T=main | avcFs.c DeleteFs() 140 | failed to delete /avc/sw/instanceId: LE_NOT_FOUND
Jan 6 07:11:41 | helloworld[12378] | | Error! in Opening ttyHSL1 fd -1
Jan 6 07:11:41 | helloworld[12378] | |
Jan 6 07:11:41 | helloworld[12378] | | errno 2

Can somebody please help?

Thanks,
Yogesh

1 Like

Hello Yogesh,

You should add the device inside the *.cdef file, for example this way:
requires: {
device: {
“/dev/ttyHSL1” “/dev/”
}

}

See also:

Regards.

1 Like