Low-Energy Muon (LEM) Experiment  0.5.1
hv_fug.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdarg.h>
#include "midas.h"
#include "msystem.h"
#include "hv_fug.h"
#include "ets_logout.h"
#include "lemSCWatchdog.h"
Include dependency graph for hv_fug.c:

Go to the source code of this file.

Data Structures

struct  HV_FUG_SETTINGS
 stores internal informations within the DD. More...
 
struct  HV_FUG_INFO
 
struct  HV_FUG_FP
 

Macros

#define FP_1000   0x0001
 RS 232 Network-Module. More...
 
#define FP_1001   0x0002
 RS 485 module, not used for NEMU. More...
 
#define FP_AI_110   0x0101
 16-bit-Analog-Input More...
 
#define FP_AO_200   0x0102
 12-bit-Analog-Output (Current), not used anymore for NEMU More...
 
#define FP_DI_330   0x0103
 not used for NEMU More...
 
#define FP_DO_400   0x0104
 not used for NEMU More...
 
#define FP_DI_301   0x0105
 not used for NEMU More...
 
#define FP_DO_401   0x0106
 not used for NEMU More...
 
#define FP_TC_120   0x0107
 not used for NEMU More...
 
#define FP_RLY_420   0x0108
 relay module More...
 
#define FP_DI_300   0x0109
 not used for NEMU More...
 
#define FP_AI_100   0x010A
 not used for NEMU More...
 
#define FP_RTD_122   0x010B
 not used for NEMU More...
 
#define FP_AI_111   0x010C
 not used for NEMU More...
 
#define FP_AO_210   0x010F
 12-bit-Analog-Output (Voltage) More...
 
#define FP_IO_NUM_CH   8
 

channels per module

More...
 
#define FP_AI_110_RANGE   0x04
 0 - 10.4 V More...
 
#define FP_AI_110_FILTER   0x00
 60 Hz More...
 
#define FP_AO_210_RANGE   0x04
 0 - 10.2 V More...
 
#define FP_RLY_SETTING   0x10
 default reply More...
 
#define FP_IO_RESOL   65536
 resolution of the i/o commands 2^16 More...
 
#define FP_AO_NORM   0.9804
 Max FUG prog / Max AO. More...
 
#define FP_AI_NORM   1.04
 Max AI / Max FUG prog. More...
 
#define FP_ERR_PUCLR_EXP   0x00
 
#define HV_FUG_TIME_OUT   3000
 time out for read rs232 communication in (ms). More...
 
#define HV_FUG_MAX_ERROR   5
 maximum number of error messages More...
 
#define HV_FUG_DELTA_TIME_ERROR   3600
 reset error counter after HV_FUG_DELTA_TIME_ERROR seconds More...
 
#define HV_FUG_MAX_READBACK_FAILURE   5
 maximum number of readback failures before a reconnect will take place More...
 
#define HV_FUG_RECONNECTION_TIMEOUT   10
 timeout in (sec) for before trying to reconnect again (after a communication breakdown) More...
 
#define HV_FUG_READ_ERROR   -99
 return value in case a read back error occured More...
 
#define HV_FUG_ETS_LOGOUT_SLEEP   10000
 sleep time (us) between the telnet commands of the ets_logout More...
 
#define HV_FUG_SETTINGS_INTERNAL_STR   "\Detailed Messages = INT : 0\n\ETS_IN_USE = INT : 1\n\SCW_IN_USE = INT : 1\n\"
 
#define HV_FUG_SETTINGS_ODB_OFFSET_STR   "\ODB Channel Offset = INT : 0\n\"
 
#define HV_FUG_SETTINGS_NO_STR   "\No of FP-IO Modules = INT : 9\n\"
 
#define HV_FUG_SETTINGS_MODULE_STR   "\Modules = STRING : [128] 0:FP-1000; 1:FP-AO-210; 2:FP-AI-110; 3:FP-AI-110; 4:FP-AO-210; 5:FP-AI-110; 6:FP-AO-210; 7:FP-AI-110; 8:FP-RLY-420;\n\"
 
#define HV_FUG_SETTINGS_OUT_STR   "\FUG fp mapping output = STRING[12] : \n\[64] Moderator 04 0x0004 04 0x0008 N 00 0x0000 \n\[64] Mod_Guard 04 0x0010 04 0x0020 N 00 0x0000 \n\[64] Mod_Grid 01 0x0001 01 0x0002 N 00 0x0000 \n\[64] Lense_1 01 0x0004 01 0x0008 N 00 0x0000 \n\[64] Mirror 04 0x0001 04 0x0002 N 00 0x0000 \n\[64] Lense_2 01 0x0040 01 0x0080 N 00 0x0000 \n\[64] Lense_3 01 0x0010 01 0x0020 N 00 0x0000 \n\[64] RA-L 06 0x0010 06 0x0020 Y 08 0x0008 \n\[64] RA-R 06 0x0004 06 0x0008 Y 08 0x0004 \n\[64] RA-T 06 0x0001 06 0x0002 Y 08 0x0002 \n\[64] RA-B 04 0x0040 04 0x0080 Y 08 0x0001 \n\[64] Sample 06 0x0040 06 0x0080 Y 08 0x0010 \n\"
 
