Low-Energy Muon (LEM) Experiment  0.5.2
hv_nhq_20xm_mscb.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <math.h>
#include <time.h>
#include "midas.h"
#include "mscb.h"
#include "hv_nhq_20xm_mscb.h"
Include dependency graph for hv_nhq_20xm_mscb.c:

Go to the source code of this file.

Data Structures

struct  HV_NHQ_20XM_SETTINGS
 
struct  MSCB_NODE_VARS
 
struct  HV_NHQ_20XM_INFO
 

Macros

#define NHQ_MAX_INIT_LOOP   5
 how often mscb_info is called before an startup error is generated More...
 
#define NHQ_DEBUG   0
 debug flag More...
 
#define NHQ_ON   0x000
 nhq tag indicating that hv channel is switched on More...
 
#define NHQ_OFF   0x001
 nhq tag indicating that hv channel is switched off More...
 
#define NHQ_MAN   0x002
 nhq tag indicating that hv channel is switched to manual More...
 
#define NHQ_ERR   0x004
 nhq tag indicating that hv channel exceeded either max. HV or max. current More...
 
#define NHQ_INH   0x008
 nhq tag indicating that hv channel inhibit signal fired More...
 
#define NHQ_QUA   0x010
 nhq tag indicating that hv channel output HV quality is not guaranteed at the moment More...
 
#define NHQ_TRP   0x020
 nhq tag indicating that hv channel has triped More...
 
#define NHQ_CH_MAN   0x02
 status flag showing that the nhq channel is switched to manual operation More...
 
#define NHQ_POL_POS   0x04
 status flag showing that the nhq channel has positive polarization More...
 
#define NHQ_CH_OFF   0x08
 status flag showing that the nhq channel is switched off More...
 
#define NHQ_KILL_ENABLE   0x10
 status flag showing that the nhq channel is in the 'kill enable' mode More...
 
#define NHQ_CH_INHIBIT   0x20
 status flag showing that the nhq channel inhibit signal is active More...
 
#define NHQ_TOO_HIGH   0x40
 status flag showing that the nhq channel is over voltage More...
 
#define NHQ_BAD_QUAL   0x80
 status flag showing that the nhq channel output HV is not stable enough More...
 
#define NHQ_NO_CHS   2
 number of HV channels of the NHQ More...
 
#define NHQ_NO_VARS   29
 number of variables on SCS-210-NHQ More...
 
#define NHQ_CMD   0x01
 general command tag for the scs210_nhq_m2xm More...
 
#define NHQ_CMD_D   0x02
 set demand voltage command tag for the scs210_nhq_m2xm More...
 
#define NHQ_CMD_V   0x04
 set ramping speed command tag for the scs210_nhq_m2xm More...
 
#define NHQ_ID   0x06
 get id command tag for the scs210_nhq_m2xm More...
 
#define NHQ_WAITTIME   0x07
 get wait time command tag for the scs210_nhq_m2xm More...
 
#define NHQ_U   0x08
 get measured high voltage command tag for the scs210_nhq_m2xm More...
 
#define NHQ_I   0x0A
 get current command tag for the scs210_nhq_m2xm More...
 
#define NHQ_M   0x0C
 get voltage limit command tag for the scs210_nhq_m2xm More...
 
#define NHQ_N   0x0E
 get current command tag for the scs210_nhq_m2xm More...
 
#define NHQ_D   0x10
 get demand voltage command tag for the scs210_nhq_m2xm More...
 
#define NHQ_V   0x12
 get ramping speed command tag for the scs210_nhq_m2xm More...
 
#define NHQ_L   0x14
 get current trip level command tag for the scs210_nhq_m2xm More...
 
#define NHQ_S   0x16
 get channel status command tag for the scs210_nhq_m2xm More...
 
#define NHQ_T   0x18
 get device status command tag for the scs210_nhq_m2xm More...
 
#define NHQ_A   0x1A
 get auto start command tag for the scs210_nhq_m2xm More...
 
#define NHQ_BAUD   0x1C
 get baud rate command tag for the scs210_nhq_m2xm More...
 
#define NHQ_MAX_ALLOWED_ERR   25
 maximal allowed tolerable errors More...
 
#define HV_NHQ_20XM_SETTINGS_STR   "\Enabled = BOOL : 0\n\Debug = BOOL : 0\n\Device = STRING : [32] mscbfff \n\PWD = STRING : [32] ???? \n\Group Addr = INT : 1\n\Node Addr = INT : 11\n\Reboot Time = STRING : [32] 00:57\n\ODB Offset = INT : 0\n\Device Name = STRING : [32] NHQ 204M Trigger Module 1 \n\Max. Voltage (kV) = FLOAT : 4.f \n\Max. Current (mA) = FLOAT : 3.f \n\CH_Name = STRING[2] : \n\[32] NHQ 204M%A \n\[32] NHQ 204M%B \n\Update Threshold Measured = FLOAT[2] : \n\0.005 \n\0.005 \n\Update Threshold Current = FLOAT[2] : \n\0.005 \n\0.005 \n\Voltage Limit = FLOAT[2] : \n\4.0 \n\4.0 \n\Current Limit = FLOAT[2] : \n\0.001 \n\0.001 \n\Ramp Speed Up = FLOAT[2] : \n\0.1 \n\0.1 \n\Ramp Speed Down = FLOAT[2] : \n\0.0 \n\0.0 \n\"
 Init ODB string for the HV_NHQ_20XM_SETTINGS. Used if the DD entry doesn't exist yet. More...
 

Functions

int hv_nhq_20xm_mscb_get_all (HV_NHQ_20XM_INFO *info, BOOL read_all)
 
void hv_nhq_20xm_mscb_check_status (HV_NHQ_20XM_INFO *info, int ch)
 
INT hv_nhq_20xm_mscb_update_odb (HV_NHQ_20XM_INFO *info, int channels)
 
int hv_nhq_20xm_mscb_set_ramping (HV_NHQ_20XM_INFO *info, INT channels)
 
void hv_nhq_20xm_mscb_get_reboot_time (HV_NHQ_20XM_INFO *info)
 
INT hv_nhq_20xm_mscb_init (HNDLE hKey, void **pinfo, INT channels, INT(*bd)(INT cmd,...))
 
INT hv_nhq_20xm_mscb_exit (HV_NHQ_20XM_INFO *info)
 
INT hv_nhq_20xm_mscb_set (HV_NHQ_20XM_INFO *info, INT channel, float value)
 
INT hv_nhq_20xm_mscb_get_label (HV_NHQ_20XM_INFO *info, INT channel, char *name)
 
INT hv_nhq_20xm_mscb_get (HV_NHQ_20XM_INFO *info, INT channel, float *pvalue)
 
INT hv_nhq_20xm_mscb_get_demand (HV_NHQ_20XM_INFO *info, INT channel, float *pvalue)
 
INT hv_nhq_20xm_mscb_get_current (HV_NHQ_20XM_INFO *info, INT channel, float *pvalue)
 
INT hv_nhq_20xm_mscb (INT cmd,...)
 

Macro Definition Documentation

#define HV_NHQ_20XM_SETTINGS_STR   "\Enabled = BOOL : 0\n\Debug = BOOL : 0\n\Device = STRING : [32] mscbfff \n\PWD = STRING : [32] ???? \n\Group Addr = INT : 1\n\Node Addr = INT : 11\n\Reboot Time = STRING : [32] 00:57\n\ODB Offset = INT : 0\n\Device Name = STRING : [32] NHQ 204M Trigger Module 1 \n\Max. Voltage (kV) = FLOAT : 4.f \n\Max. Current (mA) = FLOAT : 3.f \n\CH_Name = STRING[2] : \n\[32] NHQ 204M%A \n\[32] NHQ 204M%B \n\Update Threshold Measured = FLOAT[2] : \n\0.005 \n\0.005 \n\Update Threshold Current = FLOAT[2] : \n\0.005 \n\0.005 \n\Voltage Limit = FLOAT[2] : \n\4.0 \n\4.0 \n\Current Limit = FLOAT[2] : \n\0.001 \n\0.001 \n\Ramp Speed Up = FLOAT[2] : \n\0.1 \n\0.1 \n\Ramp Speed Down = FLOAT[2] : \n\0.0 \n\0.0 \n\"

