//------------------------------------------------------------------- // recvajay.cpp // // This program is for testing our 'ajfschar.c' device-driver's // 'read()' method when receiving data via the 'NET20DC' cable. // // to compile: $ g++ recvajay.cpp -o recvajay // to execute: $ ./recvajay // // NOTE: Installing our 'ajfschar.c' device-driver is required. // // programmer: ALLAN CRUSE // written on: 30 MAY 2010 //------------------------------------------------------------------- #include // for printf(), perror() #include // for open() #include // for exit() #include // for read() char devname[] = "/dev/ajay"; char rxbuf[ 41000 ]; int main( int argc, char **argv ) { // open the device-file for reading int fd = open( devname, O_RDONLY ); if ( fd < 0 ) { perror( devname ); exit(1); } // read the data received via the NET20DC cable int rxbytes = read( fd, rxbuf, sizeof( rxbuf ) ); if ( rxbytes < 0 ) { perror( "read" ); exit(1); } // display the data received via the NET20DC cable printf( "\n%s\n", rxbuf ); // report the amount of data that our driver has transferred printf( "\n Read %d bytes from \'%s\' \n", rxbytes, devname ); }