#define HV_FUG_SETTINGS_IN_STR   "\FUG fp mapping input = STRING[12] : \n\[64] Moderator 03 0x0004 03 0x0008 N 00 0x0000 \n\[64] Mod_Guard 03 0x0010 03 0x0020 N 00 0x0000 \n\[64] Mod_Grid 02 0x0001 02 0x0002 N 00 0x0000 \n\[64] Lense_1 02 0x0004 02 0x0008 N 00 0x0000 \n\[64] Mirror 03 0x0001 03 0x0002 N 00 0x0000 \n\[64] Lense_2 02 0x0040 02 0x0080 N 00 0x0000 \n\[64] Lense_3 02 0x0010 02 0x0020 N 00 0x0000 \n\[64] RA-L 07 0x0010 07 0x0020 Y 05 0x0008 \n\[64] RA-R 07 0x0004 07 0x0008 Y 05 0x0004 \n\[64] RA-T 07 0x0001 07 0x0002 Y 05 0x0002 \n\[64] RA-B 03 0x0040 03 0x0080 Y 05 0x0001 \n\[64] Sample 07 0x0040 07 0x0080 Y 05 0x0010 \n\"
 
#define HV_FUG_SETTINGS_PROPERTIES_STR   "\Properties = STRING[12] : \n\[64] Moderator @35.0kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\[64] Mod_Guard @20.0kV #0.6mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\[64] Mod_Grid @12.5kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\[64] Lense_1 @12.5kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\[64] Mirror @35.0kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\[64] Lense_2 @35.0kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\[64] Lense_3 @35.0kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\[64] RA-L @35.0kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\[64] RA-R @35.0kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\[64] RA-T @20.0kV #0.6mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\[64] RA-B @20.0kV #0.6mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\[64] Sample @12.5kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\"
 
#define HV_FUG_SCW_STR   "\Proc Name = STRING : [32]\n\PID = INT : -1\n\Log Name = STRING : [64]\n\DD Name = STRING : [32] FUG\n\Last Updated = DWORD : 0\n\Timeout = DWORD : 180\n\"
 defines the slowcontrol default watchdog info structure More...
 

Functions

INT hv_fug_get (HV_FUG_INFO *info, INT channel, float *pvalue)
 
INT fp_error_msg (HV_FUG_INFO *info, char *where, char *error)
 
void mid_str (char *start, char *stop, char *line, char *result)
 
void sub_str (int start, int stop, char *line, char *result, int size_line, int size_result)
 
char * filter_sub_str (char *str, char *start, char *stop, char *result)
 
int chksumchk (char *line, char *chksum)
 
int chk_attrib_in (HV_FUG_INFO *info, int module, char *line)
 
int chk_attrib_out (HV_FUG_INFO *info, int module, char *line)
 
int chk_attrib_rly (HV_FUG_INFO *info, int module, char *line)
 
void err_bad_channels (char *line, int module, HV_FUG_INFO *info)
 
static INT hv_fug_update_db_settings (HNDLE hDB, HV_FUG_INFO *info, INT channels)
 
static INT fp_power_up_clear (HNDLE hDB, HV_FUG_INFO *info)
 
static INT fp_check_modules (HNDLE hDB, HV_FUG_INFO *info)
 
static INT fp_check_attrib_settings (HNDLE hDB, HV_FUG_INFO *info)
 
static INT fp_write_defaults (HNDLE hDB, HV_FUG_INFO *info)
 
INT hv_fug_init (HNDLE hKey, void **pinfo, INT channels, INT(*bd)(INT cmd,...))
 
INT hv_fug_exit (HV_FUG_INFO *info)
 
INT hv_fug_set (HV_FUG_INFO *info, INT channel, float value)
 
INT hv_fug_get_label (INT channel, char *name)
 
INT hv_fug_get_current (HV_FUG_INFO *info, INT channel, float *pvalue)
 
INT hv_fug_set_current_limit (HV_FUG_INFO *info, INT channel, float limit)
 
INT hv_fug (INT cmd,...)
 

Variables

static HV_FUG_FP hv_fug_fp_set [12]
 

Macro Definition Documentation

#define FP_1000   0x0001

RS 232 Network-Module.

Definition at line 119 of file hv_fug.c.

#define FP_1001   0x0002

RS 485 module, not used for NEMU.

Definition at line 120 of file hv_fug.c.

#define FP_AI_100   0x010A

not used for NEMU

Definition at line 130 of file hv_fug.c.

#define FP_AI_110   0x0101

16-bit-Analog-Input

Definition at line 121 of file hv_fug.c.

#define FP_AI_110_FILTER   0x00

60 Hz

Definition at line 153 of file hv_fug.c.

Referenced by chk_attrib_in().

#define FP_AI_110_RANGE   0x04

0 - 10.4 V

Definition at line 152 of file hv_fug.c.

Referenced by chk_attrib_in().

#define FP_AI_111   0x010C

not used for NEMU

Definition at line 132 of file hv_fug.c.

#define FP_AI_NORM   1.04

Max AI / Max FUG prog.

Definition at line 158 of file hv_fug.c.

Referenced by hv_fug_get(), and hv_fug_get_current().

#define FP_AO_200   0x0102

12-bit-Analog-Output (Current), not used anymore for NEMU

Definition at line 122 of file hv_fug.c.

#define FP_AO_210   0x010F

12-bit-Analog-Output (Voltage)

Definition at line 133 of file hv_fug.c.

#define FP_AO_210_RANGE   0x04

0 - 10.2 V

Definition at line 154 of file hv_fug.c.

Referenced by chk_attrib_out().

#define FP_AO_NORM   0.9804

Max FUG prog / Max AO.

Definition at line 157 of file hv_fug.c.

Referenced by fp_write_defaults(), hv_fug_set(), and hv_fug_set_current_limit().

#define FP_DI_300   0x0109

not used for NEMU

Definition at line 129 of file hv_fug.c.

#define FP_DI_301   0x0105

not used for NEMU

Definition at line 125 of file hv_fug.c.

#define FP_DI_330   0x0103

not used for NEMU

Definition at line 123 of file hv_fug.c.

#define FP_DO_400   0x0104

not used for NEMU

Definition at line 124 of file hv_fug.c.

#define FP_DO_401   0x0106

not used for NEMU

Definition at line 126 of file hv_fug.c.

#define FP_ERR_PUCLR_EXP   0x00

defines starting with FP_ERR_* are error codes of the field point modules. For details see the field point module documentation of National Instruments.

Definition at line 166 of file hv_fug.c.

Referenced by fp_error_msg().

#define FP_IO_NUM_CH   8

channels per module

Definition at line 151 of file hv_fug.c.

Referenced by chk_attrib_in(), chk_attrib_out(), chk_attrib_rly(), and fp_check_attrib_settings().

#define FP_IO_RESOL   65536

resolution of the i/o commands 2^16

Definition at line 156 of file hv_fug.c.

Referenced by fp_write_defaults(), hv_fug_get(), hv_fug_get_current(), hv_fug_set(), and hv_fug_set_current_limit().

#define FP_RLY_420   0x0108

relay module

Definition at line 128 of file hv_fug.c.

#define FP_RLY_SETTING   0x10

default reply

Definition at line 155 of file hv_fug.c.

Referenced by chk_attrib_rly().

#define FP_RTD_122   0x010B

not used for NEMU

Definition at line 131 of file hv_fug.c.

#define FP_TC_120   0x0107

not used for NEMU

Definition at line 127 of file hv_fug.c.

#define HV_FUG_DELTA_TIME_ERROR   3600

reset error counter after HV_FUG_DELTA_TIME_ERROR seconds

Definition at line 194 of file hv_fug.c.

Referenced by hv_fug_get(), and hv_fug_get_current().

#define HV_FUG_ETS_LOGOUT_SLEEP   10000

sleep time (us) between the telnet commands of the ets_logout

Definition at line 204 of file hv_fug.c.

Referenced by hv_fug_get().

#define HV_FUG_MAX_ERROR   5
#define HV_FUG_MAX_READBACK_FAILURE   5

maximum number of readback failures before a reconnect will take place

Definition at line 197 of file hv_fug.c.

Referenced by hv_fug_get().

#define HV_FUG_READ_ERROR   -99

return value in case a read back error occured

Definition at line 201 of file hv_fug.c.

Referenced by hv_fug_get().

#define HV_FUG_RECONNECTION_TIMEOUT   10

timeout in (sec) for before trying to reconnect again (after a communication breakdown)

Definition at line 199 of file hv_fug.c.

Referenced by hv_fug_get().

#define HV_FUG_SCW_STR   "\Proc Name = STRING : [32]\n\PID = INT : -1\n\Log Name = STRING : [64]\n\DD Name = STRING : [32] FUG\n\Last Updated = DWORD : 0\n\Timeout = DWORD : 180\n\"

defines the slowcontrol default watchdog info structure

Definition at line 403 of file hv_fug.c.

Referenced by hv_fug_init().

#define HV_FUG_SETTINGS_IN_STR   "\FUG fp mapping input = STRING[12] : \n\[64] Moderator 03 0x0004 03 0x0008 N 00 0x0000 \n\[64] Mod_Guard 03 0x0010 03 0x0020 N 00 0x0000 \n\[64] Mod_Grid 02 0x0001 02 0x0002 N 00 0x0000 \n\[64] Lense_1 02 0x0004 02 0x0008 N 00 0x0000 \n\[64] Mirror 03 0x0001 03 0x0002 N 00 0x0000 \n\[64] Lense_2 02 0x0040 02 0x0080 N 00 0x0000 \n\[64] Lense_3 02 0x0010 02 0x0020 N 00 0x0000 \n\[64] RA-L 07 0x0010 07 0x0020 Y 05 0x0008 \n\[64] RA-R 07 0x0004 07 0x0008 Y 05 0x0004 \n\[64] RA-T 07 0x0001 07 0x0002 Y 05 0x0002 \n\[64] RA-B 03 0x0040 03 0x0080 Y 05 0x0001 \n\[64] Sample 07 0x0040 07 0x0080 Y 05 0x0010 \n\"

Initializing sub-string for HV_FUG_SETTINGS. default mapping field point<->FUG of the input channels

Definition at line 350 of file hv_fug.c.

Referenced by hv_fug_init().

#define HV_FUG_SETTINGS_INTERNAL_STR   "\Detailed Messages = INT : 0\n\ETS_IN_USE = INT : 1\n\SCW_IN_USE = INT : 1\n\"

Initializing sub-string for HV_FUG_SETTINGS. Internal flags.

Definition at line 225 of file hv_fug.c.

Referenced by hv_fug_init().

#define HV_FUG_SETTINGS_MODULE_STR   "\Modules = STRING : [128] 0:FP-1000; 1:FP-AO-210; 2:FP-AI-110; 3:FP-AI-110; 4:FP-AO-210; 5:FP-AI-110; 6:FP-AO-210; 7:FP-AI-110; 8:FP-RLY-420;\n\"

Initializing sub-string for HV_FUG_SETTINGS. default device settings, field point and channel addresses

Definition at line 251 of file hv_fug.c.

Referenced by hv_fug_init().

#define HV_FUG_SETTINGS_NO_STR   "\No of FP-IO Modules = INT : 9\n\"

Initializing sub-string for HV_FUG_SETTINGS. default: how many FP-IO modules do exist, in which bank, and what type

Definition at line 243 of file hv_fug.c.

Referenced by hv_fug_init().

#define HV_FUG_SETTINGS_ODB_OFFSET_STR   "\ODB Channel Offset = INT : 0\n\"

Initializing sub-string for HV_FUG_SETTINGS. default: channel offset within ODB

Definition at line 235 of file hv_fug.c.

Referenced by hv_fug_init().

#define HV_FUG_SETTINGS_OUT_STR   "\FUG fp mapping output = STRING[12] : \n\[64] Moderator 04 0x0004 04 0x0008 N 00 0x0000 \n\[64] Mod_Guard 04 0x0010 04 0x0020 N 00 0x0000 \n\[64] Mod_Grid 01 0x0001 01 0x0002 N 00 0x0000 \n\[64] Lense_1 01 0x0004 01 0x0008 N 00 0x0000 \n\[64] Mirror 04 0x0001 04 0x0002 N 00 0x0000 \n\[64] Lense_2 01 0x0040 01 0x0080 N 00 0x0000 \n\[64] Lense_3 01 0x0010 01 0x0020 N 00 0x0000 \n\[64] RA-L 06 0x0010 06 0x0020 Y 08 0x0008 \n\[64] RA-R 06 0x0004 06 0x0008 Y 08 0x0004 \n\[64] RA-T 06 0x0001 06 0x0002 Y 08 0x0002 \n\[64] RA-B 04 0x0040 04 0x0080 Y 08 0x0001 \n\[64] Sample 06 0x0040 06 0x0080 Y 08 0x0010 \n\"

Initializing sub-string for HV_FUG_SETTINGS. default mapping field point<->FUG of the output channels

Definition at line 295 of file hv_fug.c.

Referenced by hv_fug_init().

#define HV_FUG_SETTINGS_PROPERTIES_STR   "\Properties = STRING[12] : \n\[64] Moderator @35.0kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\[64] Mod_Guard @20.0kV #0.6mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\[64] Mod_Grid @12.5kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\[64] Lense_1 @12.5kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\[64] Mirror @35.0kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\[64] Lense_2 @35.0kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\[64] Lense_3 @35.0kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\[64] RA-L @35.0kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\[64] RA-R @35.0kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\[64] RA-T @20.0kV #0.6mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\[64] RA-B @20.0kV #0.6mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\[64] Sample @12.5kV #1.0mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA \n\"

