Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

How to send long sting Device::SerialPort

by rkrasowski (Sexton)
on Dec 07, 2013 at 21:47 UTC ( [id://1066156]=perlquestion: print w/replies, xml ) Need Help??

rkrasowski has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am sure that answer to this problem is simple. What I am trying to do is to communicate over serial port using Device::SerialPort. The problem is when I am trying to send long string. Only a part of it is transmitted. I understand that buffer has limits. I can do it while openning file and sending data from file using while <file >, but for string?? Here is an example of my code ( numbers up to 8 are sent, nothing after that:

a
#!/usr/bin/perl use strict; use warnings; use Device::SerialPort; my $PORT = "/dev/ttyO1"; my $ob = Device::SerialPort->new($PORT) || die "Can't Open $PORT: $!"; $ob->baudrate(115200) || die "failed setting baudrate"; $ob->parity("none") || die "failed setting parity"; $ob->databits(8) || die "failed setting databits"; $ob->handshake("none") || die "failed setting handshake"; $ob->write_settings || die "no settings"; $| = 1; my $string = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\n"; $ob->write( "$string\n");

Any idea how to fix it?? Thanks in advance. Robert

Replies are listed 'Best First'.
Re: How to send long sting Device::SerialPort
by BrowserUk (Patriarch) on Dec 07, 2013 at 22:00 UTC
    numbers up to 8 are sent, nothing after that

    That implies that your UART (or UART emulation) has a hard limit buffer of 15 -- strange in this day and age, but not impossible -- in which case, perhaps it will like it better if you only send a max of 15-bytes at a time.

    Try adding your own write method wrapper that breaks the string up into 15-byte chunks. Eg.

    sub myWrite { my( $port, $data ) = @_; for my $chunk ( unpack '(a15)*', $data ) { $port->write( $chunk ); sleep 0.1; ## may not be necessary; or maybe 0.001 is enough; +experiment. } } ... # $ob->write( "$string\n"); myWrite( $ob, $string );

    Of course, if you have time to waste, you could subclass Device::Serial and override write ...


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: How to send long sting Device::SerialPort
by oiskuu (Hermit) on Dec 08, 2013 at 10:05 UTC
    Is this OMAP uart? Ordinary PC serial ports are ttySxx (for Linux at least).

    Looking at Device::SerialPort, I see it makes a promise to handle I/O in a stream-like manner for the tied filehandles. The write method is just POSIX::write underneath, so the same concerns apply as with syswrite ie. loop and check the return value.

    With a tied handle, a simple print FH $string; ought to do.

      Yes, this is BeagleBoneBlack, so OMAP UART, that's what that is. I will try today to add wrapper to devide string into 15 bytes pieces and see if that will work the way that I expect. Second part is to send stream of data via Device::SerialPort. Will se how that one will go. I will keep you updated. Thanks for help. Robert

        Supposedly, the OMAP has 6 UARTS, each with two 64 byte buffers, one for TX, one for RX. http://www.ti.com/lit/ug/spruh73i/spruh73i.pdf, page 3984, in the diagram.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1066156]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-03-29 10:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found