I think you just answered your own question.
You need to test result codes, especially for
something like opening a file. I guess if you were
also to test the result code of the write call, you'd
find it wasn't succeeding either since the file hadn't
been opened successfully. You need to put in tests for
the result codes and take appropriate action. If you
decide to stick with the O_NONBLOCK flag you need to
be aware that it also makes all subsequent I/O on that
file descriptor non-blocking. In other words, the
reads/writes on the descriptor will be non-blocking as
well.
No offense, but you seem to be making a number of
"beginner level" type of programming errors from what
I've seen so far. You should find a good book on Unix
programming such as "The Unix Programming Environment"
by Kernighan and Pike. It has a tutorial chapter on
doing file I/O with the calls like open and write
("Unix System Calls").
-Steve
--- mohamed rafi <email@hidden> wrote:
> Hi,
>
> I tried to issue the open without the O_NONBLOCK,
> and
> found that Open was not returning at all (waited for
> almost > 10 min). Does that mean, that the program
> is
> unable to open an interface with the device ?
>
> Thanks,
> Rafi SM
>
> --- Steve Ehrenfried <email@hidden> wrote:
>
> > Are you sure that the "open" worked? I notice that
> > you're calling it with the "O_NONBLOCK" flag which
> > means open could return without actually opening
> the
> > file. Have you tried running it in a debugger?
> It's
> > nearly impossible to debug it without more info,
> > unless it's pointing out obvious errors which
> > somebody
> > else has already done.
> >
> > -Steve
> >
> > --- mohamed rafi <email@hidden> wrote:
> >
> > >
> > > I had tried that one too.... Still no difference
> > :-(
> > >
> > > Regards
> > > Rafi
> > >
> > > > strlen() returns the length of zero-terminated
> C
> > > > strings. Perhaps sizeof()
> > > > would work better.
> > > >
> > > > Steve
> > > >
> > > > > From: mohamed rafi <email@hidden>
> > > > > Date: Wed, 16 Feb 2005 15:52:05 -0800 (PST)
> > > > > To: <email@hidden>
> > > > > Subject: Request not getting sent to Device.
> > > > >
> > > > > Hi,
> > > > >
> > > > > I have a Serial Device, which I have
> connected
> > > to
> > > > my
> > > > > Mac through a Keyspan. I am trying to do
> Baud
> > > > > Synchronisation of the device, before
> sending
> > > > > commands/requests to it. I am using C to do
> > the
> > > > same.
> > > > >
> > > > > Following is the piece of code I am using
> for
> > > > that:
> > > > >
> > > > > DEVICENAME = "/dev/tty.USA19H1b1P1.1"
> > > > > fd = open(DEVICENAME, O_RDWR | O_NONBLOCK);
> > > > > ..
> > > > > unsigned char baudArray[] =
> > > > >
> > {0x01,0x00,0x96,0x00,0x02,0x95,0x4d,0x54,0x19};
> > > > >
> > > > > k = write(fd, baudArray, strlen(baudArray));
> > > > >
> > > > > How do I ensure that it gets transmitted to
> > the
> > > > > device, and how can I get the output from
> the
> > > > device
> > > > > for this ?
> > > > >
> > > > > Thanks,
> > > > > Rafi SM
> > > >
> > > >
> > > >
> _______________________________________________
> > > > Do not post admin requests to the list. They
> > will
> > > be
> > > > ignored.
> > > > Usb mailing list (email@hidden)
> > > > Help/Unsubscribe/Update your Subscription:
> > > >
> > >
> >
>
http://lists.apple.com/mailman/options/usb/email@hidden
> > > >
> > > > This email sent to email@hidden
> > > >
> > >
> > >
> > >
> > > __________________________________
> > > Do you Yahoo!?
> > > Meet the all-new My Yahoo! - Try it today!
> > > http://my.yahoo.com
> > >
> > >
> > > _______________________________________________
> > > Do not post admin requests to the list. They
> will
> > be
> > > ignored.
> > > Usb mailing list (email@hidden)
> > > Help/Unsubscribe/Update your Subscription:
> > >
> >
>
http://lists.apple.com/mailman/options/usb/email@hidden
> > >
> > > This email sent to email@hidden
> > >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam? Yahoo! Mail has the best spam
> > protection around
> > http://mail.yahoo.com
> >
>
>
>
> __________________________________
> Do you Yahoo!?
> Meet the all-new My Yahoo! - Try it today!
> http://my.yahoo.com
>
>
>
__________________________________
Do you Yahoo!?
Meet the all-new My Yahoo! - Try it today!
http://my.yahoo.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Usb mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/usb/email@hidden
This email sent to email@hidden