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.


In reply to Re: Re: Re: Com and Serial Ports by BrowserUk
in thread Com and Serial Ports by nofernandes

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.