ibbna.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /***************************************************************************
  2. lib/ibbna.c
  3. -------------------
  4. copyright : (C) 2002 by Frank Mori Hess
  5. email : fmhess@users.sourceforge.net
  6. ***************************************************************************/
  7. /***************************************************************************
  8. * *
  9. * This program is free software; you can redistribute it and/or modify *
  10. * it under the terms of the GNU General Public License as published by *
  11. * the Free Software Foundation; either version 2 of the License, or *
  12. * (at your option) any later version. *
  13. * *
  14. ***************************************************************************/
  15. #include "ib_internal.h"
  16. int my_ibbna( ibConf_t *conf, unsigned int new_board_index )
  17. {
  18. ibBoard_t *board;
  19. ibConf_t *board_conf;
  20. int retval;
  21. int old_board_index;
  22. board = interfaceBoard( conf );
  23. if( conf->is_interface )
  24. {
  25. setIberr( EARG );
  26. return -1;
  27. }
  28. retval = close_gpib_handle( conf );
  29. if( retval < 0 )
  30. {
  31. setIberr( EDVR );
  32. return -1;
  33. }
  34. board_conf = &ibFindConfigs[ new_board_index ];
  35. if( board_conf->is_interface == 0 )
  36. {
  37. setIberr( EARG );
  38. return -1;
  39. }
  40. if( is_cic( interfaceBoard( board_conf ) ) == 0 )
  41. {
  42. setIberr( ECIC );
  43. return -1;
  44. }
  45. old_board_index = conf->settings.board;
  46. conf->settings.board = board_conf->settings.board;
  47. if( ibBoardOpen( interfaceBoard( conf ) ) < 0 )
  48. {
  49. setIberr( EDVR );
  50. return -1;
  51. }
  52. retval = open_gpib_handle( conf );
  53. if( retval < 0 )
  54. {
  55. setIberr( EDVR );
  56. return -1;
  57. }
  58. setIberr( old_board_index );
  59. return 0;
  60. }
  61. int ibbna( int ud, char *board_name )
  62. {
  63. ibConf_t *conf;
  64. int retval;
  65. int find_index;
  66. conf = enter_library( ud );
  67. if( conf == NULL )
  68. return exit_library( ud, 1 );
  69. if( ( find_index = ibFindDevIndex( board_name ) ) < 0 )
  70. {
  71. setIberr( EARG );
  72. return exit_library( ud, 1 );
  73. }
  74. retval = my_ibbna( conf, find_index );
  75. if( retval < 0 )
  76. return exit_library( ud, 1 );
  77. return exit_library( ud, 0 );
  78. }