ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I wrote a little test program in c++ to read data from ttys0. It works but only as root! I have set the user to be a member of tty, I have even tried to set the ttys0 device to 777. Nothing but running as root seems to work. Any suggestions?
Here is the source to the object I wrote to read the serial port.
I am using Linux
//
// File: kybdevice.cc
// Created on: Mon Apr 11 15:01:33 2005
//
#include "kybdevice.h"
kybdevice::kybdevice()
{ // init
errorcode=0;
// Open serial port
fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY );
if (fd <0) {perror(MODEMDEVICE);
errorcode=44;
}else{
tcgetattr(fd,&oldtio); /* save current port settings */
memset(&newtio, 0, sizeof(newtio));
newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
/* set input mode (non-canonical, no echo,...) */
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 1; /* inter-character timer unused */
newtio.c_cc[VMIN] = 1; /* blocking read until 5 chars received */
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);
}
}
kybdevice::~kybdevice()
{
// TODO: put destructor code here
if(!errorcode){
tcsetattr(fd,TCSANOW,&oldtio);
}
}
int kybdevice::getKeystrokes(unsigned char *buffer, int bufsze){
res = read(fd,buffer,bufsze);
buffer[res]=0;
}
int kybdevice::getError(void){
return errorcode;
}
return 28;
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.