Init ODB string for the HV_NHQ_20XM_SETTINGS. Used if the DD entry doesn't exist yet.

Definition at line 98 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_init().

#define NHQ_A   0x1A

get auto start command tag for the scs210_nhq_m2xm

Definition at line 65 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_get_all().

#define NHQ_BAD_QUAL   0x80

status flag showing that the nhq channel output HV is not stable enough

Definition at line 42 of file hv_nhq_20xm_mscb.c.

#define NHQ_BAUD   0x1C

get baud rate command tag for the scs210_nhq_m2xm

Definition at line 66 of file hv_nhq_20xm_mscb.c.

#define NHQ_CH_INHIBIT   0x20

status flag showing that the nhq channel inhibit signal is active

Definition at line 40 of file hv_nhq_20xm_mscb.c.

#define NHQ_CH_MAN   0x02

status flag showing that the nhq channel is switched to manual operation

Definition at line 36 of file hv_nhq_20xm_mscb.c.

#define NHQ_CH_OFF   0x08

status flag showing that the nhq channel is switched off

Definition at line 38 of file hv_nhq_20xm_mscb.c.

#define NHQ_CMD   0x01

general command tag for the scs210_nhq_m2xm

Definition at line 51 of file hv_nhq_20xm_mscb.c.

#define NHQ_CMD_D   0x02

set demand voltage command tag for the scs210_nhq_m2xm

Definition at line 52 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_set().

#define NHQ_CMD_V   0x04

set ramping speed command tag for the scs210_nhq_m2xm

Definition at line 53 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_set_ramping().

#define NHQ_D   0x10

get demand voltage command tag for the scs210_nhq_m2xm

Definition at line 60 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_get_all().

#define NHQ_DEBUG   0

debug flag

Definition at line 25 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_init().

#define NHQ_ERR   0x004

nhq tag indicating that hv channel exceeded either max. HV or max. current

Definition at line 30 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_check_status().

#define NHQ_I   0x0A

get current command tag for the scs210_nhq_m2xm

Definition at line 57 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_get_all().

#define NHQ_ID   0x06

get id command tag for the scs210_nhq_m2xm

Definition at line 54 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_get_all().

#define NHQ_INH   0x008

nhq tag indicating that hv channel inhibit signal fired

Definition at line 31 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_check_status().

#define NHQ_KILL_ENABLE   0x10

status flag showing that the nhq channel is in the 'kill enable' mode

Definition at line 39 of file hv_nhq_20xm_mscb.c.

#define NHQ_L   0x14

get current trip level command tag for the scs210_nhq_m2xm

Definition at line 62 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_get_all().

#define NHQ_M   0x0C

get voltage limit command tag for the scs210_nhq_m2xm

Definition at line 58 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_get_all().

#define NHQ_MAN   0x002

nhq tag indicating that hv channel is switched to manual

Definition at line 29 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_check_status().

#define NHQ_MAX_ALLOWED_ERR   25

maximal allowed tolerable errors

Definition at line 69 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_get().

#define NHQ_MAX_INIT_LOOP   5

how often mscb_info is called before an startup error is generated

Definition at line 23 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_init().

#define NHQ_N   0x0E

get current command tag for the scs210_nhq_m2xm

Definition at line 59 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_get_all().

#define NHQ_NO_CHS   2

number of HV channels of the NHQ

Definition at line 45 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_get_all(), and hv_nhq_20xm_mscb_init().

#define NHQ_NO_VARS   29

number of variables on SCS-210-NHQ

Definition at line 48 of file hv_nhq_20xm_mscb.c.

#define NHQ_OFF   0x001

nhq tag indicating that hv channel is switched off

Definition at line 28 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_check_status().

#define NHQ_ON   0x000

nhq tag indicating that hv channel is switched on

Definition at line 27 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_check_status(), and hv_nhq_20xm_mscb_init().

#define NHQ_POL_POS   0x04

status flag showing that the nhq channel has positive polarization

Definition at line 37 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_init().

#define NHQ_QUA   0x010

nhq tag indicating that hv channel output HV quality is not guaranteed at the moment

Definition at line 32 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_check_status().

