recording hardware discrete via serial port?

From: Kevin Horton (khorton01_at_rogers.com)
Date: 03/06/05


Date: Sun, 6 Mar 2005 17:07:27 -0500
To: beginners@perl.org

I'm trying to find a way to record the status of a 14v hardware
discrete. The discrete signal will either be 14V or 0V. I've got a
USB to serial adapter, and I'm hoping to find a way to use that to
get the signal into my computer so perl can log the status of the
discrete.

Looking at various RS-232 specs on the web, it looks like there are
three lines that could legitimately be at either 14V of 0V, such as
Ring Indicator, Clear to Send or Data Set Ready.

Serial Port info: http://www.anotherurl.com/library/rs232.htm

I've set up a test where I can put 12V into a serial port line, but I
can't make perl see it. I've been trying to use the
Device::SerialPort module, as it seemed to have the capability I
needed. Is there another module that is better suited, or some basic
perl function, or system call I should be using instead?

My test script looks like:

#!/usr/bin/perl
#
# Test to see if Device::SerialPort can be used to monitor an event marker

use strict;
use warnings;

use Device::SerialPort qw( :STAT );
use Time::HiRes qw( time sleep );

my $duration = "10"; # run duration, in seconds
my $now_time = "0";

my $PortName = "/dev/tty.USA49W1b1P4.4";
my $EventMarker = new Device::SerialPort ( $PortName )
        || die "Can't open $PortName: $!\n";

my $start_time = time;
while (time < ($start_time + $duration)) {
   $now_time = time;
   my $ModemStatus = $EventMarker->modemlines;
   if ($ModemStatus & $EventMarker->MS_RING_ON) {
     print "$now_time\tevent marker detected *************\n";
   } else {
     print "$now_time\tnada\n";
   }
   sleep 0.1;
}

exit;

=============
Note: I also tried it after having set the various serial port
parametres (baud, data bits, stop bits, etc), but that made no
difference to the result.

Test setup: 12V power supply, with the ground hooked to pin 5 of the
serial port's 9 pin connector, and 12V hooked to pin 9, via a
momentary switch. A voltmeter verifies 12V between pins 9 and 5 when
the switch is depressed. The same test was also done looking for
DCD, using pin 1, and having perl look for $EventMarker->MS_RLSD_ON.

Thanks in advance for any advice,

Kevin Horton



Relevant Pages

  • Re: Alpha DB9 to DECserver RJ45 cable?
    ... > a straight or crossover network cable. ... plugging into a PC serial port, that also works fine with a serial port ... 16-line (no modem control) version of the DS700. ... to pin 5 and the other one would only work with Tx Gnd ...
    (comp.os.vms)
  • Re: Log Phone Calls
    ... In that I would have to get a 25/9 pin serial cable to be able to ... Many centuries ago, the serial port on many ... communication devices was standardised to a 25 pin/socket connector, ... and 3 (no pins in these cables) were swapped, and a heap of others were ...
    (microsoft.public.vb.general.discussion)
  • Re: Conneting hardware with SPC output to computer
    ... It has a footswitch with a 25 pin-female connector that connects to computer and a 10 pin rectangular RS-232 connector that attaches to the level. ... it has a serial port with RS-232 serial output. ... you'd want to automate this somewhat. ...
    (microsoft.public.windowsxp.hardware)
  • Re: zebra cameo2
    ... Ohh, in my case the printer ask for a PIN, i think i should contact the ... just write whatever out the serial port. ... If you're using bluetooth you need to have the port paired with the ... we use Com1 for bluetooth and Com5 for cable with our Symbol devices and ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Log Phone Calls
    ... Many centuries ago, the serial port on many communication devices was standardised to a 25 pin/socket connector, depending on whether they were Data Communication Equipment or Data Terminal equipment ... Bugger it, the standard should have just specified pin OR socket connectors, not both for the two groups ... Yep, you had to have another type of cable where sockets 2 and 3 (no pins in these cables) were swapped, and a heap of others were hooked up in various ways so that eventually the computers could talk. ...
    (microsoft.public.vb.general.discussion)