From: Vic@angband.delfax.OCunix.On.Ca (Vic Lewington)
Newsgroups: comp.sys.amiga.programmer
Subject: Re: SERIAL.DEVICE HEEEEELLLLLPPPPPPP
Distribution: world
Date: 30 Aug 92 11:14:06 AST
Organization: MMI

In article <u895762.715081138@bruny> u895762@bruny.cc.utas.edu.au (Paul S.E.) writes:
>
> Hi.
> I have a problem that has been driving me mad for the past 5 hours.
> 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.
> HELP, anybody?!

    Having just spent a few hours going nuts myself, here, try this...
    (BTW, done more or less as per the RKM: Devices.)
    Note that this assumes a lot of setup (ie opening the serial.device, and
allocating/initializing the IOExtSer struct, etc) has been done already

/*************************** cut here *******************************/

    struct IOExtSer *myIO;
    UBYTE rx_char;
    BOOL more = TRUE;

    while(more)
    {
        myIO->IOSer.io_Command = SDCMD_QUERY;
        DoIO((struct IORequest *) myIO);
        /* This finds out how much unread data, if any, is in the */
        /* device's buffer */
        if(myIO->IOSer.io_Actual)
        {
            /* Something in the buffer, so read a byte and handle it */

            myIO->IOSer.io_Command = CMD_READ;
            myIO->IOSer.io_Length = 1;
            myIO->IOSer.io_Data = (APTR) rx_char;
            if(DoIO((struct IORequest *) myIO))
            {
                printf("Error during read from %s!\n", SERIALNAME);
                more = FALSE;
            }
            else
            {
                /* Got a byte from serial port in rx_char, so handle it! */
            }
        }
        else
        {
            /* Nothing there, so bail out of loop and do something else */

            more = FALSE;
        }
    }

/*************************** cut here *******************************/

    A few points first off, why only one byte at a time?? The above code is from
a prg I wrote and has been mauled to suit your query. A better way would be to
create a buffer, say UBYTE rx_chars[MAXLEN], and a length variable, ULONG len.
With #define MAXLEN to something reasonable (256?), do this:

        myIO->IOSer.io_Command = SDCMD_QUERY;
        DoIO((struct IORequest *) myIO);
        if(len = myIO->IOSer.io_Actual)
        {
            len = (len<MAXLEN) ? len : MAXLEN;
            myIO->IOSer.io_Command = CMD_READ;
            myIO->IOSer.io_Length = len;
            myIO->IOSer.io_Data = (APTR) rx_chars;
            if(DoIO((struct IORequest *) myIO))
            {
                /* Handle error */
            }
            else
            {
                /* You now have len bytes in rx_chars, so handle 'em */
            }


    Depending on what you're trying to do, you could also go to asynch IO, with
all that that involves...

>Thanx.
    No problem. Hope that a) this helps, and b) I don't get too badly mauled by
the netfolk... ;)


>
>- u895762@bruny.cc.utas.edu.au

--
---------------------------------------------------------------------------
|Vic Lewington:                         "I pull out the plank and say     |
|(Vic@angband.delfax.ocunix.on.ca)        thank you for yanking me back   |
|                                          to the fact that there's always|
|See, there's this HUGE parrot, and...      something to distract..."     |
|                                                        - Kate Bush      |
---------------------------------------------------------------------------