View previous topic :: View next topic |
Author |
Message |
msalerno Veteran
Joined: 17 Dec 2002 Posts: 1338 Location: Sweating in South Florida
|
Posted: Mon Jul 11, 2005 8:27 pm Post subject: Serial Port programming - Yes I read the howto |
|
|
Anyone know any serial monitoring tools that can monitor DSR?
I have a device that uses the dsr for communications. Basically what I am trying to do is get a count of how many pulses it sends per second. I have a script that counts the pulses, but there is something wrong. It is counting too many pulses. I think that what is happening is that it is counting one pulse many times. I know this because I have some windows software that works, and when I compare the output of the windows software to the output of my script, my script is way off. If anyone out there could point me in the correct direction I would be very happy. It's tough to find informaion about the DSR lines. I have found lots of tools that monitor everything but the handshake lines. Anyone have any tips or tools?
Code: | #!/usr/bin/perl -w
use strict;
use Time::HiRes qw(usleep);
use Device::SerialPort qw( :PARAM :STAT 0.07 );
my %logged;
my @then;
my $PortObj = new Device::SerialPort ('/dev/ttyS0') || die "Cannot open Port: $!\n";
while () {
my $ModemStatus = $PortObj->modemlines;
my $now = sprintf '%02d-%02d-%02d', ( localtime )[ 2, 1, 0 ];
push @then, $now;
push @then, $now if $#then < 1;
shift @then if $#then > 1;
if (!exists($logged{$now})){
$logged{$now} = 0;
my $val1 = sprintf "%.2f", $logged{$then[-2]}*3.4;
my $val2 = sprintf "%.2f", $logged{$then[-2]}*2.5;
print "Then:$then[0] - $logged{$then[0]} - $val1 - $val2\n";
}
my $pulse = 0!=($ModemStatus & MS_DSR_ON);
$pulse = 0 if !$pulse;
$logged{$now} = $pulse + $logged{$now};
if ($pulse == 1){
usleep(1000);
}
}
$PortObj->close; |
Last edited by msalerno on Tue Jul 12, 2005 7:40 pm; edited 2 times in total |
|
Back to top |
|
|
Carnildo Guru
Joined: 17 Jun 2004 Posts: 594
|
Posted: Tue Jul 12, 2005 5:09 am Post subject: |
|
|
If I'm reading that correctly, you're updating your counter every time you pass through the loop that the signal line is high. What you want to be counting is rising edges -- signal line transitions from low to high. |
|
Back to top |
|
|
msalerno Veteran
Joined: 17 Dec 2002 Posts: 1338 Location: Sweating in South Florida
|
Posted: Tue Jul 12, 2005 4:26 pm Post subject: |
|
|
The device (an anemometer) does not use a baud rate. The windows software looks at the signal from the reed switch in the anemometer head and measures the time between transitions of the switch. It sends the signal through the DSR channel. The conversion between switch pulses per second and MPH are either 1 pulse/second = 2.5 MPH or 1 pulse/second = 3.4 MPH. I think that I need to debounce the opening and/or closing transitions of the reed switch. I added a 1 millisecond delay once I see a 1 in the $pulse variable, but I am still getting crazy numbers. I have updated the script in my original post to show my changes. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|