master_write_from_file.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /***************************************************************************
  2. master_write_from_file.c
  3. -------------------
  4. Example program which uses gpib c library. I use this with
  5. slave_read_to_file in order to test read/write speed between two boards.
  6. copyright : (C) 2003 by Frank Mori Hess
  7. email : fmhess@users.sourceforge.net
  8. ***************************************************************************/
  9. /***************************************************************************
  10. * *
  11. * This program is free software; you can redistribute it and/or modify *
  12. * it under the terms of the GNU General Public License as published by *
  13. * the Free Software Foundation; either version 2 of the License, or *
  14. * (at your option) any later version. *
  15. * *
  16. ***************************************************************************/
  17. #include <stdio.h>
  18. #include <sys/time.h>
  19. #include "gpib/ib.h"
  20. int main( int argc, char *argv[] )
  21. {
  22. int dev;
  23. int board_index = 0;
  24. int pad = 1;
  25. int sad = 0;
  26. int send_eoi = 1;
  27. int eos_mode = 0;
  28. char *file_path;
  29. int status;
  30. struct timeval start_time, end_time;
  31. float elapsed_time;
  32. if( argc < 2 )
  33. {
  34. fprintf( stderr, "Must provide file path as arguement\n" );
  35. return -1;
  36. }
  37. file_path = argv[ 1 ];
  38. dev = ibdev( board_index, pad, sad, TNONE, send_eoi, eos_mode );
  39. if( dev < 0 )
  40. {
  41. fprintf( stderr, "ibdev() failed\n" );
  42. fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) );
  43. return -1;
  44. }
  45. printf( "Device online: board index=%i, pad=%i, sad=%i\n"
  46. "\tfile path=%s\n", board_index, pad, sad, file_path );
  47. gettimeofday( &start_time, NULL );
  48. status = ibwrtf( dev, file_path );
  49. if( status & ERR )
  50. {
  51. fprintf( stderr, "ibwrtf() failed\n" );
  52. fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) );
  53. return -1;
  54. }
  55. gettimeofday( &end_time, NULL );
  56. elapsed_time = end_time.tv_sec - start_time.tv_sec +
  57. ( end_time.tv_usec - start_time.tv_usec ) / 1e6;
  58. printf( "Transferred %lu bytes in %g seconds: %g bytes/sec\n",
  59. ThreadIbcntl(), elapsed_time, ThreadIbcntl() / elapsed_time );
  60. return 0;
  61. }