/* Copyright (C) Magna Carta Software, Inc. 1990. All Rights Reserved. CCTDIGI0.C: First example for using C COMMUNICATIONS TOOLKIT with the DigiBoard DigiCHANNEL COM/Xi family of products. (At the present time, this consists of the COM/4i & COM/8i). Last updated: 10-21-91. Functionality: Same as CCT01.C. Usage: Connect a (null)modem to P1 of the DigiBoard Octacable and connect to a remote system. Only one port on the DigiBoard is used. You can choose which one it is. USAGE NOTE: Our "religion" underlying the support of all multi-port boards is that, once initialization is complete, you should be able to interact with the board through standard CCT calls. Various board designs permit this to varying degrees. Note that the DigiBoard DigiCHANNEL COM/Xi requires one call to initialize the board, one call to initialize each port on the board, and from that point on can be programmed with CCT as though it were 8 standard serial ports. */ #include #include #include #include #define MENU ALT_M /* key for command summary */ /* FUNCTION PROTOTYPES */ void term(COMM_PORT *p); /* the main program loop */ short menu(void); /* the function that handles the menu */ /* GLOBAL VARIABLES */ short vers = 0; /* the version number of "CCT-DIGI" */ /* The COMXI structure, maintains information about a single board. */ COMXI comxi; /* Treat each port on a DigiBoard as a COMM_PORT structure. */ COMM_PORT port[8]; /* use array index '4' for COM/4i */ int main(void) { short ret; /* INITIALIZE DIGIBOARD Parameters are: 1) Address of COMXI structure. 2) The port address for I/O between board and host (a.k.a. "mailbox"); 3) The memory segment of the board in the host address space; 4) Length of program (we are using M232, so this is zero) NOTE: comxi_init() does the following... a) Calls resetxi() to reset board; b) Calls excM232() to run DigiBoard-supplied program on board; */ ret = comxi_init(&comxi, 0X320, 0XD000, 0); printf("\nResult of comxi_init() is: %d", ret); /* Should be 0 */ if (ret) return (ret); /* Initialize the channels (ports on the board) that we desire to use In this case we use just one. We use port 0, but you can choose any other by changing the third parameter to the desired port number (0-x) */ ret = comxi_init_channel(&port[0], &comxi, 0, 38400L, 8, PARITY_NONE, 1); printf("\nResult of comxi_init_channel() is: %d", ret); /* Should be 0 */ if (ret) return (ret); /* THESE TWO LINES ARE NON-ESSENTIAL */ set_dtr(&port[0], HIGH); set_rts(&port[0], LOW); set_rx_xlat(&port[0], RX_BUFFER_LWM, 15*1024); set_tx_xlat(&port[0], FLOWCTL, XONXOFF); set_rx_xlat(&port[0], LOCAL_ECHO, ON); /* THE TERMINAL PROGRAM STARTS HERE */ printf("\nCCT-DIGI Version %d: Press Alt-M for a list of commands\n", vers); term(&port[0]); printf("\nEnd of CCT-COMM%d\n", vers); set_rts(&port[0], LOW); set_dtr(&port[0], LOW); return (0); } /* TERM -- The terminal emulation routine. Simply polls the COM port and the keyboard alternately for characters. */ void term(COMM_PORT *p) { short c; /* must be int to detect a -1 return */ for (;;) { /* CHECK SERIAL PORT FOR BYTE */ c = c_getc(p); /* CHECK KEYBOARD FOR A KEY PRESS */ if ( (c = inkey()) != EOF) { if (c == MENU) { if (menu()) break; } else c_putc(p, c); } } } #define EXIT 'Q' /* key to exit from menu */ short menu(void) { int c, retval = 0; static char *menus[] = { "\tQ. EXIT from TERM.", NULL /* null string terminates list */ }; char **menup; c = !EXIT; while (c != EXIT) { puts("\n\n"); for (menup = menus; *menup != NULL; menup++) printf("%s\n", *menup); printf("\n\t\t Enter selection (CR to quit menu) : "); if ( (c = getch()) == CR) break; /* return to term */ c = toupper(c); switch (c) { case EXIT: retval = 1; break; default: puts("Invalid choice\n\007"); break; } } puts("\nExiting menu"); return (retval); /* will be zero except if EXIT */ }