On Fri, 11 Feb 2011, melloannapolis wrote:
> All - thanks for the comments.
>
> I added parenthesis around the open statement, removed the no-delay flag,
> rebooted and it started working. I don't know exactly why it wasn't
> working but it must have had to do with the reboot more than anything....
>
> changed this:
> if (fd = open(COM2, O_RDWR | O_NOCTTY | O_NDELAY) < 0) {
Ok didn't spot this, but the reason it's wrong is that the '<' is performed
first then fd gets assigned the result of that comparison.
The open returns say '3' which is not less than 0 so the result of the
comparison is '0' - therefore fd gets set to zero.
> to this:
> if ((fd = open(COM2, O_RDWR | O_NOCTTY)) < 0) {
The brackets now force the order you wanted, first the assignment of the
open to fd, then check if that is less than zero.
cheers
Jim
p.s. I found a table of operator precedence at
http://www.difranco.net/cop2220/op-prec.htm
but if in doubt, either use simpler statements e.g.
fd = open(COM2, O_RDWR | O_NOCTTY);
if ( fd < 0 ) {
or use brackets.
------------------------------------
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|