Your applying binmode to the output file, by which time I think the damage has already been done.
What I was suggesting was to apply binmode to the input file. Whilst you don't open this directly, looking at the source of Device::SerialPort, I noticed that the filehandle it use for the serial port is accessable via the object as $obj->{FD}, hence it should be possible to enable the :utf8 IO layer on it using the snippet I included. I've modified your snippet
#!/usr/bin/perl
use warnings;
use Device::SerialPort 0.22;
$LOGDIR = "/home/neo/telex_lusa/log";
$LOGFILE = "geiger.log";
$PORT = "/dev/ttyS0";
$ob = Device::SerialPort->new ($PORT)
|| die "Can't Open $PORT: $!";
## MODIFIED HERE!!
## FD is the key used internally by D::SP for the file handle
## NOTE: The IOLayer is ':utf8' not ':UTF8'!
binmode $ob->{FD}, ':utf8';
$ob->baudrate(2400) || die "failed setting baudrate";
$ob->parity("none") || die "failed setting parity";
$ob->databits(8) || die "failed setting databits";
$ob->stty_icrnl(1) || die "failed setting convert cr to new line";
$ob->handshake("none") || die "failed setting handshake";
$ob->write_settings || die "no settings";
open(LOG,">>${LOGDIR}/${LOGFILE}")
||die "can't open smdr file $LOGDIR/$LOGFILE for append: $SUB $!\n";
select(LOG), $| = 1; # set nonbuffered mode, gets the chars out NOW
open(DEV, "<$PORT") || die "Cannot open $PORT: $_";
while($_ = <DEV>){
print LOG $_;
}
undef $ob;
As I said, I've no way to verify this. For the record and those that come after you, please post a reply stating one way or another whether this works.
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.
|