23 #define NHQ_MAX_INIT_LOOP 5
36 #define NHQ_CH_MAN 0x02
37 #define NHQ_POL_POS 0x04
38 #define NHQ_CH_OFF 0x08
39 #define NHQ_KILL_ENABLE 0x10
40 #define NHQ_CH_INHIBIT 0x20
41 #define NHQ_TOO_HIGH 0x40
42 #define NHQ_BAD_QUAL 0x80
48 #define NHQ_NO_VARS 29
52 #define NHQ_CMD_D 0x02
53 #define NHQ_CMD_V 0x04
55 #define NHQ_WAITTIME 0x07
68 #define NHQ_MAX_ALLOWED_ERR 25
79 char port[NAME_LENGTH];
80 char pwd[NAME_LENGTH];
83 char reboot_time[NAME_LENGTH];
85 char device_name[NAME_LENGTH];
98 #define HV_NHQ_20XM_SETTINGS_STR "\
101 Device = STRING : [32] mscbfff \n\
102 PWD = STRING : [32] ???? \n\
103 Group Addr = INT : 1\n\
104 Node Addr = INT : 11\n\
105 Reboot Time = STRING : [32] 00:57\n\
106 ODB Offset = INT : 0\n\
107 Device Name = STRING : [32] NHQ 204M Trigger Module 1 \n\
108 Max. Voltage (kV) = FLOAT : 4.f \n\
109 Max. Current (mA) = FLOAT : 3.f \n\
110 CH_Name = STRING[2] : \n\
113 Update Threshold Measured = FLOAT[2] : \n\
116 Update Threshold Current = FLOAT[2] : \n\
119 Voltage Limit = FLOAT[2] : \n\
122 Current Limit = FLOAT[2] : \n\
125 Ramp Speed Up = FLOAT[2] : \n\
128 Ramp Speed Down = FLOAT[2] : \n\
184 unsigned char buffer[256];
185 int size =
sizeof(buffer);
193 size = 32*
sizeof(char);
195 if (status != MSCB_SUCCESS) {
199 strncpy(info->
data.
id, (
const char *)buffer, 32);
202 size = 6*
sizeof(char);
204 if (status != MSCB_SUCCESS) {
208 status = sscanf((
const char *)buffer,
"%d", &value);
215 size = 6*
sizeof(char);
217 if (status != MSCB_SUCCESS) {
221 status = sscanf((
const char *)buffer,
"%d", &value);
224 info->
data.
m[i] = value;
227 size = 6*
sizeof(char);
229 if (status != MSCB_SUCCESS) {
233 status = sscanf((
const char *)buffer,
"%d", &value);
236 info->
data.
n[i] = value;
239 size = 6*
sizeof(char);
241 if (status != MSCB_SUCCESS) {
245 status = sscanf((
const char *)buffer,
"%d", &value);
248 info->
data.
v[i] = (float)value/1.0e3;
251 size = 6*
sizeof(char);
253 if (status != MSCB_SUCCESS) {
257 status = sscanf((
const char *)buffer,
"%d", &value);
260 info->
data.
l[i] = value;
263 size = 6*
sizeof(char);
265 if (status != MSCB_SUCCESS) {
269 status = sscanf((
const char *)buffer,
"%d", &value);
272 info->
data.
a[i] = value;
281 size = 6*
sizeof(char);
283 if (status != MSCB_SUCCESS) {
287 status = sscanf((
const char *)buffer,
"%d", &value);
290 info->
data.
u[i] = (float)value/1.0e3;
295 size = 6*
sizeof(char);
297 if (status != MSCB_SUCCESS) {
301 status = sscanf((
const char *)buffer,
"%d", &value);
304 info->
data.
d[i] = (float)value/1.0e3;
309 size = 8*
sizeof(char);
311 if (status != MSCB_SUCCESS) {
315 status = sscanf((
const char *)buffer,
"%f%f,", &fvalue, &fexp);
318 sprintf((
char *)buffer,
"%0.1fE%f", fvalue, fexp);
319 sscanf((
const char *)buffer,
"%f", &fvalue);
320 info->
data.
i[i] = fvalue*1.0e3;
325 size = 8*
sizeof(char);
327 if (status != MSCB_SUCCESS) {
331 strncpy(info->
data.
s[i], (
const char *)buffer, 8);
336 size = 6*
sizeof(char);
338 if (status != MSCB_SUCCESS) {
342 status = sscanf((
const char *)buffer,
"%d", &value);
345 info->
data.
t[i] = value;
351 fp = fopen(
"hv_nhq_20xm_mscb.log",
"a");
354 fprintf(fp,
"id: %s\n", info->
data.
id);
356 fprintf(fp,
"u: %f, %f\n", info->
data.
u[0], info->
data.
u[1]);
357 fprintf(fp,
"i: %f, %f\n", info->
data.
i[0], info->
data.
i[1]);
358 fprintf(fp,
"m: %d, %d\n", info->
data.
m[0], info->
data.
m[1]);
359 fprintf(fp,
"n: %d, %d\n", info->
data.
n[0], info->
data.
n[1]);
360 fprintf(fp,
"d: %f, %f\n", info->
data.
d[0], info->
data.
d[1]);
361 fprintf(fp,
"v: %f, %f\n", info->
data.
v[0], info->
data.
v[1]);
362 fprintf(fp,
"l: %d, %d\n", info->
data.
l[0], info->
data.
l[1]);
363 fprintf(fp,
"s: %s, %s\n", info->
data.
s[0], info->
data.
s[1]);
364 fprintf(fp,
"t: %d, %d\n", info->
data.
t[0], info->
data.
t[1]);
365 fprintf(fp,
"a: %d, %d\n", info->
data.
a[0], info->
data.
a[1]);
366 fprintf(fp,
"------------------------\n");
368 fprintf(fp,
"u: %f, %f\n", info->
data.
u[0], info->
data.
u[1]);
369 fprintf(fp,
"i: %f, %f\n", info->
data.
i[0], info->
data.
i[1]);
370 fprintf(fp,
"d: %f, %f\n", info->
data.
d[0], info->
data.
d[1]);
371 fprintf(fp,
"s: %s, %s\n", info->
data.
s[0], info->
data.
s[1]);
372 fprintf(fp,
"t: %d, %d\n", info->
data.
t[0], info->
data.
t[1]);
373 fprintf(fp,
"------------------------\n");
392 if (strstr(info->
data.
s[ch],
"?")) {
395 if (strstr(info->
data.
s[ch],
"ON")) {
398 cm_msg(MINFO,
"hv_nhq_20xm_check_status",
"%s, ch %s, channel switched on at the frontpanel. (%s)",
402 if (strstr(info->
data.
s[ch],
"OFF")) {
405 cm_msg(MERROR,
"hv_nhq_20xm_check_status",
"%s, ch %s, channel switched off at the frontpanel. (%s)",
408 }
else if (strstr(info->
data.
s[ch],
"MAN")) {
411 cm_msg(MERROR,
"hv_nhq_20xm_check_status",
"%s, ch %s, hv switched to manual.",
414 }
else if (strstr(info->
data.
s[ch],
"ERR")) {
417 cm_msg(MERROR,
"hv_nhq_20xm_check_status",
"%s, ch %s, V_max or I_max exceeded.",
420 }
else if (strstr(info->
data.
s[ch],
"INH")) {
423 cm_msg(MERROR,
"hv_nhq_20xm_check_status",
"%s, ch %s, inhibit signal was active.",
426 }
else if (strstr(info->
data.
s[ch],
"QUA")) {
429 cm_msg(MERROR,
"hv_nhq_20xm_check_status",
430 "%s, ch %s, quality of output voltage not guaranteed at present.",
433 }
else if (strstr(info->
data.
s[ch],
"TRP")) {
436 cm_msg(MERROR,
"hv_nhq_20xm_check_status",
"%s, ch %s, current trip was active.",
460 status = db_find_key(info->
hDB, 0,
"/Equipment/HV Detectors/Settings/Update Threshold Measured", &hKey);
461 if (status != DB_SUCCESS)
463 for (i=0; i<channels; i++) {
465 sizeof(
float), i+offset, TID_FLOAT);
469 status = db_find_key(info->
hDB, 0,
"/Equipment/HV Detectors/Settings/Update Threshold Current", &hKey);
470 if (status != DB_SUCCESS)
472 for (i=0; i<channels; i++) {
474 sizeof(
float), i+offset, TID_FLOAT);
478 status = db_find_key(info->
hDB, 0,
"/Equipment/HV Detectors/Settings/Voltage Limit", &hKey);
479 if (status != DB_SUCCESS)
481 for (i=0; i<channels; i++) {
483 sizeof(
float), i+offset, TID_FLOAT);
487 status = db_find_key(info->
hDB, 0,
"/Equipment/HV Detectors/Settings/Current Limit", &hKey);
488 if (status != DB_SUCCESS)
490 for (i=0; i<channels; i++) {
492 sizeof(
float), i+offset, TID_FLOAT);
497 status = db_find_key(info->
hDB, 0,
"/Equipment/HV Detectors/Settings/Ramp Up Speed", &hKey);
498 if (status != DB_SUCCESS)
500 for (i=0; i<channels; i++) {
501 db_set_data_index(info->
hDB, hKey, &value,
sizeof(
float), i+offset, TID_FLOAT);
506 status = db_find_key(info->
hDB, 0,
"/Equipment/HV Detectors/Settings/Ramp Down Speed", &hKey);
507 if (status != DB_SUCCESS)
509 for (i=0; i<channels; i++) {
510 db_set_data_index(info->
hDB, hKey, &value,
sizeof(
float), i+offset, TID_FLOAT);
534 status = db_find_key(info->
hDB, 0,
"/Equipment/HV Detectors/Settings/Ramp Up Speed", &hKey);
535 if (status != DB_SUCCESS)
538 for (i=0; i<channels; i++) {
539 size =
sizeof(float);
540 status = db_get_data_index(info->
hDB, hKey, &value, &size, i+offset, TID_FLOAT);
541 if (status != DB_SUCCESS)
544 sprintf(cmd,
"V%d=%03d", i+1, abs((
int)(value*1.0e3)));
567 if ((status == 2) && ((hh>=0) && (hh<=23)) && ((mm>=0) && (mm<=59))) {
599 cm_get_experiment_database(&hDB, NULL);
603 if ((status != DB_SUCCESS) && (status != DB_OPEN_RECORD)) {
604 cm_msg(MERROR,
"hv_nhq_20xm_init",
"hv_nhq_20xm_init: Error creating NHQ DD record in ODB, status=%d", status);
609 db_find_key(hDB, hKey,
"DD", &ddhKey);
612 db_get_record(hDB, ddhKey, &info->
settings, &size, 0);
616 cm_msg(MINFO,
"hv_nhq_20xm_mscb_init",
"\"%s\" is disabled from the ODB.", info->
settings.
device_name);
627 info->
timer = ss_millitime();
638 if (status != DB_SUCCESS) {
639 cm_msg(MERROR,
"hv_nhq_20xm_mscb_update_odb",
"Error by updating ODB HV settings.");
649 cm_msg(MINFO,
"hv_nhq_20xm_mscb_init",
"hv_nhq_20xm_mscb_init: Couldn't initialize %s, MSCB device %s",
655 cm_msg(MINFO,
"hv_nhq_20xm_mscb_init",
"hv_nhq_20xm_mscb_init: %s, MSCB node %d initialized.",
665 if (status == MSCB_SUCCESS)
670 if (status != MSCB_SUCCESS) {
671 cm_msg(MINFO,
"hv_nhq_20xm_mscb_init",
"hv_nhq_20xm_mscb_init: %s, Couldn't read data.",
679 cm_msg(MINFO,
"hv_nhq_20xm_mscb_init",
"hv_nhq_20xm_mscb_init: %s, node %d, id=%s",
683 cm_msg(MINFO,
"hv_nhq_20xm_mscb_init",
"hv_nhq_20xm_mscb_init: %s, node %d, wait time=%d (ms)",
688 cm_msg(MINFO,
"hv_nhq_20xm_init",
"%s: channel %d - hardware voltage limit = %d%% of %f (kV)",
694 cm_msg(MINFO,
"hv_nhq_20xm_init",
"%s: channel %d - hardware current limit = %d%% of %f (mA)",
700 cm_msg(MINFO,
"hv_nhq_20xm_init",
"%s: status info channel %d: %s",
708 strcpy(pol,
"positive");
711 strcpy(pol,
"negative");
713 cm_msg(MINFO,
"hv_nhq_20xm_init",
"%s: channel %s - pol = %s",
764 cm_msg(MERROR,
"hv_nhq_20xm_mscb_set",
"%s: %s set value = %f exceeds voltage limit = %f.",
772 sprintf(cmd,
"D%d=%04d", channel+1, abs((
int)(value*1.0e3)));
822 localtime_r(&tt, &now);
827 info->
timer = ss_millitime() + 60000;
836 if (info->
timer > ss_millitime())
840 if ((ss_millitime() - info->
timer) > 5000) {
843 info->
timer = ss_millitime();
845 if (status != MSCB_SUCCESS)
853 *pvalue = info->
data.
u[channel];
856 cm_msg(MERROR,
"hv_nhq_20xm_mscb_get",
857 "hv_nhq_20xm_mscb_get: Too many read back errors. Probably a communication problem.");
883 *pvalue = info->
data.
d[channel];
908 if (info->
data.
i[channel]<1.0)
909 *pvalue = info->
data.
i[channel];
922 float value, *pvalue;
927 va_start(argptr, cmd);
933 hKey = va_arg(argptr, HNDLE);
934 info = va_arg(argptr,
void *);
935 channel = va_arg(argptr, INT);
936 flags = va_arg(argptr, DWORD);
937 bd = va_arg(argptr,
void *);
942 info = va_arg(argptr,
void *);
947 info = va_arg(argptr,
void *);
948 channel = va_arg(argptr, INT);
949 value = (float) va_arg(argptr,
double);
954 info = va_arg(argptr,
void *);
955 channel = va_arg(argptr, INT);
956 pvalue = va_arg(argptr,
float*);
961 info = va_arg(argptr,
void *);
962 channel = va_arg(argptr, INT);
963 pvalue = va_arg(argptr,
float*);
968 info = va_arg(argptr,
void *);
969 channel = va_arg(argptr, INT);
970 name = va_arg(argptr,
char *);
974 case CMD_GET_CURRENT:
975 info = va_arg(argptr,
void *);
976 channel = va_arg(argptr, INT);
977 pvalue = va_arg(argptr,
float*);
983 case CMD_SET_TRIP_TIME:
984 case CMD_SET_CURRENT_LIMIT:
986 case CMD_SET_RAMPDOWN:
987 case CMD_SET_VOLTAGE_LIMIT:
988 case CMD_GET_VOLTAGE_LIMIT:
990 case CMD_GET_THRESHOLD:
991 case CMD_GET_THRESHOLD_CURRENT:
992 case CMD_GET_CURRENT_LIMIT:
993 case CMD_GET_TRIP_TIME:
995 case CMD_GET_RAMPDOWN:
#define NHQ_S
get channel status command tag for the scs210_nhq_m2xm
#define NHQ_ID
get id command tag for the scs210_nhq_m2xm
float voltage_limit[NHQ_NO_CHS]
voltage limit in (kV)
void hv_nhq_20xm_mscb_check_status(HV_NHQ_20XM_INFO *info, int ch)
int num_channels
number of channels
#define NHQ_N
get current command tag for the scs210_nhq_m2xm
INT group_addr
group address within the MSCB
#define NHQ_TRP
nhq tag indicating that hv channel has triped
#define NHQ_CMD_D
set demand voltage command tag for the scs210_nhq_m2xm
BOOL debug
if debug flag is on, the read data will be dumped into a file
#define NHQ_MAX_INIT_LOOP
how often mscb_info is called before an startup error is generated
INT hv_nhq_20xm_mscb_exit(HV_NHQ_20XM_INFO *info)
char port[NAME_LENGTH]
MSCB port, e.g. /dev/parport0.
#define NHQ_ON
nhq tag indicating that hv channel is switched on
int t[2]
device status tag
float current_limit[NHQ_NO_CHS]
current limit in (mA)
INT hv_nhq_20xm_mscb(INT cmd,...)
INT hv_nhq_20xm_mscb_init(HNDLE hKey, void **pinfo, INT channels, INT(*bd)(INT cmd,...))
#define NHQ_INH
nhq tag indicating that hv channel inhibit signal fired
int rebooting
flag indicating if NHQ is just rebooting
#define NHQ_T
get device status command tag for the scs210_nhq_m2xm
#define NHQ_A
get auto start command tag for the scs210_nhq_m2xm
float u[2]
measured voltage (kV)
HV_NHQ_20XM_SETTINGS settings
device specifc settings
INT hv_nhq_20xm_mscb_get_current(HV_NHQ_20XM_INFO *info, INT channel, float *pvalue)
int fd
mscb device descriptor
char device_name[NAME_LENGTH]
name of the device as will be shown in MIDAS
#define NHQ_MAX_ALLOWED_ERR
maximal allowed tolerable errors
int wait_time
wait time between send and echo
int l[2]
current trip value (0 -> no current trip)
#define NHQ_V
get ramping speed command tag for the scs210_nhq_m2xm
char pwd[NAME_LENGTH]
MSCB ethernet password.
#define NHQ_WAITTIME
get wait time command tag for the scs210_nhq_m2xm
INT node_addr
node address within the MSCB
float update_threshold_measured[NHQ_NO_CHS]
update threshold for the high voltage in (kV)
BOOL enabled
flag telling if the device is enabled
#define NHQ_D
get demand voltage command tag for the scs210_nhq_m2xm
int ch_status[NHQ_NO_CHS]
channel status tag
int reboot_time[2]
reboot time structure
#define NHQ_M
get voltage limit command tag for the scs210_nhq_m2xm
char reboot_time[NAME_LENGTH]
reboot time string hh:mm, if invalid no reboot will take place
#define NHQ_ERR
nhq tag indicating that hv channel exceeded either max. HV or max. current
#define NHQ_OFF
nhq tag indicating that hv channel is switched off
int ch_pol[NHQ_NO_CHS]
channel polarity
int odb_offset
ODB offset.
int err
global readback error counter
char ch_names[NHQ_NO_CHS][NAME_LENGTH]
name of the channels as will be shown in MIDAS
int hv_nhq_20xm_mscb_get_all(HV_NHQ_20XM_INFO *info, BOOL read_all)
INT hv_nhq_20xm_mscb_get(HV_NHQ_20XM_INFO *info, INT channel, float *pvalue)
int hv_nhq_20xm_mscb_set_ramping(HV_NHQ_20XM_INFO *info, INT channels)
INT hv_nhq_20xm_mscb_update_odb(HV_NHQ_20XM_INFO *info, int channels)
#define NHQ_I
get current command tag for the scs210_nhq_m2xm
INT startup_error
startup error flag
#define NHQ_U
get measured high voltage command tag for the scs210_nhq_m2xm
INT hv_nhq_20xm_mscb_get_demand(HV_NHQ_20XM_INFO *info, INT channel, float *pvalue)
int m[2]
voltage limit in (%) of the maximal voltage
DWORD timer
cyclic timer to read channels
float update_threshold_current[NHQ_NO_CHS]
update threshild for the current in (mA)
INT hv_nhq_20xm_mscb_get_label(HV_NHQ_20XM_INFO *info, INT channel, char *name)
float max_current
maximal current of the high voltage module
#define HV_NHQ_20XM_SETTINGS_STR
Init ODB string for the HV_NHQ_20XM_SETTINGS. Used if the DD entry doesn't exist yet.
#define NHQ_DEBUG
debug flag
#define NHQ_MAN
nhq tag indicating that hv channel is switched to manual
float max_voltage
maximal high voltage of the module
MSCB_NODE_VARS data
data read back from NHQ
#define NHQ_QUA
nhq tag indicating that hv channel output HV quality is not guaranteed at the moment ...
#define NHQ_POL_POS
status flag showing that the nhq channel has positive polarization
float v[2]
ramping speed in (kV/s)
void hv_nhq_20xm_mscb_get_reboot_time(HV_NHQ_20XM_INFO *info)
int n[2]
current limit in (%) of the maximal current
#define NHQ_CMD_V
set ramping speed command tag for the scs210_nhq_m2xm
HNDLE dd_hkey
ODB key to the device driver info.
INT hv_nhq_20xm_mscb_set(HV_NHQ_20XM_INFO *info, INT channel, float value)
#define NHQ_L
get current trip level command tag for the scs210_nhq_m2xm
float d[2]
demand voltage (kV)
#define NHQ_NO_CHS
number of HV channels of the NHQ
float i[2]
measured current (mA)