Ok, so here are some things that the software engineers said to try that really should show the way forward…
Firstly; stty -F /dev/ttySerMod0.0
This tries to open the file handle and read its configuration so if there is a permissions problem or the filename is wrong, it’ll tell you.
For best results, this should be done as the user that is going to run your C++ code.
If you don’t know who your C++ user is, I am a little lost, you should really know what user your code is running as.
If you are logged into shell as someone else, then sudo su username
will let you log in as the user that will be running the C++ code (swap out ‘username’ for the C++ user of course).
From that then we can continue…
The key is the error code that you mention, the -1.
When open returns -1, it sets errno with the cause of the failure. Which is exactly what @philip was correctly asking about.
The errno variable and strerror() function can then be used to find out more about the error. For example, if you compile and execute the following file, test.c
, on your PR1 you should get:
=== begin test.c ===
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
void main( int argc, void* argv)
{
int nResult = open( "/dev/ttySerMod0.0", O_RDWR | O_NOCTTY);
if( nResult < 0 )
{
int err = errno;
printf( "nResult:%d \terrno:%d \tmsg:%s\n", nResult, errno, strerror(err));
}
else
{
printf( "Success\n" );
close(nResult);
}
}
=== end test.c ===
gcc test.c -o test
./test
nResult:-1 errno:13 msg:Permission denied
sudo ./test
Success
So it’s likely you are trying to run your program as the default shell access user, which is not a member of the dialout group and therefore doesn’t have permission to access the serial ports.
If this is the case, then you need to either:
- use sudo to run your program
- add the shell access user to the dialout group
- run the program in the context of a user that is a member of the dialout group (e.g dev)
Hope that is helpful in moving forward.