Subject: Re: programming serial port
To: None <port-macppc@netbsd.org>
From: Joachim Thiemann <joachim.thiemann@gmail.com>
List: port-macppc
Date: 01/15/2007 10:34:18
On 13/01/07, Tomas D <u0giene@yahoo.com> wrote:
> Hi,
> I'm trying to find some info on how to do basic programming on mac serial port.
> I came up with the followin algorithm
> set pin1 high
> |
> check if pin2 is high
>          |
>         / \
> High     Low -> go to check if pin2 is high
> |
> write character to a file -> go to check if pin2 is high
>
> pin1 and pin2 are connected to a shaft sensor which gives n amount of short circuits in 1 revolution
>
> pin1
>   |
>  == shaft sensor
>   |
> pin2
>
> uname (just in case)
> [wally@macppc ~]$ uname -a
> NetBSD macppc 3.0 NetBSD 3.0 (GENERIC) #0: Mon Dec 19 01:25:38 UTC 2005  builds@b2.netbsd.org:/home/builds/ab/netbsd-3-0-RELEASE/macppc/200512182024Z-obj/home/builds/ab/netbsd-3-0-RELEASE/src/sys/arch/macppc/compile/GENERIC macppc
>
>
> Thanks everyone for your ideas

Hi, a couple of suggestions:  you probably wouldn't need 2 pins, just
one, and connect it with a pull-up resistor to the "high" voltage
(usually between +5 and +12V), the have the other end of the sensor go
to the "low" voltage (-5 to -12 V, though sometimes grounding it will
work, too)

The only pins you can generally poll directly on a serial port are the
modem control lines, "Carrier Detect" for example.

However, a polling loop like you described is never a good idea, since
it will eat up many CPU cycles doing nothing and is likely to miss
pulses if they are coming too fast.

While I don't know the specifics of your project, I would probably add
a little cheap hardware: get yourself an old mouse with a ball (USB,
ADB, or even serial - you can probably find these for near-free at any
computer junk store) and hack into the rotary encoder for one of the
axes... (a (PC) serial mouse generally is regular RS-232 at a low
speed)

Joe.