1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
/***************************************************************************
lib/ibOnl.c
-------------------
copyright : (C) 2001,2002,2003 by Frank Mori Hess
email : fmhess@users.sourceforge.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "ib_internal.h"
#include <stdlib.h>
int board_online(ibBoard_t *board, int online, ibConf_t *conf)
{
if (online) {
if (ibBoardOpen(board, conf->error_msg_disable) < 0)
return -1;
} else {
ibBoardClose(board);
}
return 0;
}
int conf_online(ibConf_t *conf, int online)
{
ibBoard_t *board;
int retval;
if ((online && conf->board_is_open) ||
(online == 0 && conf->board_is_open == 0))
return 0;
board = interfaceBoard(conf);
retval = board_online(board, online, conf);
if (retval < 0)
return retval;
if (online)
retval = open_gpib_handle(conf);
else
retval = close_gpib_handle(conf);
if (retval < 0)
return retval;
conf->board_is_open = online != 0;
return 0;
}
int reinit_descriptor(ibConf_t *conf)
{
int msad;
int retval;
retval = internal_ibpad(conf, conf->defaults.pad);
if (retval < 0)
return retval;
msad = conf->defaults.sad;
if (msad < 0)
msad = 0;
else
msad = MSA(msad);
retval = internal_ibsad(conf, msad);
if (retval < 0)
return retval;
if (conf->is_interface == 0) { /* ibbna is device only */
retval = my_ibbna(conf, conf->defaults.board);
if (retval < 0) return retval;
}
conf->settings.usec_timeout = conf->defaults.usec_timeout;
conf->settings.spoll_usec_timeout = conf->defaults.usec_timeout;
conf->settings.ppoll_usec_timeout = conf->defaults.usec_timeout;
conf->settings.eos = conf->defaults.eos;
conf->settings.eos_flags = conf->defaults.eos_flags;
conf->settings.ppoll_config = conf->defaults.ppoll_config;
internal_ibeot(conf, conf->defaults.send_eoi);
conf->settings.local_lockout = conf->defaults.local_lockout;
conf->settings.readdr = conf->defaults.readdr;
return 0;
}
int ibonl(int ud, int onl)
{
ibConf_t *conf;
int retval;
int status;
conf = general_enter_library(ud, 1, 1);
if (conf == NULL)
return general_exit_library(ud, 1, 0, 0, 0, 0, 1);
retval = internal_ibstop(conf);
if (retval < 0)
return general_exit_library(ud, 1, 0, 0, 0, 0, 1);
retval = conf_lock_board(conf);
if (retval < 0)
return general_exit_library(ud, 1, 0, 0, 0, 0, 1);
if (onl) {
retval = reinit_descriptor(conf);
if (retval < 0)
return exit_library(ud, 1);
else
return exit_library(ud, 0);
}
status = general_exit_library(ud, 0, 0, 0, 0, CMPL, 1);
if (onl == 0)
retval = close_gpib_handle(conf);
else
retval = 0;
conf_unlock_board(conf);
if (retval < 0) {
fprintf(stderr, "libgpib: failed to mark device as closed!\n");
status |= ERR;
setIbsta(status);
sync_globals();
return status;
}
release_descriptor(ud);
return status;
}
|