ibdev.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /***************************************************************************
  2. ibdev.c
  3. -------------------
  4. begin : Tues Feb 12 2002
  5. copyright : (C) 2002 by Frank Mori Hess
  6. email : fmhess@users.sourceforge.net
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************/
  16. #include "ib_internal.h"
  17. #include <stdlib.h>
  18. #if 0
  19. static int is_device_addr( int minor, int pad, int sad )
  20. {
  21. ibBoard_t *board;
  22. unsigned int board_pad;
  23. int board_sad;
  24. board = &ibBoard[ minor ];
  25. if( query_pad( board, &board_pad ) < 0 )
  26. {
  27. fprintf( stderr, "failed to query pad\n" );
  28. return -1;
  29. }
  30. if( query_sad( board, &board_sad ) < 0 )
  31. {
  32. fprintf( stderr, "failed to query sad\n" );
  33. return -1;
  34. }
  35. if( gpib_address_equal( board_pad, board_sad, pad, sad ) == 0 )
  36. {
  37. return 1;
  38. }
  39. return 0;
  40. }
  41. #endif
  42. int ibdev( int minor, int pad, int sad, int timo, int eot, int eosmode )
  43. {
  44. int retval;
  45. ibConf_t new_conf;
  46. retval = ibParseConfigFile();
  47. if(retval < 0)
  48. {
  49. setIbsta( ERR );
  50. return -1;
  51. }
  52. sad -= sad_offset;
  53. init_ibconf( &new_conf );
  54. new_conf.settings.pad = pad;
  55. new_conf.settings.sad = sad; /* device address */
  56. new_conf.settings.board = minor; /* board number */
  57. new_conf.settings.eos = eosmode & 0xff; /* local eos modes */
  58. new_conf.settings.eos_flags = eosmode & 0xff00;
  59. new_conf.settings.usec_timeout = timeout_to_usec( timo );
  60. if( eot )
  61. new_conf.settings.send_eoi = 1;
  62. else
  63. new_conf.settings.send_eoi = 0;
  64. new_conf.defaults = new_conf.settings;
  65. new_conf.is_interface = 0;
  66. return my_ibdev( new_conf );
  67. // XXX check for address conflicts with boards
  68. }
  69. int my_ibdev( ibConf_t new_conf )
  70. {
  71. int ud;
  72. ibConf_t *conf;
  73. ud = ibGetDescriptor(new_conf);
  74. if( ud < 0 )
  75. {
  76. fprintf( stderr, "libgpib: ibdev failed to get descriptor\n" );
  77. setIbsta( ERR );
  78. return -1;
  79. }
  80. conf = enter_library( ud );
  81. if( conf == NULL )
  82. {
  83. exit_library( ud, 1 );
  84. return -1;
  85. }
  86. // XXX do local lockout if appropriate
  87. exit_library( ud, 0 );
  88. return ud;
  89. }