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!
--
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!
--