ts-7000
[Top] [All Lists]

RE: [ts-7000] Block problem when reading from a serial port.

To: <>
Subject: RE: [ts-7000] Block problem when reading from a serial port.
From: "Rodrigo Varas" <>
Date: Mon, 29 Sep 2008 11:06:57 -0700
Hi Dave,

Thanks for your detailed answer.

I don't think we are using any extra port on TS but the regular ones
includes in the basic board.
One of our developer report that the close(fd) on that serial port file
descriptor does not unblock the read().
I will double check but I'm pretty sure they try that.

The use of the select function seems to be a partial solution that could
work for us but I was wondering why this fails.

I wrote before a layer that works for other platforms like Win32 and then I
use another function to unblock the thread.
Then we migrate the layer to Linux only to found that stopping the thread is
really complicated.

Somebody in this group reply about sending a signal using pthread_kill?

Will this unblock the 'read' statement for the target thread?
I assume read will return an amount read of -1 or 0.
If that is the case we could immediately detect that the driver needs to be
closed and gracefully exit the thread.

Rodrigo.


-----Original Message-----
From:   On Behalf Of
David Hawkins
Sent: Monday, September 29, 2008 9:09 AM
To: 
Subject: Re: [ts-7000] Block problem when reading from a serial port.

Hi Rodrigo,

> Here is problem, everything works ok except when we want to close the 
> serial port.
>
> We want to unblock the serial port 'read' and have the thread to finish.
> 
> We have try many different things to the file descriptor, like close the 
> file, changing the blocking mode, opening the port again,etc..
> 
> What would be the right way to force the read to return with a -1 ( or 
> EOF) to allow the thread to finish as a good citizen..?

I would think, the device driver should have read unblock if you
close its file descriptor. However, if this is a driver written
by TS for a custom serial port (an extra port), then it could be
something that was accidentally 'missed' from their driver.

Rather than opening a thread to perform a blocked read, you could
use the thread to call select() on the file descriptor opened in
non-blocking mode. The use of the select() call requires
the driver to have implemented the poll() driver call.

In the case of using select, the select() call should unblock if
the device is closed. If the driver is 'broken', you could have
the select call wait on two handles; the serial port, and
a fifo/pipe. When you want to kill the thread, write to the
pipe to unblock select, and then the thread can shut down.

At least with the select method, you can work around limitations
of the driver (if that is indeed the cause). I'd recommend writing
some test code that works on an x86 serial port (16550 UART),
and then see if that same code fails to work on the TS board.

Just some ideas for you ...

Cheers,
Dave


------------------------------------

Yahoo! Groups Links




------------------------------------

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/

<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU