If you want to connect to a device and initiate automated two way conversations then you could see if expect will get you what you want. Put an entry in your inittab(5) file to run it on the appropriate serial port on a respawn basis. You can configure the system to allow logins from a terminal over a serial port by seting up a getty(1) session on the serial port - getty is the tool for setting up a terminal and allowing logins onto it. If you want bidirectional communication then I presume you want something interactive with a human on the terminal. Do you want to run a shell or applicaiton interactively from the terminal, connect out to another computer over the serial line, automate communication with a device over a serial port? # Capture PID of background process so it is possible to terminate itĬat >"$port" # Redirect all keyboard input to serial port # Let cat read the serial port to the screen in the background Stty raw -echo isig intr ^Q quit undef susp undefĮcho "Connecting to $port. # * "isig intr ^Q" will make Ctrl+Q send SIGINT to this script # * "quit undef susp undef" will disable Ctrl+\ and Ctrl+Z handling Stty -F "$port" raw -echo Set current terminal to pass through everything except Ctrl+Q # Set up serial port, append all remaining parameters from command line # Remove serial port from parameter list, so only stty settings remain Trap 'set +e kill "$bgPid" stty "$original_settings"' EXIT # Kill background process and restore terminal when this shell exits # Save settings of current terminal to restore later Just put the following code into a file /usr/local/bin/femtocom (or any other place in $PATH) and do chmod +x /usr/local/bin/femtocom.įrom there on you can connect to any serial port like this for example: femtocom /dev/ttyUSB0 57600 This enables you to use Ctrl+C or Ctrl+Z on the remote host, and to use interactive "GUI" programs like aptitude or alsamixer. This script is based on another answer, but sends everything over the serial port (except Ctrl+Q), not just single commands followed by Enter. You can also use a tool like setserial to set up the port and then interact with it directly from the shell. The most basic program that I know that does this is picocom. Minimal serial communicationīasically, two things are needed to have two-way communication through a serial port: 1) configuring the serial port, and 2) opening the pseudo-tty read-write. Run stty again after using minicom, and you'll notice the settings are set to what the program was using. In this situation, sending the commands cat or echo to the port will either produce garbage or not work at all. These are probably different than what you will need to make your connection. If you have done it right after booting the computer and before running any other program like minicom, the communication settings will be at their default settings. You can query the communication settings using the stty program like this: stty < /dev/ttyS0 Notice that once you run a program like minicom, the port is left with the settings that minicom used. If it weren't set up appropriately, the cat and echo commands would not do for you what you might have expected. The main reason why you need any program like minicom to communicate over a serial port is that the port needs to be set up prior to initiating a connection.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |