Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
This is my first post here, hope this is the best place to ask this question. It is definitely a linux problem (same code working fine on windows).
I'm developing an application in C++ (compiled with gcc), running on Ubuntu 10.4 guest OS on XP host. I need to implement MBus protocol and I'm stuck with serial port behavior.
I configure the port properly, then I try to write some data to the port. No matter the length of the buffer I want to write, on the output of the serial port I can see 2 first characters from the buffer, then a space (time delay of about a single char length), and then the rest of the buffer. The delay varies with baudrate (higher baud, smaller delay). Seen on oscilloscope, so I'm quite confident what's going on. All the buffer content is properly sent over the serial port, the only problem is the time delay after first 2 bytes...
Have you got any idea what can cause the problem and how can I get rid of it?
I don't think it is a VM problem, I tried to run this app on PC with native Ubuntu Hardy and the behavior was exact.
int fd = 0;
fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NONBLOCK);
if (fd == -1)
printf("\n SP failed!\n");
fcntl(fd, F_SETFL, 0);
struct termios options;
// Get the current options for the port...
// Set the baud rates to 2400...
// Enable the receiver and set local mode...
options.c_cflag |= (CLOCAL | CREAD);
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
options.c_cflag |= PARENB;
options.c_cflag &= ~PARODD;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
// Set the new options for the port...
tcsetattr(fd, TCSANOW, &options);
fcntl(fd, F_SETFL, FNDELAY);
printf("\nSP OK\n");//erial port opened succesfully, FD = %d\n", fd);
I have to be honest with you, (1) extreme kudos to you for doing the due diligence and writing the correct program first, testing it out, ... putting in a proper effort before sending out a question; however (2) I have also seen the programming examples much like you have, read, and re-read the Serial HOWTO and for the life of me, I can't get things to always work correctly by using the tc functions and fcntl.
So as a result, I fork() and exec() the following:
stty -F/dev/ttyS# 19200 raw -echo
And wait on the child to complete.
Believe me, I have 4 serial USB tty devices on an embedded system, all different data rates, from 9600 up to 115.2k and getting the ports into raw mode was extremely important for me to properly get my data without delays. For some reason if you don't do that, you get what I saw and what I think you were describing, sometimes you do not get the data until a later point; it's there, but delayed. And when you have async data of indeterminate length, it is a huge deal to be stuck waiting for part of it.
If you really do wish to give the program instructions a continued effort, then read the Linux Serial HOWTO, there's an async port example right in there, and one thing you're missing is a fcntl call that includes FASYNC, and I think you are supposed to set ICANON, not clear it as you have.