#define NHQ_S   0x16

get channel status command tag for the scs210_nhq_m2xm

Definition at line 63 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_get_all().

#define NHQ_T   0x18

get device status command tag for the scs210_nhq_m2xm

Definition at line 64 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_get_all().

#define NHQ_TOO_HIGH   0x40

status flag showing that the nhq channel is over voltage

Definition at line 41 of file hv_nhq_20xm_mscb.c.

#define NHQ_TRP   0x020

nhq tag indicating that hv channel has triped

Definition at line 33 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_check_status().

#define NHQ_U   0x08

get measured high voltage command tag for the scs210_nhq_m2xm

Definition at line 56 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_get_all().

#define NHQ_V   0x12

get ramping speed command tag for the scs210_nhq_m2xm

Definition at line 61 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_get_all().

#define NHQ_WAITTIME   0x07

get wait time command tag for the scs210_nhq_m2xm

Definition at line 55 of file hv_nhq_20xm_mscb.c.

Referenced by hv_nhq_20xm_mscb_get_all().

Function Documentation

INT hv_nhq_20xm_mscb ( INT  cmd,
  ... 
)

nhq high voltag device driver (DD). It is handling the communication between the iseg NHQ hv module and midas.

Definition at line 917 of file hv_nhq_20xm_mscb.c.

References hKey, hv_nhq_20xm_mscb_exit(), hv_nhq_20xm_mscb_get(), hv_nhq_20xm_mscb_get_current(), hv_nhq_20xm_mscb_get_demand(), hv_nhq_20xm_mscb_get_label(), hv_nhq_20xm_mscb_init(), hv_nhq_20xm_mscb_set(), and info.

void hv_nhq_20xm_mscb_check_status ( HV_NHQ_20XM_INFO info,
int  ch 
)

Reads the status of a channel of the nhq module. If there is a status change, it is reported once.

Parameters
infopointer to the device driver info structure
chchannel number

Definition at line 390 of file hv_nhq_20xm_mscb.c.

References HV_NHQ_20XM_SETTINGS::ch_names, HV_NHQ_20XM_INFO::ch_status, HV_NHQ_20XM_INFO::data, HV_NHQ_20XM_SETTINGS::device_name, NHQ_ERR, NHQ_INH, NHQ_MAN, NHQ_OFF, NHQ_ON, NHQ_QUA, NHQ_TRP, MSCB_NODE_VARS::s, and HV_NHQ_20XM_INFO::settings.

Referenced by hv_nhq_20xm_mscb_get().

INT hv_nhq_20xm_mscb_exit ( HV_NHQ_20XM_INFO info)

terminates the bus driver and free's the memory allocated for the info structure BH_INFO.

return: FE_SUCCESS

Parameters
infois a pointer to the DD specific info structure

Definition at line 730 of file hv_nhq_20xm_mscb.c.

References HV_NHQ_20XM_INFO::fd, and HV_NHQ_20XM_INFO::startup_error.

Referenced by hv_nhq_20xm_mscb().

INT hv_nhq_20xm_mscb_get ( HV_NHQ_20XM_INFO info,
INT  channel,
float *  pvalue 
)
INT hv_nhq_20xm_mscb_get_current ( HV_NHQ_20XM_INFO info,
INT  channel,
float *  pvalue 
)

reads a current value from the nhq.

return: FE_SUCCESS

Parameters
infois a pointer to the DD specific info structure.
channelis the channel number
pvalueread

Definition at line 898 of file hv_nhq_20xm_mscb.c.

References HV_NHQ_20XM_INFO::data, MSCB_NODE_VARS::i, and HV_NHQ_20XM_INFO::startup_error.

Referenced by hv_nhq_20xm_mscb().

INT hv_nhq_20xm_mscb_get_demand ( HV_NHQ_20XM_INFO info,
INT  channel,
float *  pvalue 
)

reads back a demand high voltage value from the nhq.

return: FE_SUCCESS

Parameters
infois a pointer to the DD specific info structure.
channelis the channel number
pvalueread

Definition at line 873 of file hv_nhq_20xm_mscb.c.

References MSCB_NODE_VARS::d, HV_NHQ_20XM_INFO::data, and HV_NHQ_20XM_INFO::startup_error.

