Re: Reading serial port lines

From: AlanGLLoyd (alanglloyd_at_aol.com)
Date: 10/11/04


Date: 11 Oct 2004 18:47:26 GMT

In article <Xns957F6D0B32C55pj12345pjpj@216.196.97.142>, Phil
<philj@xxspearnet.net> writes:

>I am writing a simple program to be triggered by an external
>switch.
>The switch will be normally closed and the program watches for the
>switch opening.
>
>The program would sit idly watching for the switch opening and when
>detected, would perform its function, then delay for about 5 to 10
>seconds and resume watching for switch opening again.
>
>It would be very easy to use a joystick port but many computers do
>not have one. Since virtually all computers have an unused serial
>port, it would be much more convenient to use that rather than a
>joystick port.
>
>I have never used a serial port for this, but it seems that it
>should be easily implemented. (But then everything I have no
>knowlege of seems easy...) Perhaps the DSR / DTR lines could
>be used?
>
>Has anyone used a serial port in this manner? How did you do it?
>

Yes - I wanted to use a footswitch with three switches - and I found it a can
of a few worms, but made it work.

Basically you SetComm with a DCB structure to initialise the port and set one
of the protocol pins as a supply voltage for the external switch(es). Then you
open a file on the port (using CreateFile) with a FILE_OVERLAPPED FLAG and
create an event on the file. You then WaitForSingleObject on the event. The
WFSO is given a time and is reset if it expires on time. If it returns with an
event you get the modem status. If this is > 0 you check the modem status for a
flag denoting which pin has changed its status to high. If the ModemStatus is 0
you check the CommEvent to see which Item has changed to low (CommEvent's flag
are high for either a pin going high or going low, ModemStatus is the pin
status itself, high for high and low for low)

BUT ... when an pin event occurs the winport appears to pass a number of
varying (and in error) CommEvents, of which only the last is valid, so one has
to start a timer for each triggered event, and only if another has not come
along for 50 mS (or so) do you take that last event.

I tried using some commercially available components but they all showed this
effect. In the end we used Winsoft's TCommPort and added a lag as above to the
events (we were not using it in a time-critical system).

It all went away when we went to a usb footswitch to be our input. But the
footswitch came with a driver which ended in an MCI interface and worked OK.

If you are not discouraged by now <g> I could dig you out some code, but you
would have to consult MSDN Library to understand or change it - its not for the
fainthearted.

Alan Lloyd
alanglloyd@aol.com



Relevant Pages

  • Re: [patch -mm 20/20 RFC] chardev: GPIO for SCx200 & PC-8736x: add sysfs-GPIO interf
    ... We need a standard rep for GPIO in sysfs, ... GPIO hardware design appears to have 2 top-level factors; ... change will also exhibit in the port attr too. ... if a pin is output only, it shouldnt have an _output_enabled attr. ...
    (Linux-Kernel)
  • Re: OT: DOS programming EPP
    ... There seems to be *no* specifications or equivalent circuits for the parallel port as implemented on the ASICs used in modern PCs. ... it is completely unknown as to the maximum safe sink current to a logic low pin or the maximum source current from a logic high pin. ... The EPP page assumes you did. ... CONTROL bit 5 defaults low. ...
    (sci.electronics.design)
  • Re: Any Plug and Play device shuts down PC
    ... Where 'X' represents each pin on the USB header. ... The only other thing that can be done is to adopt the way the rear port on ... if you used a wire ...
    (microsoft.public.windowsxp.hardware)
  • Re: bike computer to PC interface
    ... I have a pic of a basic circuit I found but don't know how it works ... Basically it has a connection to pin ... When the com port is opened, ... When the wheel contact was made, ...
    (sci.electronics.basics)
  • Re: PICMicro pin goes up and stays up
    ... > to go high or low and then sends the state of this port ... You need something to pull the pin down when the button isn't pressed. ... It's an input pin and has a very high input impedance. ... The gate on a mosfet transistor behaves the same as an input pin on a ...
    (comp.robotics.misc)