/******************************************************************

      SIODEMO1.C

      BL11xx/Little Giant
      
   Demo of serial driver for SIO channel B of the KIO. 
   
   Connect J9 3-5, 2-4, RS-485 RX / TX, -RX / -TX.

   This will loop the serial port back on itself so that the signal
   that is sent is received on the same port.  Z-World serial drivers
   are interrupt driven and continue to run while the program executes.

*****************************************************************/

#use "serial.lib"

char buf[]="This message sent over serial line!";
char cc;       /* down counter for transmitter */

char rbuf[50]; /* receive buffer */
char rcc;      /* receiver down counter */

main()
{
   int  tt;                    /* time out counter */

   setdaisy (1);               /* set KIO interrupt priorities, SIO 1st */
   ser_init_s1 (4,9600/1200);  /* setup serial port */
   cc = sizeof (buf);          /* number of character to send */
   rcc = cc;                   /* receive the same number of characters */
   rbuf[0] = 0;                /* in case print null string */

   ser_rec_s1 (rbuf,&rcc);      /* get ready to receive characters */

   /* enable RS-485 transmitter, not needed for receiver */
   outport (ENB485,1);          
   ser_send_s1 (buf,&cc) ;      /* OK now we can send the string */

   EI();                       /* make sure that interrupts are enabled */
   tt=0;                       /* time out counter */
   while (rcc && --tt) hitwd();/* wait for receive count = 0 or time out */

   if (!tt) 
      printf("Timed out - port not loop connected?\n");
  
   printf ("%s\n",rbuf);
}

/***********************************************End of SIODEMO1.C *****/

