Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Serial Port programming - Yes I read the howto
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
msalerno
Veteran
Veteran


Joined: 17 Dec 2002
Posts: 1338
Location: Sweating in South Florida

PostPosted: Mon Jul 11, 2005 8:27 pm    Post subject: Serial Port programming - Yes I read the howto Reply with quote

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
View user's profile Send private message
Carnildo
Guru
Guru


Joined: 17 Jun 2004
Posts: 594

PostPosted: Tue Jul 12, 2005 5:09 am    Post subject: Reply with quote

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
View user's profile Send private message
msalerno
Veteran
Veteran


Joined: 17 Dec 2002
Posts: 1338
Location: Sweating in South Florida

PostPosted: Tue Jul 12, 2005 4:26 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
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