Send stuff from mangOH app to /dev/ttyUSBx


#1

So I eventually got my FTDI USB-to-serial cable working on the command line.

Now - how do I do that from an app?

I have tried:

    int fd = open( "/dev/ttyUSB1", O_RDWR | O_NOCTTY | O_NDELAY );
    if( fd < 0 )
    {
    	LE_INFO("open failed");
    }

   ssize_t result = write( fd, "Opened.\r\n", 9 );
    
   if( result < 0 )
    {
    	LE_INFO("1st write failed");
    }

But the open fails.

Where am going wrong?

Update:
errno is 2 when the open fails - which, I think, is

ENOENT 2 /* No such file or directory */


#2

If your app is sandboxed (if you don’t specify “sandboxed: false” in the .adef it will be), then /dev/ttyUSB1 won’t exist in the filesystem seen by your app.

See this section of the Legato documentation on how to put a device file into your sandbox:
http://legato.io/legato-docs/latest/defFilesAdef.html#defFilesAdef_requiresDevice

Basically, you need this:

requires:
{
    device:
    {
        [rw] /dev/ttyUSB1 /dev/
        // Above line is a shortcut for: [rw] /dev/ttyUSB1 /dev/ttyUSB1
    }
}

#3

Yes, that’s it.

Thanks.

:grin:


#4