Initializing sub-string for HV_FUG_SETTINGS. default: Description of the individual FUG HV devices

Definition at line 386 of file hv_fug.c.

Referenced by hv_fug_init().

#define HV_FUG_TIME_OUT   3000

time out for read rs232 communication in (ms).

Definition at line 190 of file hv_fug.c.

Referenced by fp_check_attrib_settings(), fp_check_modules(), fp_power_up_clear(), fp_write_defaults(), hv_fug_get(), hv_fug_get_current(), hv_fug_set(), and hv_fug_set_current_limit().

Function Documentation

int chk_attrib_in ( HV_FUG_INFO info,
int  module,
char *  line 
)

checks if the attribute and range settings of an input field point module is correct.

Return:

  • 0, if OK
  • FE_ERR_HW, otherwise.
Parameters
infois a pointer to the DD specific info structure
moduleFP input module number
lineresponds string from the field point interface

Definition at line 684 of file hv_fug.c.

References HV_FUG_INFO::errorcount, FP_AI_110_FILTER, FP_AI_110_RANGE, FP_IO_NUM_CH, and HV_FUG_MAX_ERROR.

Referenced by fp_check_attrib_settings().

int chk_attrib_out ( HV_FUG_INFO info,
int  module,
char *  line 
)

checks if the attribute and range settings of an output field point module is correct.

Return:

  • 0, if OK
  • FE_ERR_HW, otherwise.
Parameters
infois a pointer to the DD specific info structure
moduleFP output module number
lineresponds string from the field point interface

Definition at line 726 of file hv_fug.c.

References HV_FUG_INFO::errorcount, FP_AO_210_RANGE, FP_IO_NUM_CH, and HV_FUG_MAX_ERROR.

Referenced by fp_check_attrib_settings().

int chk_attrib_rly ( HV_FUG_INFO info,
int  module,
char *  line 
)

checks if the attribute and range settings of an relay field point module is correct.

Return:

  • 0, if OK
  • FE_ERR_HW, otherwise.
Parameters
infois a pointer to the DD specific info structure
moduleFP input module number
lineresponds string from the field point interface

Definition at line 759 of file hv_fug.c.

References HV_FUG_INFO::errorcount, FP_IO_NUM_CH, FP_RLY_SETTING, and HV_FUG_MAX_ERROR.

Referenced by fp_check_attrib_settings().

int chksumchk ( char *  line,
char *  chksum 
)

checks the if the checksum of 'line' corresponds to 'chksum'

Return:

  • 1, if checksum is OK
  • 0, otherwise.
Parameters
lineinput string which needs to be checked if it corresponds to chksum
chksumas a string

Definition at line 654 of file hv_fug.c.

Referenced by fp_check_attrib_settings(), hv_fug_get(), hv_fug_get_current(), and hv_fug_set().

void err_bad_channels ( char *  line,
int  module,
HV_FUG_INFO info 
)

generates from a coded input an error message when a channel went bad, and sends a message to the ODB message system.

Parameters
lineresponds string from the field point interface
moduleFP module number
infois a pointer to the DD specific info structure

Definition at line 788 of file hv_fug.c.

References HV_FUG_INFO::errorcount, HV_FUG_MAX_ERROR, and HV_FUG_INFO::num_channels.

Referenced by fp_write_defaults().

char* filter_sub_str ( char *  str,
char *  start,
char *  stop,
char *  result 
)

searches substring for sandwiched substring and returns substring if found otherwise returns NULL.

Return: pointer to result

Parameters
strinput string
startstart-pattern
stopstop-pattern
resultreturn sub-string

Definition at line 631 of file hv_fug.c.

static INT fp_check_attrib_settings ( HNDLE  hDB,
HV_FUG_INFO info 
)
static

checks all the settings of the field point moduels.

gets ALL the attributes and ranges of ALL the channels per input module at once. see FieldPoint Programmer Reference Manual, p.5-14

0xFF = 11111111, i.e. for every channel (8 for the FP-AI-110) there is a character (bit) set = 1. for each channel 'bit' set there is an attribute mask and a range mask. The attribute mask is 4 byte (e.g. 0x0001) and the range mask 1 byte (e.g. 1).

return structure: A0004...000420 with the meaning for each channel 4 characters, the first two are the attributes 0x00=60Hz, the second two are the range 0x04=0-10.4V. The very last two characters of the string are the checksum. (for checksum see subroutine chksumchk above and Manual P.1-3)

Return:

  • 0, if everthing was fine.
  • error code otherwise.
Parameters
hDBhandle onto the ODB
infois a pointer to the DD specific info structure

Definition at line 1084 of file hv_fug.c.

