Linux - EnterpriseThis forum is for all items relating to using Linux in the Enterprise.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I am new to the linux.I have written a program in c/C++ to communicate with a device through serial port.This program is not able to read data from serial port.
I tried to connect the device using minicom and it seems to working fine.
Here is the program:-
using namespace std;
const int MAXDATASIZE = 512;
// std::vector<char> m_vRequestBuf;
int totalBytes = 0;
//struct termios port_settings;
int configure_port(int fd);
fd1=open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd1 == -1 )
perror("open_port: Unable to open /dev/ttyS0 – ");
printf("Port 1 has been successfully opened and %d is the file description\n",fd1);
fd1 = configure_port(fd1);
printf("Port Configured \n");// apply the settings to the port
printf("Start Writing... \n");
wr = write(fd1,"SFC\r",4);
if (wr < 0)
printf("no bytes written \n");
printf("bytes written %d \n" ,wr );
fcntl(fd1, F_SETFL, FNDELAY);
if(rd > 0)
cout << "charsRead" << rd << endl;
//Sleep for some time and read again
int configure_port(int fd) // configure the port
struct termios port_settings; // structure to store the port settings in
cfsetispeed(&port_settings, B9600); // set baud rates
port_settings.c_cflag &= ~PARENB; // set no parity, stop bits, data bits
port_settings.c_cflag &= ~CSTOPB;
port_settings.c_cflag &= ~CSIZE;
port_settings.c_cflag |= CS8;
port_settings.c_cflag &= ~CRTSCTS;
port_settings.c_cflag |= (CLOCAL | CREAD);
tcsetattr(fd, TCSANOW, &port_settings);
What result do you get from running the program? Also, have you tried flushing the port after the write to ensure the data is sent, as I've have problems with data being held in local data buffers until the port if flushed?