/*************************************** * sy127_set.c * * * * SET Parameters of CAEN HV Supply * * ATTENTION: this version inhibits the * * switch on/off of the channels, since * * this operation must be related to * * a switch on the distributor slot !! * * if you REALLY need it, you may use * * sy127_set_special * ***************************************/ #define HV_MAX 6000 #include #include #include #include #include "../lib/mylib1.h" #include "a200.h" /* definitions relative to the CAEN system */ #include "a200.hmn" /* conversion table */ SY127_MBOX *hv_mod; int mev_id; char *caller; sighand(signal) register int signal; { printf(" %s : signal %d received \n",*caller, signal); if ( signal >= 2 && signal <= 3){ /* ^C or ^E ? */ A200_end(); sem_unl_del(mev_id, "sy127mod", caller); munlink(hv_mod); exit(0); } } main(argc, argv) int argc; char *argv[]; { short ndata, data[45]; int hra[6]; short i, j, code; int try; int max_try = 3; char *par_code, *crate_code, *chan_code, *set_code; short par_val, crate_val, chan_val, set_val; short map[40]; intercept(sighand); caller = argv[0]; if (argc < 5 || *argv[1] =='-'){ printf(" sy127_set : set parameters on the CAEN HV Supply \n"); printf("\n usage : sy127_set par crate chan value \n"); printf("\n par : V0, V1, I0, I1, RAMP_UP, RAMP_DOWN, \n"); printf(" TRIP, GROUP_ASS \n"); printf("\n crate : 0 \n"); printf("\n chan : 0-39 , ALL, \n"); printf(" GAG_A, GAG_B ... GAG_G, \n"); printf(" GRG_A, GRG_B ... GRG_G \n"); printf(" (group G includes channel of B/RMU)\n"); printf("\n value : depends on the chosen par \n"); exit(0); } par_code = argv[1]; crate_code = argv[2]; chan_code = argv[3]; set_code = argv[4]; if (!isdigit( *par_code)) { if ((par_val = (short) find_code(par_code)) < 0 ) exit(_errmsg(0," %s error decoding parameter\n",caller)); } else par_val = (short) atoi(par_code); if (par_val == SWITCH){ printf(" HV voltage channels must be sincronized with Distr. slots\n"); printf(" if you really need to change a HV channel alone\n"); printf(" please use sy127_set_special ( under your responsability !)\n"); exit(0); } if (!isdigit( *crate_code)) { if ((crate_val = (short) find_code(crate_code)) < 0 ) exit(_errmsg(0," %s error decoding crate\n",caller)); } else crate_val = (short) atoi(crate_code); if (!isdigit( *chan_code)) { if ((chan_val = (short) find_code(chan_code)) < 0 ) exit(_errmsg(0," %s error decoding chan\n",caller)); } else chan_val = (short) atoi(chan_code); if (!isdigit( *set_code)) { if ((set_val = (short) find_code(set_code)) < 0 ) exit(_errmsg(0," %s error decoding value to be set\n",caller)); } else set_val = (short) atoi(set_code); if (chan_val >= ALL && par_val == ALL_PAR) exit(_errmsg(0,"%s cannot set several paraneters on several channel\n", caller )); mev_id = sem_link_cr("sy127mod", argv[0]); if((hv_mod = (SY127_MBOX *)modlink("sy127mod", 0)) == (SY127_MBOX *)-1){ data_ora(&hra[0], &hra[1], &hra[2], &hra[3], &hra[4], &hra[5]); sem_wait(mev_id, argv[0]); if((hv_mod = (SY127_MBOX *) _mkdata_module("sy127mod", sizeof(SY127_MBOX), 0x8001, 0x0033)) == (SY127_MBOX *)-1) /* see module.h for attr,perm */ exit(_errmsg(errno,"hv_mod: err. link/create data module\n")); for(i=0; i<6; i++) hv_mod->creat_tim[i] = hra[i]; sem_free(mev_id, argv[0]); } A200_init(); /* take the module until update is ok */ sem_wait(mev_id, argv[0]); /* read HV map */ HV_Map(crate_val); for(try = 1; try < max_try; try++){ if ( (par_val == V0 || par_val == V1) && set_val > HV_MAX) printf(" Too large of HV: %d\n", set_val); else if ((code = HV_Set(par_val, crate_val, chan_val, set_val)) ==0) { data_ora(&hra[0], &hra[1], &hra[2], &hra[3], &hra[4], &hra[5]); for(i=0; i<6; i++) hv_mod->pset_tim[i] = hra[i]; if (chan_val >= ALL && chan_val <= GRG_G) get_map( crate_val, chan_val, map); switch (par_val){ case V0: if (set_val > HV_MAX) printf(" Bad value of HV: %d V !!!\n", set_val); else if (chan_val < ALL) hv_mod->hv_par[0].v0[chan_val] = set_val; else if (chan_val >= ALL && chan_val <= GRG_G) for( i = 0; i < 40; i++) if (map[i]){ if (chan_val >= ALL && chan_val <= GAG_G) hv_mod->hv_par[0].v0[i] = set_val; else if (chan_val >= GRG_ALL && chan_val <= GRG_G) hv_mod->hv_par[0].v0[i] += set_val; } break; case V1: if (set_val > HV_MAX) printf(" Bad value of HV: %d V !!!\n", set_val); else if (chan_val < ALL) hv_mod->hv_par[0].v1[chan_val] = set_val; else if (chan_val >= ALL && chan_val <= GRG_G) for( i = 0; i < 40; i++) if (map[i]){ if (chan_val >= ALL && chan_val <= GAG_G) hv_mod->hv_par[0].v1[i] = set_val; else if (chan_val >= GRG_ALL && chan_val <= GRG_G) hv_mod->hv_par[0].v1[i] += set_val; } break; case I0: if (chan_val < ALL) hv_mod->hv_par[0].i0[chan_val] = set_val; else if (chan_val >= ALL && chan_val <= GRG_G) for( i = 0; i < 40; i++) if (map[i]){ if (chan_val >= ALL && chan_val <= GAG_G) hv_mod->hv_par[0].i0[i] = set_val; else if (chan_val >= GRG_ALL && chan_val <= GRG_G) hv_mod->hv_par[0].i0[i] += set_val; } break; case I1: if (chan_val < ALL) hv_mod->hv_par[0].i1[chan_val] = set_val; else if (chan_val >= ALL && chan_val <= GRG_G) for( i = 0; i < 40; i++) if (map[i]){ if (chan_val >= ALL && chan_val <= GAG_G) hv_mod->hv_par[0].i1[i] = set_val; else if (chan_val >= GRG_ALL && chan_val <= GRG_G) hv_mod->hv_par[0].i1[i] += set_val; } break; case RAMP_UP: if (chan_val < ALL) hv_mod->hv_par[0].ramp_up[chan_val] = set_val; else if (chan_val >= ALL && chan_val <= GRG_G) for( i = 0; i < 40; i++) if (map[i]){ if (chan_val >= ALL && chan_val <= GAG_G) hv_mod->hv_par[0].ramp_up[i] = set_val; else if (chan_val >= GRG_ALL && chan_val <= GRG_G) hv_mod->hv_par[0].ramp_up[i] += set_val; } break; case RAMP_DOWN: if (chan_val < ALL) hv_mod->hv_par[0].ramp_down[chan_val] = set_val; else if (chan_val >= ALL && chan_val <= GRG_G) for( i = 0; i < 40; i++) if (map[i]){ if (chan_val >= ALL && chan_val <= GAG_G) hv_mod->hv_par[0].ramp_down[i] = set_val; else if (chan_val >= GRG_ALL && chan_val <= GRG_G) hv_mod->hv_par[0].ramp_down[i] += set_val; } break; case SWITCH: if (chan_val < ALL) hv_mod->hv_par[0].status[chan_val] = set_val; else if (chan_val >= ALL && chan_val <= GRG_G) for( i = 0; i < 40; i++) if (map[i]) hv_mod->hv_par[0].status[i] = set_val; break; case CH_TO_GR_ASS: if (chan_val < ALL) hv_mod->hv_par[0].ch_to_gr_ass[chan_val] = set_val; else if (chan_val >= ALL && chan_val <= GRG_G) for( i = 0; i < 40; i++) if (map[i]) hv_mod->hv_par[0].ch_to_gr_ass[i] = set_val; break; } break; } } sem_free(mev_id, argv[0]); A200_end(); sem_unl_del(mev_id, "SY127mod", caller); munlink(hv_mod); if ( try == max_try ){ printf(" %s not able to set HV after %d attempts \n", caller, max_try); exit(-1); } else exit(0); } int find_code(par_code) char *par_code; { int i; for ( i = 0; *(par_code + i) != '\0'; i++) *(par_code + i) = (char) toupper((int) *(par_code + i)); for( i = 0; i < a200_conv_tab_size; i++) if (strcmp(a200_conv[i].key, par_code) == 0) break; if ( i < a200_conv_tab_size ) return a200_conv[i].code; else return -1; }