# hp_gpib.mac macros for using gpib and serial port # # hp 19.07.2000 # hp 24.07.2000 support of serial connections added # # # # known problems: # # These macros were only tested and working at 6ID-B and have not been used at # 6ID-D. In the moment because of problems with EPICS the generic GPIB record # is not working at 6ID-D. # # With some commands of the Lakeshore 340 temperature controller error messages # in the MEDM window of the generic serial or GPIB record are observed. The reason # is not completely clear, but it is not a problem of the macros in the file # hp_lakeshore340.mac, because these macros are working if used for example with # hp_gpib_11id.mac at BESSRC. It seems like it is a communication problem between the # Lakeshore 340 controller and EPICS. Unfortunately not all comands given to the # Lakeshore 340 controller at mu-CAT are therefore working as expected. # # # # # global definitions # global GPIB_val,GPIB_field global GPIB_name[],GPIB_command[],GPIB_com_n[],GPIB_sleep,GPIB_debug global GPIB_defs[],GPIB_defs_init[],GPIB_sleep[],GPIB_eol_character[] # global SERIAL_name_format,GPIB_SERIAL,SERIAL_defs[] # # # debug level between 0 and 10 determines the amount of messages shown during execution # GPIB_debug = 0 # # # EPICS Names for the generic GPIB and serial records. In the generic serial record %u # is replaced by the record addressed during execution of the macros, %u must be in the name! # GPIB_name[0] = "6idb1:gpib1." SERIAL_name_format = "6idb1:seriala[%u]." # # # example values: These are device dependent. These variables should be defined in # the specific macros for these devices, for example hp_lakeshore340.mac # # GPIB_sleep[0][15] = 0.25 # time your device needs after put and get # GPIB_eol_character[15] = 13 # end of line character your device expects after put # # # # Definitions of GPIB parameters: # Here the names of all EPICS variables belonging to the generic GPIB record are defined. # To make it possible that several GPIB devices share the same generic GPIB record it is necessary # to keep track of the different configurations those devices need. As a minimum the address # of the device has to be stored in memory. Therefore GPIB_defs_init[0][3] = 2 always has to have # a value assigned larger then 1. Normally it should not be necessary to store other values. Whenever # a GPIB command is issued which addresses an device with a different device address than the GPIB # command used before all variables with values larger than one will be read and stored and afterwords # replaced by the values stored for the new device. # # the sequence of the first 4 GPIB_command[0] variables is important and # should not be changed! GPIB_com_n[0] = 15 GPIB_command[0][0] = "PROC" # process button GPIB_command[0][1] = "AOUT" # output line GPIB_command[0][2] = "AINP" # input line GPIB_command[0][3] = "ADDR" # gpib address GPIB_command[0][4] = "TMOD" GPIB_command[0][5] = "OFMT" GPIB_command[0][6] = "IFMT" GPIB_command[0][7] = "EOS" GPIB_command[0][8] = "NRRD" GPIB_command[0][9] = "NORD" GPIB_command[0][10] = "TMOT" GPIB_command[0][11] = "SEVR" GPIB_command[0][12] = "SPR" GPIB_command[0][13] = "UCMD" GPIB_command[0][14] = "ACMD" # set GPIB_defs_init to a value greater than one if they have to be initialized GPIB_defs_init[0][0] = 0 GPIB_defs_init[0][1] = 0 GPIB_defs_init[0][2] = 0 GPIB_defs_init[0][3] = 2 GPIB_defs_init[0][4] = 0 GPIB_defs_init[0][5] = 0 GPIB_defs_init[0][6] = 0 GPIB_defs_init[0][7] = 0 GPIB_defs_init[0][8] = 0 GPIB_defs_init[0][9] = 0 GPIB_defs_init[0][10] = 0 GPIB_defs_init[0][11] = 0 GPIB_defs_init[0][12] = 0 GPIB_defs_init[0][13] = 0 GPIB_defs_init[0][14] = 0 # # # # Definition of SERIAL parameters: # Same rules as for GPIB devices apply but normally it is not necessary to store any # device information because each serial device has it's own generic serial record. # Nevertheless this function is implemented and can be used if necessary. # # the sequence of the first 3 GPIB_command[1] variables is important and # should not be changed! GPIB_com_n[1] = 18 GPIB_command[1][0] = "PROC" # process button GPIB_command[1][1] = "AOUT" # output line GPIB_command[1][2] = "AINP" # input line GPIB_command[1][3] = "TMOD" GPIB_command[1][4] = "SCAN" GPIB_command[1][5] = "OFMT" GPIB_command[1][6] = "ODEL" GPIB_command[1][7] = "IFMT" GPIB_command[1][8] = "IDEL" GPIB_command[1][9] = "NRRD" GPIB_command[1][10] = "NORD" GPIB_command[1][11] = "TMOT" GPIB_command[1][12] = "SEVR" GPIB_command[1][13] = "BAUD" GPIB_command[1][14] = "DBIT" GPIB_command[1][15] = "SBIT" GPIB_command[1][16] = "PRTY" GPIB_command[1][17] = "FCLT" # set GPIB_defs_init to a value greater than one if they have to be initialized GPIB_defs_init[1][0] = 0 GPIB_defs_init[1][1] = 0 GPIB_defs_init[1][2] = 0 GPIB_defs_init[1][3] = 0 GPIB_defs_init[1][4] = 0 GPIB_defs_init[1][5] = 0 GPIB_defs_init[1][6] = 0 GPIB_defs_init[1][7] = 0 GPIB_defs_init[1][8] = 0 GPIB_defs_init[1][9] = 0 GPIB_defs_init[1][10] = 0 GPIB_defs_init[1][11] = 0 GPIB_defs_init[1][12] = 0 GPIB_defs_init[1][13] = 0 GPIB_defs_init[1][14] = 0 GPIB_defs_init[1][15] = 0 GPIB_defs_init[1][16] = 0 GPIB_defs_init[1][17] = 0 # # # # ################################################################################# # # hp_gpib_read_configuration # hp 19.07.2000 # # read the configuration for a specific gpib device # ################################################################################# # def hp_gpib_read_configuration ' { local i,_act_addr if (GPIB_debug > 10) printf("This is macro hp_gpib_read_configuration ...\n") if (GPIB_SERIAL == 0) { _hp_gpib_get 3 _act_addr = GPIB_val if (GPIB_debug>0) printf("reading actual gpib parameters for address %u:\n",_act_addr) for(i=0;i0) { _hp_gpib_get i GPIB_defs[_act_addr][i] = GPIB_val if (GPIB_debug > 0) printf("%s = %s\n",GPIB_field,GPIB_defs[_act_addr][i]) } } } else { if (GPIB_debug>0) printf("reading actual serial parameters for %s:\n",GPIB_name[GPIB_SERIAL]) if ($# != 1) { eprint "hp_gpib_read_configuration: Parameter giving serial port number necessary!" exit } _act_addr = $1 for(i=0;i0) { _hp_gpib_get i SERIAL_defs[_act_addr][i] = GPIB_val if (GPIB_debug > 0) printf("%s = %s\n",GPIB_field,SERIAL_defs[_act_addr][i]) } } } } ' # # # # ################################################################################# # # _hp_gpib_init # hp 19.07.2000 # # # ################################################################################# # def _hp_gpib_init ' { local i,_a if (GPIB_debug > 10) printf("This is macro _hp_gpib_init ...\n") if ($# != 1) { eprint "wrong number of arguments in _hp_gpib_init" exit } _a = $1 if (GPIB_SERIAL == 0) { if (_a == GPIB_defs[_a][3]) { for(i=0;i1) { _hp_gpib_put i GPIB_defs[_a][i] if (GPIB_debug > 0) printf("%s writing %s\n",GPIB_field,GPIB_defs[_a][i]) } } } else { _hp_gpib_put 3 _a if (GPIB_debug > 0) printf("%s writing %s\n",GPIB_field,_a) hp_gpib_read_configuration } } else { for(i=0;i1) { _hp_gpib_put i SERIAL_defs[_a][i] if (GPIB_debug > 0) printf("%s writing %s\n",GPIB_field,SERIAL_defs[_a][i]) } } } } ' # # # # ################################################################################# # # hp_gpib_put # hp 19.07.2000 # # # ################################################################################# # def hp_gpib_put ' { local _hp_addr,_hp_uuu,_hp_vvv,_hp_addr_sign if (GPIB_debug > 10) printf("This is macro hp_gpib_put ...\n") if ($# != 2) { eprint "usage: hp_gpib_put gpib_address string" exit } _hp_vvv = $2 _hp_uuu = _hp_vvv if (_hp_vvv) { if (GPIB_eol_character[_hp_addr]>0) _hp_uuu = sprintf("%s%c",_hp_vvv,GPIB_eol_character[_hp_addr]) } else { if (GPIB_eol_character[_hp_addr]>0) { _hp_uuu = sprintf("%s%c","$2",GPIB_eol_character[_hp_addr]) } else { _hp_uuu = "$2" } } _hp_addr_sign = $1 _hp_addr = fabs(_hp_addr_sign) if (_hp_addr_sign>0) { GPIB_SERIAL = 0 if (GPIB_debug>8) printf("hp_gpib_put: execute GPIB command\n") _hp_gpib_get 3 if (_hp_addr != GPIB_val) _hp_gpib_init _hp_addr } else { GPIB_SERIAL = 1 if (GPIB_debug>8) printf("hp_gpib_put: execute SERIAL command\n") GPIB_name[GPIB_SERIAL] = sprintf(SERIAL_name_format,_hp_addr) } _hp_gpib_put 1 _hp_uuu if (GPIB_sleep[GPIB_SERIAL][_hp_addr]>0) sleep(GPIB_sleep[GPIB_SERIAL][_hp_addr]) } ' # # # # ################################################################################# # # hp_gpib_get # hp 19.07.2000 # # # ################################################################################# # def hp_gpib_get ' { local _hp_addr,_hp_addr_sign if (GPIB_debug > 10) printf("This is macro hp_gpib_get ...\n") if ($# != 1) { eprint "usage: hp_gpib_get gpib_address" exit } _hp_addr_sign = $1 _hp_addr = fabs(_hp_addr_sign) if (_hp_addr_sign>0) { GPIB_SERIAL = 0 if (GPIB_debug>8) print "hp_gpib_get: execute GPIB command" _hp_gpib_get 3 if (_hp_addr != GPIB_val) _hp_gpib_init _hp_addr } else { GPIB_SERIAL = 1 if (GPIB_debug>8) print "hp_gpib_get: execute SERIAL command" GPIB_name[GPIB_SERIAL] = sprintf(SERIAL_name_format,_hp_addr) } _hp_gpib_put 0 1 if (GPIB_sleep[GPIB_SERIAL][_hp_addr]>0) sleep(GPIB_sleep[GPIB_SERIAL][_hp_addr]) _hp_gpib_get 2 } ' # # # # ################################################################################# # # _hp_gpib_put # hp 19.07.2000 # # # ################################################################################# # def _hp_gpib_put ' { local _hp_i,_hp_val if (GPIB_debug > 10) printf("This is macro _hp_gpib_put ...\n") if ($# != 2) { eprint "Wrong number of arguments in _hp_gpib_put!" exit } _hp_i = $1 if ((_hp_i)<0 || _hp_i>=GPIB_com_n[GPIB_SERIAL]) { eprint "Argument out of range in _hp_gpib_put!" exit } _hp_val = $2 GPIB_field = sprintf("%s%s",GPIB_name[GPIB_SERIAL],GPIB_command[GPIB_SERIAL][_hp_i]) GPIB_val = epics_put(GPIB_field,_hp_val) if (GPIB_debug > 4) printf("_hp_gpib_put: %s = %s\n",GPIB_field,_hp_val) } ' # # # # ################################################################################# # # _hp_gpib_get # hp 19.07.2000 # # # ################################################################################# # def _hp_gpib_get ' { local _hp_i if (GPIB_debug > 10) printf("This is macro hp_gpib_get ...\n") if ($# != 1) { eprint "Wrong number of arguments in _hp_gpib_get!" exit } _hp_i = $1 if ((_hp_i)<0 || _hp_i>=GPIB_com_n[GPIB_SERIAL]) { eprint "Argument out of range in _hp_gpib_get!" exit } GPIB_field = sprintf("%s%s",GPIB_name[GPIB_SERIAL],GPIB_command[GPIB_SERIAL][_hp_i]) GPIB_val = epics_get(GPIB_field) } ' # # # #