Re: serial port question.



int fd = open( "/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY );


For portability, O_NONBLOCK is preferred over O_NDELAY. They
are exactly identical on Linux (and most other systems), but
have subtle differences on some platforms that make O_NDELAY
non-portable.

well you learn something new every day. i will use O_NONBLOCK from now on :)

options.c_cflag |= (CLOCAL | CREAD);


Why use an OR function, when you know that the initial value
is 0?


options.c_cflag |= PARENB;
options.c_cflag &= ~PARODD; /* Even parity */
options.c_cflag &= ~CSTOPB; /* 1 Stop bit */
options.c_cflag &= ~CSIZE;


Why clear bits, when the initial value is 0?


options.c_cflag |= CS8; /* 8 data bits */

options.c_cflag &= ~CRTSCTS;


All of the above can be a one liner:

options.c_cflag = (CLOCAL | CREAD | CS8 | PARENB);


options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);

options.c_iflag |= (IGNPAR); /* Ignore parity */


Why enable parity and then ignore it on input?


options.c_iflag &= ~(IXON | IXOFF | IXANY);

tcsetattr(fd, TCSANOW, &options);


This call really should be checked for an error return.

tcflush( fd, TCIOFLUSH );

well yes, there is a truck load of redundant code and
un-handled return values. I agree with and thank you for your comments
however i was merely posting this as a quick example to the OP
in an attempt to probe for extra information about the problem.
not to be the be-all end-all of solutions. :)
.



Relevant Pages

  • Re: gcc math
    ... doing work on Linux might also be interested in portability to other platforms ... -- Andrew Koenig ...
    (comp.os.linux.development.apps)
  • Re: gcc math
    ... Randy Howard wrote: ... > doing work on Linux might also be interested in portability to other ... > platforms and not realize this isn't ubiquitous, ...
    (comp.os.linux.development.apps)
  • Re: Linux in Forth?
    ... >TOPIC: Linux in Forth? ... >> you recommend something different now? ... >the evaluation packages of commercial Forths ... >don't care if my code has that kind of portability. ...
    (comp.lang.forth)
  • Re: Standard Forth versus Python: a case study
    ... It can connect to DLL's or Linux or OS X libraries so anything missing I can find a library and hook into it. ... Now it looks like PureBasic has joined the ranks of BASIC versions that runs on several platforms. ... I'm a fan of FreeBSD it runs well and no fuss secure OS, right now I'm using Ubuntu and I'm happy with it, I only have a couple of applications that need Windows for it and I use VMware to run a virtual copy of XP, that works out quite well, I have several PC's and only one boots to windows only because there is no hurry to knock it out. ... Both Pygmy and Holon are quite old but they work well for what they do, simple systems and they are very reliable, but they have their limits because of being so old. ...
    (comp.lang.forth)
  • Re: Programming Language Productivity: The Stupidity of Programmers
    ... The portability issues now are more serious ... dropping the original copy command in favor of their own COPY, ... including marking the CP/M-compatible APIs as obsolete. ... > bad as some Linux people would have us believe. ...
    (comp.object)