References chk_attrib_in(), chk_attrib_out(), chk_attrib_rly(), chksumchk(), HV_FUG_SETTINGS::detailed_msg, fp_error_msg(), FP_IO_NUM_CH, HV_FUG_TIME_OUT, HV_FUG_INFO::hv_settings, HV_FUG_SETTINGS::no_fp_modules, and sub_str().

Referenced by hv_fug_init().

static INT fp_check_modules ( HNDLE  hDB,
HV_FUG_INFO info 
)
static

checks if the number of field point modules is correct and further, if the modules are correctely connected and of the right type.

Return:

  • 0, if everthing was fine.
  • FE_ERR_HW otherwise.
Parameters
hDBhandle onto the ODB
infois a pointer to the DD specific info structure

Definition at line 984 of file hv_fug.c.

References HV_FUG_INFO::errorcount, fp_error_msg(), HV_FUG_SETTINGS::fp_io_modules, HV_FUG_MAX_ERROR, HV_FUG_TIME_OUT, HV_FUG_INFO::hv_settings, mid_str(), and HV_FUG_SETTINGS::no_fp_modules.

Referenced by hv_fug_init().

INT fp_error_msg ( HV_FUG_INFO info,
char *  where,
char *  error 
)

This routine decodes an error message obtained form the field point modules. It sends a message to the midas message system if an error occured.

Return: FE_ERR_HW

Parameters
infois a pointer to the DD specific info structure
wherestring holding the name of the routine which got the field point error message
errorcoded error message form the field point module

Definition at line 484 of file hv_fug.c.

References HV_FUG_SETTINGS::detailed_msg, HV_FUG_INFO::errorcount, FP_ERR_PUCLR_EXP, HV_FUG_MAX_ERROR, and HV_FUG_INFO::hv_settings.

Referenced by fp_check_attrib_settings(), fp_check_modules(), fp_write_defaults(), hv_fug_get(), hv_fug_get_current(), hv_fug_set(), and hv_fug_set_current_limit().

static INT fp_power_up_clear ( HNDLE  hDB,
HV_FUG_INFO info 
)
static

sends a 'power up clear' command to the field point modules, and checks the responds. For 'power up clear' see 'FieldPoint Programmer Reference Manual' p.4-2.

Return:

  • 0, if everthing was fine.
  • FE_ERR_HW otherwise.
Parameters
hDBhandle onto the ODB
infois a pointer to the DD specific info structure

Definition at line 950 of file hv_fug.c.

References HV_FUG_INFO::errorcount, HV_FUG_MAX_ERROR, HV_FUG_TIME_OUT, HV_FUG_INFO::hv_settings, and HV_FUG_SETTINGS::no_fp_modules.

Referenced by hv_fug_init().

static INT fp_write_defaults ( HNDLE  hDB,
HV_FUG_INFO info 
)
static

sends default values (current limits, ...) to the field point modules.

Return:

  • 0, if everthing was fine.
  • error code otherwise.
Parameters
hDBhandle onto the ODB
infois a pointer to the DD specific info structure

Definition at line 1173 of file hv_fug.c.

References HV_FUG_FP::channel_cdc_out, err_bad_channels(), HV_FUG_INFO::errorcount, FP_AO_NORM, fp_error_msg(), FP_IO_RESOL, HV_FUG_MAX_ERROR, HV_FUG_TIME_OUT, HV_FUG_INFO::hv_settings, HV_FUG_FP::module_cdc_out, HV_FUG_SETTINGS::no_fp_modules, HV_FUG_INFO::num_channels, and sub_str().

Referenced by hv_fug_init().

INT hv_fug ( INT  cmd,
  ... 
)

The FUG high voltage devices are used for the muon transport system in the low energy muon experiment (LEM) at PSI. Since the high voltage devices themselfs only have analog input controls, analog input/output cards of National Instruments (FP-AI-110 / FP-AO-210) are used to connect to the digital world. To control them via a computer a special interface card (FP1000) and bus is used (again National Instrument stuff).

The hard wiring looks like this:

                                   |- FP-RLY-420,bus address 8 (set polarity of FUG HCL devices 8-12)
                                   |- FP-AI-110, bus address 5 (read polarity of FUG HCL devices 8-12)
                                   |- FP-AI-110, bus address 7 (Grid_1, Sample_G1, Sample_G2, Sample)
                                   |- FP-AI-110, bus address 3 (Lense_3, RA-L, RA-R, Guard)
                                   |- FP-AI-110, bus address 2 (Moderator, Lense_1, Mirror, Lense_2)
PC <-- Lantronix/RS232 --> FP1000 -|
                                   |- FP-AO-210, bus address 6 (Grid_1, Sample_G1, Sample_G2, Sample)
                                   |- FP-AO-210, bus address 4 (Lense_3, RA-L, RA-R, Guard)
                                   |- FP-AO-210, bus address 1 (Moderator, Lense_1, Mirror, Lense_2)

