Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Com and Serial Ports

by diskcrash (Hermit)
on Sep 24, 2003 at 23:33 UTC ( #294037=note: print w/replies, xml ) Need Help??

in reply to Com and Serial Ports

Dear Nuno,

Take a look at the code at this node I use to read a Geiger Counter.

Serial Port

Hope it helps.


Replies are listed 'Best First'.
Re: Re: Com and Serial Ports
by nofernandes (Beadle) on Sep 26, 2003 at 11:20 UTC

    Thank you very much for your tip!

    In fact that solved my problem, thank you.

    I have one more question. I´m using this code in a machine with Linux, and the code catches the data that comes from the serial port. The problem is that i cannot capture special caracters such as: é or olá, any caracter that as an accent!

    For example: it appears "informa‡”es" instead of "informações"

    Is there any way of resolving this?

    Thank you very much for your help.


      If you want to be able to read utf data from your serial port, then you probably need to be using at least perl 5.8, and using the new "IO layer", ':utf8' on the open to set the filehandle to expect utf-8 data.

      If your using Device::Serial, you probably aren't doing the open yourself, in which case you need to get hold of the filehandle being used (which appears to be available via $PortObj->{FD}) and use binmode to set the IOlayer to utf8

      use Device::SerialPort; my $PortObj = Device::SerialPort( ... ); binmode $PortObj->{FD}, ':utf8'; ...

      Note: This is an educated guess. It's based upon my use of Win32::SerialPort (of which Device::SerialPort is an emulation), but I've no way to verify the speculation.


      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.

        I have this code that i got from here.

        I´ve used as you said the binmode $ob->{LOG}, ':UTF8'; but the problem is that it can´t catch the correct format!

        How can i change the format in order to save the data from the serial port to the file correctly?

        #!/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: $!"; $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"; binmode $ob->{LOG}, ':UTF8'; select(LOG), $| = 1; # set nonbuffered mode, gets the chars out NOW open(DEV, "<$PORT") || die "Cannot open $PORT: $_"; while($_ = <DEV>){ print LOG $_; } undef $ob;

        Thank you very much!

        Nuno Fernandes

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://294037]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2018-01-19 16:20 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (221 votes). Check out past polls.