Referenced by hv_nhq_20xm_mscb().

INT hv_nhq_20xm_mscb_get_label ( HV_NHQ_20XM_INFO info,
INT  channel,
char *  name 
)

at startup, after initialization of the DD, this routine allows to write default names of the in-channels into the ODB.

return: FE_SUCCESS

Parameters
infois a pointer to the DD specific info structure
channelof the name to be set
namepointer to the ODB name

Definition at line 789 of file hv_nhq_20xm_mscb.c.

References HV_NHQ_20XM_SETTINGS::ch_names, and HV_NHQ_20XM_INFO::settings.

Referenced by hv_nhq_20xm_mscb().

void hv_nhq_20xm_mscb_get_reboot_time ( HV_NHQ_20XM_INFO info)

Extracts the reboot time from the DD reboot time string. If this string is not a valid time in the from hh:mm, reboot time array is initialized with -1.

Parameters
infopointer to the device driver info structure

Definition at line 559 of file hv_nhq_20xm_mscb.c.

References HV_NHQ_20XM_SETTINGS::reboot_time, HV_NHQ_20XM_INFO::reboot_time, and HV_NHQ_20XM_INFO::settings.

Referenced by hv_nhq_20xm_mscb_init().

INT hv_nhq_20xm_mscb_init ( HNDLE  hKey,
void **  pinfo,
INT  channels,
INT(*)(INT cmd,...)  bd 
)
INT hv_nhq_20xm_mscb_set ( HV_NHQ_20XM_INFO info,
INT  channel,
float  value 
)

set a high voltage value of the nhq.

return: FE_SUCCESS

Parameters
infois a pointer to the DD specific info structure.
channelis the channel number
valuehigh voltage value in (kV) to be set

Definition at line 752 of file hv_nhq_20xm_mscb.c.

References HV_NHQ_20XM_SETTINGS::ch_names, HV_NHQ_20XM_SETTINGS::device_name, HV_NHQ_20XM_INFO::fd, NHQ_CMD_D, HV_NHQ_20XM_SETTINGS::node_addr, HV_NHQ_20XM_INFO::settings, HV_NHQ_20XM_INFO::startup_error, and HV_NHQ_20XM_SETTINGS::voltage_limit.

Referenced by hv_nhq_20xm_mscb().

int hv_nhq_20xm_mscb_set_ramping ( HV_NHQ_20XM_INFO info,
INT  channels 
)

Sets the HV ramping of the device. Since the frontend is using DF_PRIO_DEVICE, this needs to be done the way it is done here, since the class driver otherwise is reading not only the demand setting from the device back, but also the ramping speed. Since the bloody NHQ is set to 2 V/s ramping speed after repowering this is needed :-(

Parameters
infopointer to the device driver info structure
channelsnumber of channels

Definition at line 526 of file hv_nhq_20xm_mscb.c.

References HV_NHQ_20XM_INFO::fd, HV_NHQ_20XM_INFO::hDB, hKey, NHQ_CMD_V, HV_NHQ_20XM_SETTINGS::node_addr, HV_NHQ_20XM_SETTINGS::odb_offset, offset, and HV_NHQ_20XM_INFO::settings.

Referenced by hv_nhq_20xm_mscb_init().

INT hv_nhq_20xm_mscb_update_odb ( HV_NHQ_20XM_INFO info,
int  channels 
)

This routine updates at startup all the boundary and operation settings of the nhq.

return: ODB status tag, i.e. DB_SUCCESS if everthing is OK

Parameters
infopointer to the device driver info structure
channelsnumber of channels

Definition at line 452 of file hv_nhq_20xm_mscb.c.

References HV_NHQ_20XM_SETTINGS::current_limit, HV_NHQ_20XM_INFO::hDB, hKey, HV_NHQ_20XM_SETTINGS::odb_offset, offset, HV_NHQ_20XM_INFO::settings, HV_NHQ_20XM_SETTINGS::update_threshold_current, HV_NHQ_20XM_SETTINGS::update_threshold_measured, and HV_NHQ_20XM_SETTINGS::voltage_limit.

Referenced by hv_nhq_20xm_mscb_init().