4 Replies Latest reply on Dec 2, 2014 9:52 AM by Xuchun

    Print to /dev/ttyMFD1 won't work using Perl script

    Xuchun

      Hello,

       

      When I use "printf [data] > /dev/ttyMFD1" in Edison shell, I can successfully display data on LCD or command my Roomba. But when I put it on a perl script and run the script, I failed to display anything on LCD or control Roomba. The syntax seems ok. I have no idea what went wrong. Any comment?

        • 1. Re: Print to /dev/ttyMFD1 won't work using Perl script
          mhahn

          how does your perl script look like? How do you run it? what's the log message you get?

          • 2. Re: Print to /dev/ttyMFD1 won't work using Perl script
            Xuchun

            Hi mhahn,

             

            Thank you for your prompt reply. Here is the script:

             

             

            #!/usr/bin/perl

            #

            # roombacmd.pl -- Roomba command-line tool,  part of RoombaComm

            #

            # http://roombahacking.com/

            #

            # Copyright (C) 2006, Tod E. Kurt, tod@todbot.com

            #

            #

             

            # in case we have stty in the current directory

            # $ENV{'PATH'}="$ENV{PATH}:.";

             

             

            sub usage() {

                printf "Usage: $0 {init|note|light|sensor|spinright|stop}\n";

                exit(1);

            }

             

             

            sub roomba_init() {

                # this style stty is for linux

                system("stty -F $PORT 115200 raw -parenb -parodd cs8 -hupcl -cstopb clocal");

                printf "\x80" > $PORT;   sleep 1;

                printf "\x82" > $PORT;   sleep 1;

            }

            sub roomba_note() {

                printf "\x8C\x02\x01\x3C\x20\x8D\x02" > $PORT;

            }

            sub roomba_light() {

                printf "\x8B\x3F\x80\x80" > $PORT;

            }

            sub roomba_sensor() {

                printf "\x8e\x00" > $PORT;

            }

            sub roomba_spinright() {

               printf "\x58 hello goodnoon" > $PORT;

            }

            sub roomba_stop() {

                $vel="\x00\x00";

                $rad="\x00\x00";

                printf "\x89$vel$rad" > $PORT;

            }

             

            # If not enough arguments were passed, return

            usage() if( @ARGV < 2 );

             

            $PORT = $ARGV[0];

            $CMD  = $ARGV[1];

             

            if( $CMD eq 'init' ) {

                roomba_init();

            }

            elsif( $CMD eq 'note' ) {

                roomba_note();

            }

            elsif( $CMD eq 'light' ) {

                roomba_light();

            }

            elsif( $CMD eq 'sensor' ) {

                roomba_sensor();

            }

            elsif( $CMD eq 'spinright' ) {

                roomba_spinright();

            }

            elsif( $CMD eq 'stop' ) {

                roomba_stop();

            }

            else {

                usage();

            }



            And I ran this command:  ./roombacmd.mpl /dev/ttyMFD1 spinright

             



            • 3. Re: Print to /dev/ttyMFD1 won't work using Perl script
              mhahn

              I suppose you do have the mini breakout board?

              Are you sure you want "/dev/ttyMFD1" and not "/dev/ttyMFD2"?

               

              Just ran following on the console:

              perl -e 'open SERIAL, ">/dev/ttyMFD2"; printf SERIAL "Hello World";'

               

              Printed my "Hello World" nicely to tty

              • 4. Re: Print to /dev/ttyMFD1 won't work using Perl script
                Xuchun

                Hi mhahn,

                 

                Your script works! I have no knowledge about perl. And I just want to try out some code example. The script I posted was supposed to run using microperl. I think this is why it won't work when using perl. I use the Edison arduino board. So it's ttyMFD1. Have a nice day!