20 #include "hv_scs3000.h"
47 #define LEMVAC_GAS_INLET_ON 0x80
48 #define LEMVAC_MC_STATUS_WORD_2 15
49 #define LEMVAC_TC_STATUS_WORD_2 18
50 #define LEMVAC_SC_STATUS_WORD_2 21
53 #define FUG_READ_TIME 10
54 #define FUG_DEMAND_CHANGED_TIMEOUT 300
61 #define FUG_BEAMLINE_KV61_CH 28
62 #define FUG_BEAMLINE_KV62_CH 29
100 "FUG Monitoring = INT : 0\n\
101 Trip Rate Source = STRING : [32] TD\n\
102 Trip Enabled = INT : 1\n\
103 Trip Level = INT : 1500000\n\
110 {
"hv_spin_rot", hv_scs3000, 4, null, DF_PRIO_DEVICE },
111 {
"hv_mc_tc", hv_scs3000, 7, null, DF_PRIO_DEVICE },
112 {
"hv_sc", hv_scs3000, 5, null, DF_PRIO_DEVICE }
155 INT
poll_event(INT source, INT count, BOOL test) {
return 1;};
175 char svalue[NAME_LENGTH];
180 strcpy(str,
"/Equipment/Scaler/Variables/RATE/MCP1");
181 status = db_find_key(hDB, 0, str, &hKey);
182 if (status != DB_SUCCESS) {
183 cm_msg(MERROR,
"hv_fug_trip_rate_source_changed",
"hv_fug_scfe: Couldn't find %s", str);
186 db_close_record(hDB, hKey);
189 strcpy(str,
"/Equipment/Scaler/Variables/RATE/TD");
190 status = db_find_key(hDB, 0, str, &hKey);
191 if (status != DB_SUCCESS) {
192 cm_msg(MERROR,
"hv_fug_trip_rate_source_changed",
"hv_fug_scfe: Couldn't find %s", str);
197 if (status != DB_SUCCESS) {
198 cm_msg(MERROR,
"hv_fug_trip_rate_source_changed",
"hv_fug_scfe: Couldn't establish hotlink to %s", str);
203 cm_msg(MINFO,
"hv_fug_trip_rate_source_changed",
"hv_fug_scfe: Switched to the TD rate for the HV trip monitoring");
208 strcpy(str,
"/Equipment/Scaler/Variables/RATE/TD");
209 status = db_find_key(hDB, 0, str, &hKey);
210 if (status != DB_SUCCESS) {
211 cm_msg(MERROR,
"hv_fug_trip_rate_source_changed",
"hv_fug_scfe: Couldn't find %s", str);
214 db_close_record(hDB, hKey);
217 strcpy(str,
"/Equipment/Scaler/Variables/RATE/MCP1");
218 status = db_find_key(hDB, 0, str, &hKey);
219 if (status != DB_SUCCESS) {
220 cm_msg(MERROR,
"hv_fug_trip_rate_source_changed",
"hv_fug_scfe: Couldn't find %s", str);
225 if (status != DB_SUCCESS) {
226 cm_msg(MERROR,
"hv_fug_trip_rate_source_changed",
"hv_fug_scfe: Couldn't establish hotlink to %s", str);
231 cm_msg(MINFO,
"hv_fug_trip_rate_source_changed",
"hv_fug_scfe: Switched to the MCP1 rate for the HV trip monitoring");
234 cm_msg(MERROR,
"hv_fug_trip_rate_source_changed",
"hv_fug_scfe: %s not allowed, will switch to TD",
hv_fug_trip_rate_source);
235 strcpy(str,
"/Equipment/HV/Monitoring/Trip Rate Source");
236 status = db_find_key(hDB, 0, str, &hKey);
237 if (status != DB_SUCCESS) {
238 cm_msg(MERROR,
"hv_fug_trip_rate_source_changed",
"hv_fug_scfe: Couldn't find %s", str);
241 strcpy(svalue,
"TD");
242 db_set_data(hDB, hKey, svalue,
sizeof(svalue), 1, TID_STRING);
260 INT status, size, i, run_state;
262 float hv_demand_value[
FUG_CHS];
263 HNDLE demandKey, runStateKey;
270 strcpy(str,
"/Equipment/HV/Variables/Demand");
271 status = db_find_key(hDB, 0, str, &demandKey);
272 if (status != DB_SUCCESS) {
273 cm_msg(MERROR,
"hv_fug_check_trip_level",
"Couldn't find %s", str);
276 status = db_get_key(hDB, demandKey, &key);
277 if (status != DB_SUCCESS) {
278 cm_msg(MERROR,
"hv_fug_check_trip_level",
"Couldn't get key info of %s", str);
282 size =
sizeof(hv_demand_value);
283 db_get_data(hDB, demandKey, &hv_demand_value, &size, TID_FLOAT);
284 for (i=0; i < key.num_values; i++) {
285 if (hv_demand_value[i] != 0)
289 if (i<key.num_values) {
292 for (i=0; i < key.num_values; i++)
293 db_set_data_index(hDB, demandKey, &value,
sizeof(value), i, TID_FLOAT);
296 sprintf(str,
"HV tripped due to too high rate (TD=%d/trip level=%d)",
299 sprintf(str,
"HV tripped due to too high rate (MCP1=%d/trip level=%d)",
302 cm_msg(MERROR,
"hv_fug_check_trip_level", str);
304 al_trigger_alarm(
"hv_fug_check_trip_level", str,
"Warning",
"High Voltage tripped. Will also close KV61, KV62!", AT_INTERNAL);
309 strcpy(str,
"/Runinfo/State");
310 status = db_find_key(hDB, 0, str, &runStateKey);
311 if (status != DB_SUCCESS) {
312 cm_msg(MERROR,
"hv_fug_check_trip_level",
"Couldn't find %s", str);
315 size =
sizeof(run_state);
316 db_get_data(hDB, runStateKey, &run_state, &size, TID_INT);
317 if (run_state == STATE_RUNNING) {
319 status = cm_transition(TR_PAUSE, 0, str,
sizeof(str), TR_SYNC, 0);
320 if (status != CM_SUCCESS) {
321 cm_msg(MERROR,
"hv_fug_check_trip_level",
"%s", str);
327 strcpy(str,
"/Equipment/Beamline/Variables/Demand");
328 status = db_find_key(hDB, 0, str, &demandKey);
329 if (status != DB_SUCCESS) {
330 cm_msg(MERROR,
"hv_fug_check_trip_level",
"Couldn't find %s", str);
368 hv_measured = (
float *)hv;
372 if (fabs(hv_measured[i]) < 0.1f) {
384 cm_msg(MERROR,
"hv_fug_scfe_monitoring",
"TD HV off!! Will switch off all HV :-(");
385 strcpy(str,
"/Equipment/HV/Variables/Demand");
386 status = db_find_key(hDB, 0, str, &demandKey);
387 if (status != DB_SUCCESS) {
388 cm_msg(MERROR,
"hv_fug_scfe_monitoring",
"Couldn't find %s", str);
391 status = db_get_key(hDB, demandKey, &key);
392 if (status != DB_SUCCESS) {
393 cm_msg(MERROR,
"hv_fug_scfe_monitoring",
"Couldn't get key info of %s", str);
397 for (i=0; i < key.num_values; i++)
398 db_set_data_index(hDB, demandKey, &value,
sizeof(value), i, TID_FLOAT);
430 strcpy(str,
"/Equipment/HV/Variables/Demand");
431 status = db_find_key(hDB, 0, str, &fug_hKey);
432 if (status != DB_SUCCESS) {
433 cm_msg(MERROR,
"hv_fug_scfe_gas_inlet",
"Couldn't find %s", str);
441 db_set_data_index(hDB, fug_hKey, &value,
sizeof(value), i, TID_FLOAT);
447 if (ival & LEMVAC_GAS_INLET_ON) {
449 strcpy(str,
"/Equipment/HV/Variables/Demand");
450 status = db_find_key(hDB, 0, str, &fug_hKey);
451 if (status != DB_SUCCESS) {
452 cm_msg(MERROR,
"hv_fug_scfe_gas_inlet",
"Couldn't find %s", str);
460 db_set_data_index(hDB, fug_hKey, &value,
sizeof(value), i, TID_FLOAT);
466 if (ival & LEMVAC_GAS_INLET_ON) {
468 strcpy(str,
"/Equipment/HV/Variables/Demand");
469 status = db_find_key(hDB, 0, str, &fug_hKey);
470 if (status != DB_SUCCESS) {
471 cm_msg(MERROR,
"hv_fug_scfe_gas_inlet",
"Couldn't find %s", str);
479 db_set_data_index(hDB, fug_hKey, &value,
sizeof(value), i, TID_FLOAT);
515 cm_deregister_transition(TR_START);
516 cm_deregister_transition(TR_STOP);
517 cm_deregister_transition(TR_PAUSE);
518 cm_deregister_transition(TR_RESUME);
546 cm_get_experiment_database(&hDB, NULL);
552 strcpy(str,
"/Equipment/HV/Monitoring/FUG Monitoring");
553 status = db_find_key(hDB, 0, str, &hKey);
554 if (status != DB_SUCCESS) {
555 cm_msg(MINFO,
"frontend_init",
"hv_fug_scfe: Couldn't find %s. Will try to generate it.", str);
558 if (status != DB_SUCCESS) {
559 cm_msg(MERROR,
"frontend_init",
"hv_fug_scfe: **ERROR** Couldn't find %s", str);
566 MODE_READ, NULL, NULL);
567 if (status != DB_SUCCESS) {
568 cm_msg(MERROR,
"frontend_init",
"hv_fug_scfe: Couldn't establish hotlink to %s", str);
659 strcpy(str,
"/Equipment/HV/Variables/Measured");
660 status = db_find_key(hDB, 0, str, &hKey);
661 if (status != DB_SUCCESS) {
662 cm_msg(MERROR,
"frontend_init",
"hv_fug_scfe: Couldn't find %s", str);
681 strcpy(str,
"/Equipment/HV/Variables/Demand");
682 status = db_find_key(hDB, 0, str, &hKey);
683 if (status != DB_SUCCESS) {
684 cm_msg(MERROR,
"frontend_init",
"hv_fug_scfe: Couldn't find %s", str);
713 cm_get_experiment_database(&hDB, NULL);
716 strcpy(str,
"/Equipment/HV/Monitoring/FUG Monitoring");
717 status = db_find_key(hDB, 0, str, &hKey);
718 if (status != DB_SUCCESS) {
719 cm_msg(MERROR,
"frontend_exit",
"hv_fug_scfe: Couldn't find %s, status=%d", str, status);
722 db_close_record(hDB, hKey);
797 strcpy(str,
"/Equipment/HV/Variables/Demand");
798 status = db_find_key(hDB, 0, str, &hKey);
799 if (status != DB_SUCCESS) {
800 cm_msg(MERROR,
"frontend_exit",
"hv_fug_scfe: Couldn't find %s, status=%d", str, status);
803 db_close_record(hDB, hKey);
820 char name[NAME_LENGTH];
828 cm_msg(MINFO,
"frontend_loop",
"hv_fug_scfe: time to do something ...");
836 cm_msg(MINFO,
"frontend_loop",
"hv_fug_scfe: will read hv measured");
840 size =
sizeof(measured);
847 cm_msg(MINFO,
"frontend_loop",
"hv_fug_scfe: ch = %d, drop counter = %d", i,
hv_fug_drop_counter[i]);
851 strcpy(str,
"/Equipment/HV/Settings/Names");
854 db_get_data_index(
hv_fug_hDB, hKey, name, &size, i, TID_STRING);
855 sprintf(str,
"HV FUG %s: measured = %f, demand = %f, check!!",
857 al_trigger_alarm(
"hv_fug_scfe", str,
"Warning", str, AT_INTERNAL);
const char * frontend_name
< created by ODBedit, command "make"
#define FUG_BEAMLINE_KV61_CH
float hv_detectors_measured[HV_DETECTOR_CHANNELS]
INT max_event_size
maximum event size produced by this frontend
#define LEMVAC_GAS_INLET_ON
INT hv_fug_tripEnabled
hotlink variable holding the trip enabled flag
BOOL frontend_call_loop
frontend_loop is called periodically if this variable is TRUE
float hv_fug_demand[FUG_CHS]
INT display_period
a frontend status page is displayed with this frequency in ms
#define LEMVAC_TC_STATUS_WORD_2
INT event_buffer_size
buffer size to hold events
INT hv_fug_tripRate
hotlink variable holding the TD trip rate
#define LEMVAC_SC_STATUS_WORD_2
char hv_fug_trip_rate_source[NAME_LENGTH]
hotlink variable holding the name of the detector which is to monitor the rate
#define FUG_DEMAND_CHANGED_TIMEOUT
int hv_fug_chamber_flag[FUG_CHS]
void hv_fug_scfe_gas_inlet(INT hDB, INT hKey, void *dummy)
int hv_fug_drop_counter[FUG_CHS]
DWORD hv_fug_demand_changed_timer
#define LEMVAC_MC_STATUS_WORD_2
INT hv_fug_detector_rate
hotlink variable holding the TD or MCP1 rate
INT begin_of_run(INT run_number, char *error)
DEVICE_DRIVER hv_driver[]
device driver list
const char * hv_fug_monitoring_str
INT interrupt_configure(INT cmd, INT source, PTYPE adr)
INT resume_run(INT run_number, char *error)
HNDLE hv_fug_measured_hKey
void hv_fug_check_trip_level(INT, INT, void *)
INT max_event_size_frag
maximum event size for fragmented events (EQ_FRAGMENTED)
float lemvac_in[27]
holds the status info of lemvac input variables
void hv_fug_scfe_monitoring(INT hDB, INT hKey, void *hv)
BOOL equipment_common_overwrite
INT hv_fug_monitoring_enabled
hotlink variable holding the monitoring enabled flag
#define FUG_BEAMLINE_KV62_CH
INT end_of_run(INT run_number, char *error)
INT poll_event(INT source, INT count, BOOL test)
INT hv_fug_hvAlreadyOff
HV already switched off.
INT pause_run(INT run_number, char *error)
DWORD hv_fug_check_timestamp
void hv_fug_trip_rate_source_changed(INT hDB, INT hKey, void *dummy)
const char * frontend_file_name
The frontend file name, don't change it.
void hv_fug_demand_changed(INT hDB, INT hKey, void *dummy)