home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / perl / 5855 < prev    next >
Encoding:
Internet Message Format  |  1992-09-11  |  1.6 KB

  1. Path: sparky!uunet!spool.mu.edu!sdd.hp.com!elroy.jpl.nasa.gov!ames!sun-barr!west.West.Sun.COM!cronkite.Central.Sun.COM!sixgun.East.Sun.COM!matthew
  2. From: matthew@sunpix.East.Sun.COM (Matthew Stier - Sun NC Development Center)
  3. Newsgroups: comp.lang.perl
  4. Subject: Handling serial ports in perl.
  5. Date: 11 Sep 1992 13:00:00 GMT
  6. Organization: Sun Microsystems, Research Triangle Park, NC
  7. Lines: 48
  8. Distribution: world
  9. Message-ID: <18q58gINN5sg@sixgun.East.Sun.COM>
  10. NNTP-Posting-Host: superdave.east.sun.com
  11. Summary: Anyone have a package to talk to devices?
  12.  
  13.  
  14. I'm trying to make a ipc server to talk to a device hanging off a serial 
  15. port on a Sparcstation 1+.
  16.  
  17. I've been able to emulate 'tip' using the following script, but would to
  18. know if anyone has written a package to talk to devices, or would have an 
  19. idea on how to wrap this into a ipc server. 
  20.  
  21. {What I'm interested in, is to telnet to a host/port, issue commands which
  22.  the server will feed to the device, and that the reply will be returned
  23.  to requestor.}
  24.  
  25.  
  26. #!/usr/bin/perl
  27.  
  28. $tty =  "/dev/ttya";
  29.  
  30. $SIG{'INT'} = 'dokill';
  31. sub dokill {
  32.     kill 9,$child if $child;
  33. }
  34.  
  35. if($child = fork) {
  36.     # Parent
  37.     open(TTY, ">  $tty");
  38.     system("stty raw >  $tty"); # place the tty in the raw mode
  39.     while (<STDIN>) {
  40.         tr/a-z/A-Z/;
  41.         last if /^QUIT/;
  42.         print TTY;
  43.     }
  44.     sleep 1;
  45.     do dokill();
  46. }
  47. else {
  48.     # Child
  49.     open(TTY, "< $tty");
  50.     while(<TTY>) {
  51.         print;
  52.     }
  53. }
  54.  
  55.  
  56. -- 
  57. Matthew Lee Stier                          |
  58. Sun Microsystems ---  RTP, NC  27709-3447  |     "Wisconsin   Escapee"
  59. Email: matthew.stier@East.Sun.COM          |
  60. Phone: (919) 469-8300 fax: (919) 460-8355  | 
  61.