home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / scripts / ckermit / logserial < prev    next >
Text File  |  2009-12-06  |  4KB  |  88 lines

  1. #!./wermit
  2. #
  3. # logserial
  4. # C-Kermit Script to copy a local shell session out the serial port in real
  5. # time; for example to feed it to a speaking device or serial printer; in this
  6. # case, the RC Systems DoubleTalk LT, which needs each line to be terminated
  7. # by an ASCII NUL character.
  8. # Replace "./wermit" in the first line with the full path of your C-Kermit 9.0
  9. # program and give this script file execute permission with chmod +x.
  10. # C-Kermit 9.0 or later is required, and it must be a version built with
  11. # -DNOUUCP, as the Mac OS X versions are, by default, in this C-Kermit
  12. # release.  SET SESSION-LOG NULL-PADDED is new to C-Kermit 9.0, as is the
  13. # ability to send a log file (session, debug, packets...) to a serial port.
  14. # The device on the other end should be connected with a null modem cable or
  15. # modem eliminator and it should be turned on before this script is executed,
  16. # otherwise the script is likely to hang when it tries to open the serial
  17. # port, because many versions of Unix will not open a serial port unless or
  18. # until certain modem signals such as CD, DSR, and/or CTS are presented.
  19. # Frank da Cruz, Columbia University, October 2009
  20. # Last update: Tue Oct 27 10:59:35 2009
  21.  
  22. if < \v(version) 900299 exit 1 "FATAL - C-Kermit 9.0 required"
  23.  
  24. # Change port parameters as appropriate:
  25.  
  26. .portname = /dev/tty.KeySerial1        # Tested on a Keyspan USB adapter 
  27. .speed = 9600
  28. .flow = rts/cts
  29.  
  30. # Set up the serial port 
  31.  
  32. set carrier-watch off            # Don't require carrier 
  33. set line \m(portname)            # Try to open the serial port
  34. if fail exit 1 "FATAL - \m(portname): \v(setlinemsg)" # Stop here on error
  35. set speed \m(speed)            # Set the required transmission speed 
  36. if fail exit 1 FATAL - "set speed \m(speed)" rejected for \m(portname)
  37. set flow \m(flow)            # Set the appropriate flow control 
  38. if fail exit 1 FATAL - "set flow \m(flow)" unsupported for \m(portname)
  39. output \13                # Send it a Carriage Return 
  40. output \{1}4S                # Set the desired speaking speed 
  41.  
  42. # The two output commands are specific to the DoubleTalk device.  The carriage
  43. # return (\13) activates the speaking function, and "\{1}4S" (Ctrl-A, 4, S) is
  44. # a command to set the speaking rate.  5 is average, use a lower digit to slow
  45. # it down, a higher digit (up to 9) to speed it up.
  46. #
  47. # Since Kermit can't have two terminal connections open at the same time,
  48. # the serial port has to be closed.  We just have to hope the settings stick
  49. # (in Mac OS X they do).
  50.  
  51. close connection            # Close the port
  52.  
  53. # In the following section we open a new connection to a pseudoterminal (pty).
  54. # "set session-log null-padded" is also specific to the DoubleTalk device.
  55.  
  56. set session-log binary            # text might also work
  57. set session-log null-padded             # Put ^@ after every ^J
  58. log session \m(portname)        # Log session to serial port
  59. if fail {
  60.     echo "---------------------------------------------------"
  61.     echo ERROR: SERIAL PORT \m(portname) CAN'T BE OPENED FOR
  62.     echo LOGGING.  EITHER THE DEVICE IS NOT ACCESSIBLE OR IT
  63.     echo IS IN USE BY ANOTHER PROCESS.
  64.     echo "---------------------------------------------------"
  65.     exit 1
  66. }
  67. set host /pty \$(SHELL)            # Start new shell in a pseudoterminal 
  68. if fail exit 1 "FATAL - Can't spawn a new shell"
  69.  
  70. echo "---------------------------------------------------"
  71. echo STARTING NEW SHELL SESSION LOGGING TO \m(portname)...
  72. echo GIVE AN 'exit' COMMAND TO THE SHELL TO STOP LOGGING.
  73. echo "---------------------------------------------------"
  74.  
  75. connect
  76.  
  77. echo "---------------------------------------------------"
  78. echo SESSION TERMINATED, LOGGING STOPPED.
  79. echo "---------------------------------------------------"
  80. close session
  81. exit 0
  82.