[Pythonmac-SIG] ctb module question
Sean Hummel
hummelsean@mac.com
Tue, 21 Aug 2001 23:08:07 -0700
Ticks are 1/60th of a second. No matter which Macintosh you are on, if you
are using Classic OS.
> From: Lawrence Hudson <lhudson@geminidataloggers.com>
> Date: Tue, 21 Aug 2001 09:35:37 +0100
> To: "Pythonmac-SIG (E-mail)" <Pythonmac-SIG@python.org>
> Subject: [Pythonmac-SIG] ctb module question
>
> Hello all,
>
> I have a question about serial comms using the ctb module. The
> documentation on connection objects
> (http://www.python.org/doc/current/mac/connection-object.html) indicates
> that timeout values are in seconds.
> Apple's documentation on the communications toolbox (PDF at
> http://developer.apple.com/techpubs/macos8/NetworkCommSvcs/CommToolboxUtilit
> ies/commtoolbox.html) indicates timeouts are in ticks. I can find no
> translations from seconds to ticks in the source and no native function to
> do it?
>
> I am very new to Mac development (and Macs at all, to be honest) so I may
> well have missed something obvious!
>
> A little script I used to investigate:
>
>
> import time, MacOS
> import ctb
>
> ticks_per_ms = None
>
> def ticks_per_millisecond():
> global ticks_per_ms
> if not ticks_per_ms:
> start = MacOS.GetTicks()
> time.sleep(1.0)
> ticks_per_ms = (MacOS.GetTicks()-start) / 1000.0
> return ticks_per_ms
>
> def timed_read(port, timeout):
> port.Idle()
> start = time.time()
> port.Read(1024, ctb.cmData, timeout*ticks_per_millisecond())
> return time.time()-start
>
> p = ctb.CMNew('Serial Tool', None)
>
> port_name = 'Printer Port USB'
> baud = 1200
> config = 'Baud %d Databits 8 Parity None StopBits 1 Port "%s" Handshake None
> HoldConnection False RemindDisconnect False' % (baud,port_name,)
>
> p.Open(10)
> p.SetConfig(config)
> p.Idle()
>
> print '%r ticks per millisecond'%ticks_per_millisecond()
> print 1.0, timed_read(p, 1000)
> print 2.0, timed_read(p, 2000)
> print 5.0, timed_read(p, 5000)
>
> p.Close(-1,1)
>
>
> Output when run on my iMac (MacOS 9.0.4)
>
> 0.060999999999999999 ticks per millisecond
> 1.0 1.02847003937
> 2.0 2.04259109497
> 5.0 5.08227872849
>
>
> Thanks,
> Lawrence Hudson
>
>
>
> _______________________________________________
> Pythonmac-SIG maillist - Pythonmac-SIG@python.org
> http://mail.python.org/mailman/listinfo/pythonmac-sig