11 Replies Latest reply on Apr 3, 2015 11:48 AM by Jacen

    How to redirect stdin/stdout to Serial

    Jacen

      Hi All,

      Is there a way to redirect the stdin stdout to Edison Serial0, which could allow like printf() printing out to Serial instead in terminal.

      And i do only want this effecting on one program not entire system.

       

      Thanks

       

      Jacen

        • 1. Re: How to redirect stdin/stdout to Serial
          mhahn

          something like

          echo "Hello World" 2>&1 > /dev/tty<serial name>

          ?

          • 2. Re: How to redirect stdin/stdout to Serial
            Jacen

            Hi mhahn

            I want build program by c in eclipse that allow me using printf() printing out the result to Serial.

            So the way you show me may working under the terminal

            I know their are some system api to allow you redirect your stdin or stdout to somewhere like a psychical file .

            but I don't is there a way that could  redirect the stdin or strout to serial.


            Thanks

            • 3. Re: How to redirect stdin/stdout to Serial
              Intel_Alvarado

              Hi,

               

              I think what you are trying is not possible. One option would be, using Python, to save the output of a Linux command in a file and then read the file from the Python script and print it.

               

              Sergio

              • 4. Re: How to redirect stdin/stdout to Serial
                KurtE

                I know with things like popen, what it does is to fork the program, it then sets up a pipe between the two processes, where it either replaces STDOUT, or STDIN in the new process and then execs the target program, which assuming the pipe is setup to output stuff from the created app to the original app, then STDOUT is replaced with the pipes (input) file handle...

                 

                So with what you are wanting to do, you might be able to do it, by opening a handle to the output serial port your wish to output to, then maybe use dup2, to duplicate the handle into the stdout position.

                 

                Not sure if I am explaining this overly well.

                 

                Kurt

                • 5. Re: How to redirect stdin/stdout to Serial
                  Jacen

                  Yeah, your are right ,that is the way. But i am not very clear about how to implement code. i am still trying.

                  • 6. Re: How to redirect stdin/stdout to Serial
                    Intel_Alvarado

                    Hi Jacen,

                     

                    Were you able to implement the code?

                     

                    Sergio

                    • 7. Re: How to redirect stdin/stdout to Serial
                      Jacen

                      Hi Intel_Alvarado

                      I still have no clue on this portion.

                      I can using Serial like Arduino did  under Eclipse. But i don't know how to redirect it.

                       

                      Thanls

                      • 8. Re: How to redirect stdin/stdout to Serial
                        KurtE

                        What have you tried?  I have code that opens up different devices like serial ports for reading and writing.  You can look at the code for exec or the like that uses dup2.  So have you tried opening up the desired port and then dup2 it's handle into the appropriate file handle?  Did it work?

                        • 9. Re: How to redirect stdin/stdout to Serial
                          Jacen

                          Hi KurtE,

                          where i can get that code?

                          could you give me a link or send email to me ?

                           

                          Thanks in advanced

                           

                          Jacen

                          • 10. Re: How to redirect stdin/stdout to Serial
                            KurtE

                            I should again mention, I don't have a complete solution for you.  I have only done bits and pieces.  Also should mention, my network is currently in a messed up state (can reach here, but not teensy forum, robotshop forum, github, ...)  Hopefully they will fix whatever their problem is soon.

                             

                            A lot of my more recent Edison stuff is up on Github at: KurtE/Edison_Eclipse · GitHub

                            As the name implies it is setup for Eclipse.  The version up there was for the previous version of Eclipse, but for the most part, I have not pushed up any of the eclipse internal like files, so probably not a big issue.

                             

                            Pieces I have:

                             

                            I have an TFT display program (Which the last released image SPI issues busted, I think I have it working again with my updated kernel...).

                            If you look into the Edison workspace (stuff up on github) in the project EdisonConsole in the fille (src/screens/tft_run_screen.cpp), toward the end of the file, I have function popen2, which sets up pipes and then launches a program (My usage is to launch my Hexapod Robot code), where the STDIN/STDOUT of the program launched are setup to use the pipes.  The other end of the pipes are used by the display program, such that anytime the app on the other side, writes something out, it is displayed on the TFT display.  It is also setup (currently just a little), that I can input commands from the display and those commands are sent over the pipe to the Hexapod program who see's them on stdin...

                             

                            I have code that reads/writes to Serial (Terminal devices), that I use. Example I have code for Hexapod to use read in from an XBee.  I have it in a few different places, (Example a version to map the Trossen Robotics Arbotix Commander).  I normally have my setup, such that I assume /dev/ttyXBee points to which ever device On most systems, I have udev rules to map the actual device to this name.  So far I have not found a rule that works for the Edison hardware serial port, so I have a hard coded create of a symbolic link in my .profile file... The commander code is in the project ArduinoSupport, with the files src/CommanderEx.cpp as well as CommanderEx.h

                             

                            A more generic version is in same place, but is called wrapperSerial.cpp (.h) - where you pass in a device name and it creates a wrapper class that configures the device for terminal usage as well as is setup to match the Arduino serial class...

                             

                            What I don't have is anything that ties these two parts into one...

                            • 11. Re: How to redirect stdin/stdout to Serial
                              Jacen

                              Hi KurtE

                              OK, i will take  a look  your popen2. see if i could merge to wrapperSerial,

                              also If you make any progress ,please let met know.


                              Thanks very much

                              Jacen