/* Copyright (C) Magna Carta Software, Inc. 1990. All Rights Reserved. CCTDIGI1.C: Example 2 for using C COMMUNICATIONS TOOLKIT with the DigiBoard DigiCHANNEL COM/Xi family of products (i.e. the COM/4i & COM/8i). Last updated: 08-31-90 Usage: This program sends data out of one DigiBoard port and receives on another. It is set up to send from port 0 and receive on port 1. */ #include #include #include #include #define MENU ALT_M /* key for command summary */ /* FUNCTION PROTOTYPES */ void term(COMM_PORT *p1, COMM_PORT *p2); /* the main program loop */ short menu(void); /* the function that handles the menu */ /* GLOBAL VARIABLES */ short vers = 0; /* the version number of "CCT-DIGI" */ /* Treat each DigiBoard port as a COMM_PORT structure. For the Com/4i, abbreviate the next two lines after 4 ports */ COMM_PORT d0, d1, d2, d3, d4, d5, d6, d7; COMM_PORT *digi[] = {&d0, &d1, &d2, &d3, &d4, &d5, &d6, &d7, NULL}; void main(void) { short ret; /* INITIALIZE DIGIBOARD Parameters are: 1) Address of an array of COMM_PORT structures (NULL terminated); 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: xi_init() does the following... a) Calls resetxi() to reset board; b) Calls excM232() to run DigiBoard-supplied program on board; c) Initializes the COMM_PORT structures passed via the first parameter; d) Initializes the board data format to 2400 N81 as we must have it in a known state; 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. */ ret = xi_init(digi, 0X320, 0XD800, 0); printf("\nResult of xi_init() is: %d", ret); /* Should be 0 */ /* THE NEXT SIX LINES SET SPEED, DATA FORMAT, RS-232 SIGNALS FOR PORT 1 */ set_speed(digi[0], 19200L); set_databits(digi[0], 8); set_stopbits(digi[0], 1); set_parity(digi[0], PARITY_NONE); set_rts(digi[0], HIGH); set_dtr(digi[0], HIGH); /* THE NEXT SIX LINES SET SPEED, DATA FORMAT, RS-232 SIGNALS FOR PORT 2 */ set_speed(digi[1], 19200L); set_databits(digi[1], 8); set_stopbits(digi[1], 1); set_parity(digi[1], PARITY_NONE); set_rts(digi[1], HIGH); set_dtr(digi[1], HIGH); /* THE TERMINAL PROGRAM STARTS HERE */ printf("\nCCT-DIGI Version %d: Press Alt-M for a list of commands\n", vers); term(digi[0], digi[1]); printf("\nEnd of CCT-COMM%d\n", vers); set_rts(digi[0], LOW); set_dtr(digi[0], LOW); } /* TERM -- The terminal emulation routine. Simply polls the COM port and the keyboard alternately for characters. */ void term(COMM_PORT *p1, COMM_PORT *p2) { short c; /* must be int to detect a -1 return */ for (;;) { while ((c = c_waitc(p2, EOF, 100)) != EOF) printf("%c", c); /* CHECK KEYBOARD FOR A KEY PRESS */ if ( (c = inkey()) != EOF) { if (c == MENU) { if (menu()) break; } else c_putc(p1, c); } else c_puts(p1, "\nMary had a little C compiler"); } } #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 */ }