echo "Hello World" 2>&1 > /dev/tty<serial name>
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.
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.
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.
Yeah, your are right ,that is the way. But i am not very clear about how to implement code. i am still trying.
Were you able to implement the code?
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?
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...