i.e. we use

  • 3 analog input cards (FP-AI-110) with each 8 channels to read the HV and the current
  • 3 analog output cards (FP-AO-210) with each 8 channels to write the HV and the current
  • 1 anlog input card (FP-AI-110) with 8 channels to read the polarity of HCL devices (5 devices (8-12) connected in control box)
  • 1 relay module (FP-RLY-420) with 8 channels to set the polarity of HCL devices (5 devices (8-12) connected in control box)

for 12 FUG high voltage devices. Each FUG HV device needs 2 input and 2 output channels (in/out voltage/current).

The new HCL devices (we will use four of them for Grid_1, Sample_G1, Sample_G2, Sample) have the option to change the polarity remotely. This is done by using the relay module FP-RLY-420. The polarity of these devices is monitored by an additional FP-AI-110: +polarity gives ~15V, i.e. overrange at the FP-AI-110 (10.4V max. measurable voltage) -polarity gives ~0V.

For a detailed description of the command language of the field point bus of National Instruments see: Field Point – FP-1000/FP-1001 Programmer Reference Manual.

The ODB equipment definition of the different FUG HV devices is organized as follows: key : /Equipment/HV/Settings/Devices/FUG/DD

With the following entries:

  • No of FP-IO Modules: total number of field point modules
  • Modules: list of all the modules 'x1:name1; x2:name2; ...' with x_i the number of the field point module and name_i the type of the field point module, i.e. FP-1000 for the RS232 communication module.
  • FUG fp mapping input: coded array of all the input channels. The coding is as follows (e.g. Moderator 02 0x0001 02 0x0002 N 00 0x0000):
    • name u_module u_ch i_module i_ch switch_tag module u_ch, with
      • name : name of the fug
      • u_module : voltage readback module (bus address)
      • u_ch : voltage readback channel (channel address)
      • i_module : current readback module (bus address)
      • i_ch : current readback channel (channel address)
      • switch_tag : (Y/N) Y: polarity of the FUG is remote switchable, otherwise N
      • module : if switch_tag = Y, the module of the relais readback (bus address)
      • u_ch : relais readback channel (channel address)
  • FUG fp mapping output: dito to 'FUG fp mapping input' except for the output channels
  • Properties: specification of the FUG's coded as e.g.
    Moderator @ 20.0kV #0.6mA up0.1kV/s down0.0kV/s $0.00kV !0.001mA
       ^        ^       ^       ^          ^          ^        ^
      name   max hv     |     upramp    downramp   default hv  |
                     max current                      default current limit
    
  • Moderator Group: on/off, xkV -> on : i.e. Moderator, Mod_Guard, Mod_Grid form a group where the maximal difference in the HV is x kV, e.g. on, 5kV if 'off' you can do whatever you want
  • Sample Group: dito, where Sample, Sample_G1, Sample_G2 form a group
  • RA Group: dito, where RA-R and RA-L form a group

RS232: 9600 baud, 8 data bits, 1 stop bit, no parity bit, no hardware protocol, no software protocol, termination: \ r (CR)

Definition at line 1790 of file hv_fug.c.

References hKey, hv_fug_exit(), hv_fug_get(), hv_fug_get_current(), hv_fug_get_label(), hv_fug_init(), hv_fug_set(), hv_fug_set_current_limit(), and info.

INT hv_fug_exit ( HV_FUG_INFO info)

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

Return: FE_SUCCESS

Parameters
infois a pointer to the DD specific info structure

Definition at line 1415 of file hv_fug.c.

References HV_FUG_INFO::bd, HV_FUG_INFO::bd_connected, HV_FUG_INFO::bd_info, HV_FUG_INFO::hv_settings, HV_FUG_INFO::scw, HV_FUG_SETTINGS::scw_in_use, and HV_FUG_INFO::startup_error.

Referenced by hv_fug().

INT hv_fug_get_current ( HV_FUG_INFO info,
INT  channel,
float *  pvalue 
)

gets the current measured value of an FUG.

Return: FE_SUCCESS

Parameters
infois a pointer to the DD specific info structure
channelto be set
pvaluepointer onto current measured in (mA)

Definition at line 1694 of file hv_fug.c.

References HV_FUG_INFO::bd_connected, chksumchk(), HV_FUG_INFO::errorcount, FP_AI_NORM, fp_error_msg(), FP_IO_RESOL, HV_FUG_DELTA_TIME_ERROR, HV_FUG_MAX_ERROR, HV_FUG_TIME_OUT, HV_FUG_INFO::last_valid_current, HV_FUG_INFO::lasterrtime, HV_FUG_FP::max_curr, HV_FUG_INFO::startup_error, and sub_str().

