USB/Serial adapters and sleep mode on OS X

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

USB/Serial adapters and sleep mode on OS X

David Fleming-2
After doing lots of testing, I've come up with some interesting observations.
When OS X goes to sleep, either from an idle timeout or a forced sleep (selecting 'Sleep' from the Apple menu), *some* USB to Serial adapters can end up in an unresponsive state after OS X wakes up. I've tested this with the three most common adapters, Keyspan, FTDI and Prolific. The Prolific adapters seem to tolerate a sleep cycle just fine without any untoward side effects. But the Keyspan and FTDI adapters get very grumpy when they wake up after being put to sleep. In the case of the Keyspan, all open connections are closed when it goes to sleep. Upon awakening, the Keyspan port remains closed until the app re-opens it. But.. I found that if an app is actively polling the serial port at the time it is put to sleep, for example while W2.exe is running and polling the port very rapidly, the adapter can wake up in an unresponsive, or unreliable state. The Keyspan adapter must be unplugged and replugged to recover. This happens every time with the
 Keyspan adapter IF it is being actively polled at the time it goes to sleep. If it is not being polled at the time the OS goes to sleep, for example while the W2 Utility is connected but idle, the Keyspan will wake up healthy and responsive. It's not necessary to unplug and replug to get it back, but the port still remains closed until it is re-opened by the app. In the case of the FTDI adapter, the port is not closed when it goes to sleep. If it is not being actively polled at the time it goes to sleep, then it wakes up healthy and all is well. But if it IS being polled when it goes to sleep, for example by W2.exe, then it wakes up totally messed up and must be unplugged and replugged to regain consciousness. 
Thanks, Dale, for pointing this out. I'm surprised this hasn't come up before. I've been writing serial port apps for the Mac for many years. This is the first time I've had someone point out this problem when an app is running when the Mac goes to sleep.
I will be adding code to all my apps to close the serial port whenever the computer is going to sleep and to reopen the port upon awakening. In the mean time, users of the Keyspan and FTDI USB/Serial adapters should close all apps that use the serial port before putting the Mac to sleep (W2.exe, W2 Utility, K3 Utility, and P3 Utility) .
David, W4SMT

--- On Fri, 9/3/10, dalej <[hidden email]> wrote:













 
 



 


   
     
     
      Hello again David,
To follow up.  I also get a spinning beach ball sometimes, which I just did now after waking it up.  I then have to force quit the W2 app and restart it after unplugging and replugging the USA19 adapter.  
73Dale, k9vuj

__,_._,___


 



 








______________________________________________________________
Elecraft mailing list
Home: http://mailman.qth.net/mailman/listinfo/elecraft
Help: http://mailman.qth.net/mmfaq.htm
Post: mailto:[hidden email]

This list hosted by: http://www.qsl.net
Please help support this email list: http://www.qsl.net/donate.html
Reply | Threaded
Open this post in threaded view
|

Re: USB/Serial adapters and sleep mode on OS X

Kok Chen
On Sep 5, 2010, at 5:21 PM, David Fleming wrote:

> But the Keyspan and FTDI adapters get very grumpy when they wake up after being put to sleep.

The way I handled this in µH Router (the microHAM devices uses FTDI chips) is to register for MacOS X Power Manager callbacks.

Before the Mac OS X Power Manager sends the hardware into sleep mode, it will call back and at that time, I do an ordered shutdown of any opened microHAM ports.  When the Power Manager again calls back when the machine wakes up, I reopen the serial port (setting baud rate and restart the microHAM watchdog timer) of any microHAM box(es) that was(were) previously connected.

When the Mac OS X Power Manager calls back before going to sleep, you also have the option of telling the system to terminate the sleep process.

See http://developer.apple.com/mac/library/qa/qa2004/qa1340.html .

For example, if there is something critical that is happening, you can terminate sleeping, finish anything that you are doing that cannot be stopped (like changing the firmware of the K3 :-), and when that task is completed, finally ask the Power Manager to go to sleep.

73
Chen, W7AY

______________________________________________________________
Elecraft mailing list
Home: http://mailman.qth.net/mailman/listinfo/elecraft
Help: http://mailman.qth.net/mmfaq.htm
Post: mailto:[hidden email]

This list hosted by: http://www.qsl.net
Please help support this email list: http://www.qsl.net/donate.html
Reply | Threaded
Open this post in threaded view
|

Re: USB/Serial adapters and sleep mode on OS X

David Fleming-2
This is precisely how I'm doing it, but with a plug-in. I have four callback events that give complete control of the sleep cycle.

Thanks, Chen.

David, W4SMT

--- On Sun, 9/5/10, Kok Chen <[hidden email]> wrote:

> > But the Keyspan and FTDI adapters get very grumpy when
> they wake up after being put to sleep.
>
> The way I handled this in µH Router (the microHAM devices
> uses FTDI chips) is to register for MacOS X Power Manager
> callbacks.
>
> Before the Mac OS X Power Manager sends the hardware into
> sleep mode, it will call back and at that time, I do an
> ordered shutdown of any opened microHAM ports.  When
> the Power Manager again calls back when the machine wakes
> up, I reopen the serial port (setting baud rate and restart
> the microHAM watchdog timer) of any microHAM box(es) that
> was(were) previously connected.
>
> When the Mac OS X Power Manager calls back before going to
> sleep, you also have the option of telling the system to
> terminate the sleep process.
>
> See http://developer.apple.com/mac/library/qa/qa2004/qa1340.html
> .
>
> For example, if there is something critical that is
> happening, you can terminate sleeping, finish anything that
> you are doing that cannot be stopped (like changing the
> firmware of the K3 :-), and when that task is completed,
> finally ask the Power Manager to go to sleep.
>
> 73
> Chen, W7AY
>
> ______________________________________________________________
> Elecraft mailing list
> Home: http://mailman.qth.net/mailman/listinfo/elecraft
> Help: http://mailman.qth.net/mmfaq.htm
> Post: mailto:[hidden email]
>
> This list hosted by: http://www.qsl.net
> Please help support this email list: http://www.qsl.net/donate.html
>

______________________________________________________________
Elecraft mailing list
Home: http://mailman.qth.net/mailman/listinfo/elecraft
Help: http://mailman.qth.net/mmfaq.htm
Post: mailto:[hidden email]

This list hosted by: http://www.qsl.net
Please help support this email list: http://www.qsl.net/donate.html