//-------------------------------------------------------------------------- // Read an array of bytes to the COM port, verify that it was // sent out. Assume that baud rate has been set. // // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to // OpenCOM to indicate the port number. // 'inlen' - number of bytes to read from COM port // 'inbuf' - pointer to a buffer to hold the incomming bytes // // Returns: number of characters read // int ReadCOM(int portnum, int inlen, uchar *inbuf) { volatile int i = 0; volatile uchar cnt = 5; volatile uchar quit = FALSE; if(portnum==0) { for(; !quit && i<inlen; cnt=5) { while( !serial0_peek() && (cnt--)>0 ) msDelay(10); if(!serial0_peek()) quit = TRUE; else inbuf[i++] = serial0_getchar(); } } else { for(; !quit && i<inlen; cnt=5) { while( !serial1_peek() && (cnt--)>0 ) msDelay(10); if(!serial1_peek()) quit = TRUE; else inbuf[i++] = serial1_getchar(); } } return i; }
//-------------------------------------------------------------------------- // Read an array of bytes to the COM port, verify that it was // sent out. Assume that baud rate has been set. // // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to // OpenCOM to indicate the port number. // 'inlen' - number of bytes to read from COM port // 'inbuf' - pointer to a buffer to hold the incomming bytes // // Returns: number of characters read // int ReadCOM(int portnum, int inlen, uchar *inbuf) { int i = 0; uchar cnt = 5; //50ms timeout uchar quit = FALSE; switch (port_handle[portnum]) { case DS400_SERIAL0: for(; !quit && i<inlen; cnt=5) { while( !serial0_peek() && (cnt--)>0 ) msDelay(10); if(!serial0_peek()) quit = TRUE; else inbuf[i++] = serial0_getchar(); } break; case DS400_SERIAL1: for(; !quit && i<inlen; cnt=5) { while( !serial1_peek() && (cnt--)>0 ) msDelay(10); if(!serial1_peek()) quit = TRUE; else inbuf[i++] = serial1_getchar(); } break; case DS400_SERIAL2: for(; !quit && i<inlen; cnt=5) { while( !serial2_peek() && (cnt--)>0 ) msDelay(10); if(!serial2_peek()) quit = TRUE; else inbuf[i++] = serial2_getchar(); } break; } return i; }