Referenced by hv_fug().

INT hv_fug_get_label ( INT  channel,
char *  name 
)

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

Return: FE_SUCCESS

Parameters
channelof the name to be set
namepointer to the ODB name

Definition at line 1678 of file hv_fug.c.

Referenced by hv_fug().

INT hv_fug_init ( HNDLE  hKey,
void **  pinfo,
INT  channels,
INT(*)(INT cmd,...)  bd 
)

Initializes the fug device drivers via the field point modules, i.e. generates all the necessary structures in the ODB if necessary, initializes the bus driver and the FUG's.

Return:

  • FE_SUCCESS if everything went smooth
  • FE_ERR_ODB otherwise
Parameters
hKeyis the device driver handle given from the class driver
pinfois needed to store the internal info structure
channelsis the number of channels of the device (from the class driver)
bdis a pointer to the bus driver

Definition at line 1271 of file hv_fug.c.

References HV_FUG_INFO::bd, HV_FUG_INFO::bd_connected, HV_FUG_INFO::bd_info, HV_FUG_INFO::errorcount, HV_FUG_INFO::first_bd_error, fp_check_attrib_settings(), fp_check_modules(), fp_power_up_clear(), fp_write_defaults(), hDB, HV_FUG_INFO::hDB, HV_FUG_INFO::hDDkey, hKey, HV_FUG_INFO::hkey, HV_FUG_SCW_STR, HV_FUG_SETTINGS_IN_STR, HV_FUG_SETTINGS_INTERNAL_STR, HV_FUG_SETTINGS_MODULE_STR, HV_FUG_SETTINGS_NO_STR, HV_FUG_SETTINGS_ODB_OFFSET_STR, HV_FUG_SETTINGS_OUT_STR, HV_FUG_SETTINGS_PROPERTIES_STR, hv_fug_update_db_settings(), HV_FUG_INFO::hv_settings, info, HV_FUG_INFO::last_reconnect, HV_FUG_INFO::lasterrtime, HV_FUG_INFO::num_channels, HV_FUG_INFO::readback_failure, HV_FUG_INFO::reconnection_failures, HV_FUG_INFO::scw, HV_FUG_SETTINGS::scw_in_use, and HV_FUG_INFO::startup_error.

Referenced by hv_fug().

INT hv_fug_set ( HV_FUG_INFO info,
INT  channel,
float  value 
)

sets the HV demand value of an FUG.

Return: FE_SUCCESS

Parameters
infois a pointer to the DD specific info structure
channelto be set
valueHV demand in (kV)

Definition at line 1443 of file hv_fug.c.

References HV_FUG_INFO::bd_connected, chksumchk(), HV_FUG_INFO::errorcount, HV_FUG_INFO::first_bd_error, FP_AO_NORM, fp_error_msg(), FP_IO_RESOL, HV_FUG_MAX_ERROR, HV_FUG_TIME_OUT, HV_FUG_FP::max_volt, HV_FUG_INFO::startup_error, and sub_str().

Referenced by hv_fug().

INT hv_fug_set_current_limit ( HV_FUG_INFO info,
INT  channel,
float  limit 
)

sets the current limit values of an FUG.

Return: FE_SUCCESS

Parameters
infois a pointer to the DD specific info structure
channelto be set
limitcurrent limit value in (mA)

Definition at line 1758 of file hv_fug.c.

References HV_FUG_INFO::bd_connected, FP_AO_NORM, fp_error_msg(), FP_IO_RESOL, HV_FUG_TIME_OUT, and HV_FUG_INFO::startup_error.

Referenced by hv_fug().

static INT hv_fug_update_db_settings ( HNDLE  hDB,
HV_FUG_INFO info,
INT  channels 
)
static
void mid_str ( char *  start,
char *  stop,
char *  line,
char *  result 
)

copies a substring from 'line' starting at 'start' and ending at 'stop' to 'result'.

Parameters
startstart pattern
stopstop pattern
lineinput string
resultreturn sub-string

Definition at line 582 of file hv_fug.c.

Referenced by fp_check_modules().

void sub_str ( int  start,
int  stop,
char *  line,
char *  result,
int  size_line,
int  size_result 
)

copies a substring from 'line' starting at 'start' and ending at 'stop' to 'result'.

Parameters
startstart-position
stopstop-position
lineinput string
resultreturn sub-string
size_linesize of line
size_resultsize of result

Definition at line 604 of file hv_fug.c.

Referenced by fp_check_attrib_settings(), fp_write_defaults(), hv_fug_get(), hv_fug_get_current(), and hv_fug_set().

Variable Documentation

HV_FUG_FP hv_fug_fp_set[12]
static

global variable which handles all the settings 12 = No of FUG HV devices

Definition at line 462 of file hv_fug.c.