uncleared data on serial port problem

H

hl

Hello all,
I am trying to write a simple perl script communicate with my
serial port. Every one second, it will send a command to a
specific device(keithley 2400); and the device will response
with
some data. The problem I have right now is after the correct
first
command, the code will precede the command with the previous
data
from the device.

I am using activeperl 5.8.8 on Windows XP Home.

Here is the code:
# ==============================
open (FH,'+<','COM1') or die "failed to open serial port: $!";
open (OUT,'>',"DATA.txt") or die "failed to open data file: $!";
sub clearup {
close(FH);
close(OUT);
exit;
}
$SIG{'INT'}=\&clearup;
$|=1;
while(1){
print FH "read?\n";
$dat=<FH>;
print OUT $dat;
sleep 1;
}
#==============end==============

The data I collected from a monitering software looks like(data not
real):
send: read?..
receive: 1.82331,3.1201,8.3883,1384,0120..

this is the problem--->send: 1.82331,3.1201,8.3883,1384,0120read?..
receive: 1.9339,3.8504,9.8383,1808,3930

Any suggestions?
Thanks!
--
 
E

Ekki Plicht (DF4OR)

hl said:
Hello all,
I am trying to write a simple perl script communicate with my
serial port. Every one second, it will send a command to a
specific device(keithley 2400); and the device will response
with
some data. The problem I have right now is after the correct
first
command, the code will precede the command with the previous
data
from the device.

My first aasumption would be that the serial port has 'echo' turned on. If
thatis at all possible under Windows.
Try to find out how the serial port is configured outside of Perl (way back
at DOS times that was done with the 'mode' command).
send: read?..
receive: 1.82331,3.1201,8.3883,1384,0120..

this is the problem--->send: 1.82331,3.1201,8.3883,1384,0120read?..
receive: 1.9339,3.8504,9.8383,1808,3930

If the wrong data is actually transmitted, it's probably another problem.
Then you really take the incoming data and somehow pipe it back to the
transmit buffer... however you do this :)

Rgds,
Ekki
 
H

hl

My first aasumption would be that the serial port has 'echo' turned on. If
thatis at all possible under Windows.
Try to find out how the serial port is configured outside of Perl (way back
at DOS times that was done with the 'mode' command).



If the wrong data is actually transmitted, it's probably another problem.
Then you really take the incoming data and somehow pipe it back to the
transmit buffer... however you do this :)

Rgds,
Ekki
Thank you very much! But I am still not able to solve this problem.
1. can't find a "echo" option with "mode" command.
2. when I do debug mode as "perl -d readdat.pl" and just keep on
stepping down, everything works ok; no data echoed. But not when I
run the script.


I am really confused.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,630
Members
45,334
Latest member
66Zeinab9

Latest Threads

Top