Using RS232 for Alarm switch

Discussion in 'The Projects Forum' started by kwire, Mar 5, 2009.

  1. kwire

    Thread Starter New Member

    Feb 28, 2009
    2
    0
    Hi all,

    I am trying to use a RS232 port to test if a key switch is turned off/on so I can enable/disable the sending of E-Mails from my ZoneMinder system.

    I have done a lot of research and some experimentation and I thought I had if fugured out, but it appears I burned out my UART on the motherboard.

    Here is what I was doing, could you take a look and see if I am way off base, or maybe suggest another idea.

    First some documentation...
    Code ( (Unknown Language)):
    1.   ___________                    
    2.   \1 2 3 4 5/  Looking at pins  
    3.    \6 7 8 9/  on male connector  
    4.     ------
    5. Pin #   Acronym  Full-Name   Direction  What-it-May-Do/Mean
    6. 9-pin  
    7.  1      DCD     Data Carrier Detect<--  Modem connected to another
    8.  2      RxD     Receive Data      <--   Receives bytes into PC
    9.  3      TxD     Transmit Data     -->   Transmits bytes out of PC
    10.  4      DTR     Data Terminal Ready-->  I'm ready to communicate
    11.  5      SG      Signal Ground
    12.  6      DSR     Data Set Ready    <--   I'm ready to communicate
    13.  7      RTS     Request To Send   -->   RTS/CTS flow control
    14.  8      CTS     Clear To Send     <--   RTS/CTS flow control
    15.  9      RI      Ring Indicator    <--   Telephone line ringing
    16.  
    I used a Key Switch, a 6.8K Resistor, and a RadioShack (276-0041) 2.6V - 28 maA LED in this circuit.

    When the Key Switch is open, the LED is lit and I consider the system "Armed".


    Code ( (Unknown Language)):
    1. RS232        6.8K       Key Switch
    2. 1 CD  ______/\/\/\___________/ ___________
    3.                      |              |    |
    4.       ^              |              |    |
    5.       |              |_____>|_______|    |
    6.       |4.49V              LED            |
    7.       |                                  |
    8.                                          |
    9. 4 DTR ___________________________________|
    10.  
    The current flow and voltages are:

    Code ( (Unknown Language)):
    1.                       Switch Open           Switch Closed
    2.                 ----------------------   --------------------
    3. Resistor       :    2.67V  .373mA            3.75V    .524mA
    4. LED            :    1.82V  .373mA            0.0V      0.0mA
    5. Pin 4 to Pin 1 :    4.49V  .373mA            3.75V    .524mA
    I am using Linux and have written the following program to test if the switch is Open/Closed (Armed/Disarmed).


    Code ( (Unknown Language)):
    1. #include <string.h>
    2. #include <stdio.h>
    3. #include <fcntl.h>
    4. #include <errno.h>
    5. #include <sys/ioctl.h>
    6. #include <unistd.h>
    7.  
    8. main()
    9. {
    10.   int fd, status;
    11.   while( 1 ){
    12.     sleep( 2 );
    13.     fd = open("/dev/ttyUSB0", O_RDONLY);
    14.     if (ioctl(fd, TIOCMGET, &status) == -1) {
    15.       printf("TIOCMGET failed: %s\n", strerror(errno));
    16.     }
    17.     else {
    18.       if (status & TIOCM_CAR) {
    19.         puts("TIOCM_CAR - Alarm off!!!");
    20.       }
    21.       else {
    22.         puts("TIOCM_CAR - Alarm is armed!!!");
    23.       }
    24.     }
    25.   close(fd);
    26.   }
    27. }
    28.  
    It works just fine. The LED flashes off every two seconds when the port is being read. The voltage and current readings seem to be well within tolerance.

    However, as I said at the top, it ran for a while but now the serial port no longer works. So, can you spot something I have overlooked before I go and burn out all my COM ports?

    Thanks, Keith
     
  2. kwire

    Thread Starter New Member

    Feb 28, 2009
    2
    0
    Hi again,

    Well no body replied so I'm guessing one of three things:

    1) I stumped everybody.
    2) I didn't give enough information.
    3) Nobody has any experience with RS232 ports.

    Does anybody know another forum where I could ask?

    Thanks, Keith
     
Loading...