home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / amiga / programm / 12964 < prev    next >
Encoding:
Internet Message Format  |  1992-09-01  |  3.7 KB

  1. Path: sparky!uunet!utcsri!torn!cunews!revcan!sidus!atronx.OCUnix.On.Ca!delfax!angband!Vic
  2. From: Vic@angband.delfax.OCunix.On.Ca (Vic Lewington)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: SERIAL.DEVICE HEEEEELLLLLPPPPPPP
  5. Distribution: world
  6. Message-ID: <Vic.00yf@angband.delfax.OCunix.On.Ca>
  7. References:  <u895762.715081138@bruny>
  8. Date: 30 Aug 92 11:14:06 AST
  9. Organization: MMI
  10. Lines: 94
  11.  
  12. In article <u895762.715081138@bruny> u895762@bruny.cc.utas.edu.au (Paul S.E.) writes:
  13. >
  14. > Hi.
  15. > I have a problem that has been driving me mad for the past 5 hours.
  16. > I am trying to read data from serial.device, one character at a time. (i.e. in real time), but the 512 byte buffer prevents me from doing it.
  17. > HELP, anybody?!
  18.  
  19.     Having just spent a few hours going nuts myself, here, try this...
  20.     (BTW, done more or less as per the RKM: Devices.)
  21.     Note that this assumes a lot of setup (ie opening the serial.device, and
  22. allocating/initializing the IOExtSer struct, etc) has been done already
  23.  
  24. /*************************** cut here *******************************/
  25.  
  26.     struct IOExtSer *myIO;
  27.     UBYTE rx_char;
  28.     BOOL more = TRUE;
  29.  
  30.     while(more)
  31.     {
  32.         myIO->IOSer.io_Command = SDCMD_QUERY;
  33.         DoIO((struct IORequest *) myIO);
  34.         /* This finds out how much unread data, if any, is in the */
  35.         /* device's buffer */
  36.         if(myIO->IOSer.io_Actual)
  37.         {
  38.             /* Something in the buffer, so read a byte and handle it */
  39.  
  40.             myIO->IOSer.io_Command = CMD_READ;
  41.             myIO->IOSer.io_Length = 1;
  42.             myIO->IOSer.io_Data = (APTR) rx_char;
  43.             if(DoIO((struct IORequest *) myIO))
  44.             {
  45.                 printf("Error during read from %s!\n", SERIALNAME);
  46.                 more = FALSE;
  47.             }
  48.             else
  49.             {
  50.                 /* Got a byte from serial port in rx_char, so handle it! */
  51.             }
  52.         }
  53.         else
  54.         {
  55.             /* Nothing there, so bail out of loop and do something else */
  56.  
  57.             more = FALSE;
  58.         }
  59.     }
  60.  
  61. /*************************** cut here *******************************/
  62.  
  63.     A few points first off, why only one byte at a time?? The above code is from
  64. a prg I wrote and has been mauled to suit your query. A better way would be to
  65. create a buffer, say UBYTE rx_chars[MAXLEN], and a length variable, ULONG len.
  66. With #define MAXLEN to something reasonable (256?), do this:
  67.  
  68.         myIO->IOSer.io_Command = SDCMD_QUERY;
  69.         DoIO((struct IORequest *) myIO);
  70.         if(len = myIO->IOSer.io_Actual)
  71.         {
  72.             len = (len<MAXLEN) ? len : MAXLEN;
  73.             myIO->IOSer.io_Command = CMD_READ;
  74.             myIO->IOSer.io_Length = len;
  75.             myIO->IOSer.io_Data = (APTR) rx_chars;
  76.             if(DoIO((struct IORequest *) myIO))
  77.             {
  78.                 /* Handle error */
  79.             }
  80.             else
  81.             {
  82.                 /* You now have len bytes in rx_chars, so handle 'em */
  83.             }
  84.  
  85.  
  86.     Depending on what you're trying to do, you could also go to asynch IO, with
  87. all that that involves...
  88.  
  89. >Thanx.
  90.     No problem. Hope that a) this helps, and b) I don't get too badly mauled by
  91. the netfolk... ;)
  92.  
  93.  
  94. >
  95. >- u895762@bruny.cc.utas.edu.au
  96.  
  97. --
  98. ---------------------------------------------------------------------------
  99. |Vic Lewington:                         "I pull out the plank and say     |
  100. |(Vic@angband.delfax.ocunix.on.ca)        thank you for yanking me back   |
  101. |                                          to the fact that there's always|
  102. |See, there's this HUGE parrot, and...      something to distract..."     |
  103. |                                                        - Kate Bush      |
  104. ---------------------------------------------------------------------------
  105.  
  106.