/*
	z1232.c
	
   This program demonstrates the use of Z180 serial port 1 configured
	for either a 3 wire RS232 communication or 4 wire full duplex RS485 
	communication.
*/

#use "default.h"

#if ((BOARD_TYPE==CPLC_BOARD) || (BOARD_TYPE==L_STAR))
#use cplc.lib
#endif

/**********************************************
CONTROL PARAMETERS
***********************************************/
#define IBAUD   9600         /*baud rate
                                with modem either 2400 or 1200
                                without modem => 19200,9600, 4800, etc   */
#define TBUFSIZE 384         // size of transmit buffer
#define RBUFSIZE 384         // size of receive buffer

char ismodem = 0;            // set to 1 if you want modem
char isecho = 1;             // set to 1 if you want character echoed back to the pc

main()
{
    int ercode;
    int i;
    int count;
    char tbuf[TBUFSIZE];     // transmit buffer
    char rbuf[RBUFSIZE];     // receive buffer
    char buf[20];         // dummy buffer for receiving a complete command

#if ((BOARD_TYPE==CPLC_BOARD) || (BOARD_TYPE==L_STAR))
        uplc_init();
#endif

    Dinit_z1(rbuf, tbuf, RBUFSIZE, TBUFSIZE, 4, IBAUD / 1200, ismodem, isecho);

    if (! ismodem)           // if no modem, you have to service your own screen
    {                        // at power up
        Dz1send_prompt();
    }

    for (;;)    // endless loop constantly monitoring for new command line
    {
    	  hitwd();
        if( Dread_z1(buf, ENTER) != 0)
        {
            Dz1send_prompt();
            Dwrite_z1("i got the message", 17);
            Dz1send_prompt();
        }
    }
}
