C++ access of EPIC serial module port

I am porting an app to an epic. The is written in C++ and uses one or more serial ports to talk to other devices. Is there a preferred/recommended way to access the serial ports (GRV-CSERI-4 card)?

nResult = open("/dev/ttySerSys0", O_RDWR | O_NOCTTY);

always returns -1.

I don’t have an EPIC serial module on hand just this minute (let me see if I can find one), but I am just wondering about that device name… /dev/ttySerSys0
Is that what an ‘ls’ of the /dev/ directory shows as its name?
(In other words, I am assuming you have a shell license installed on your EPIC and I am wondering what the Linux device name is for the serial ports on the module).

I picked up the name from the config screen

I have tried multiple device name with the same result.

Hmmm. Ok.
I found where I posted about accessing the serial ports on the module directly via Linux, its here;

Might have to revisit it from a C++ point of view (in which case, I am not the guy, but might know a guy).

EDIT. Try using /dev/ttyUSB0

Yes, I saw that. There are not USB ports though. I will try it.

I wonder if there is anything that needs to be installed on the device out Opto22.

Ah, but that’s the fun part… they are…
The first 4 slots on EPIC have a USB bus under them. That’s why you have to put the serial module in the first 4 slots only.

No, The native Linux OS has the drivers required.

No luck. Is there some other name you think I should try?

I have tried “/dev/ttyUSB0”, "/dev/ttySerSys0

This is what I see from ls dev

Hmm, not off the top of my head no…
Did you try the ttySerMod0.0? I wonder what its linked to (blue means its a sym link).
I honestly expected the ttyUSB0 to work since its the baseline that everything else is built off.

No good. I have tried tty, tty0, ttySerMOd0.0, ttyserSys0, etc. I am struggling for what else to try.

Thanks for letting us know.
Sorry for the frustration.
Just reaching out to internal resources to see what I can find out.

Can you check errno (errno.h) after the open call to see if that sheds any light?

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:

  1. use sudo to run your program
  2. add the shell access user to the dialout group
  3. 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.

Yep, errno is 13: Permission denied.

Bingo!
Ok, well, just a few permissions tweaks and you should be on your way.