18 #include "hv_scs3000.h"
45 #define LEMVAC_GAS_INLET_ON 0x80
46 #define LEMVAC_MC_STATUS_WORD_2 15
47 #define LEMVAC_TC_STATUS_WORD_2 18
48 #define LEMVAC_SC_STATUS_WORD_2 21
51 #define FUG_READ_TIME 10
52 #define FUG_DEMAND_CHANGED_TIMEOUT 300
59 #define FUG_BEAMLINE_KV61_CH 28
60 #define FUG_BEAMLINE_KV62_CH 29
98 "FUG Monitoring = INT : 0\n\
99 Trip Rate Source = STRING : [32] TD\n\
100 Trip Enabled = INT : 1\n\
101 Trip Level = INT : 1500000\n\
108 {
"hv_spin_rot", hv_scs3000, 4, null, DF_PRIO_DEVICE },
109 {
"hv_mc_tc", hv_scs3000, 7, null, DF_PRIO_DEVICE },
110 {
"hv_sc", hv_scs3000, 5, null, DF_PRIO_DEVICE }
143 INT
poll_event(INT source[], INT count, BOOL test) {
return 1;};
163 char svalue[NAME_LENGTH];
168 strcpy(str,
"/Equipment/Scaler/Variables/RATE/MCP1");
169 status = db_find_key(hDB, 0, str, &hKey);
170 if (status != DB_SUCCESS) {
171 cm_msg(MERROR,
"hv_fug_trip_rate_source_changed",
"hv_fug_scfe: Couldn't find %s", str);
174 db_close_record(hDB, hKey);
177 strcpy(str,
"/Equipment/Scaler/Variables/RATE/TD");
178 status = db_find_key(hDB, 0, str, &hKey);
179 if (status != DB_SUCCESS) {
180 cm_msg(MERROR,
"hv_fug_trip_rate_source_changed",
"hv_fug_scfe: Couldn't find %s", str);
185 if (status != DB_SUCCESS) {
186 cm_msg(MERROR,
"hv_fug_trip_rate_source_changed",
"hv_fug_scfe: Couldn't establish hotlink to %s", str);
191 cm_msg(MINFO,
"hv_fug_trip_rate_source_changed",
"hv_fug_scfe: Switched to the TD rate for the HV trip monitoring");
196 strcpy(str,
"/Equipment/Scaler/Variables/RATE/TD");
197 status = db_find_key(hDB, 0, str, &hKey);
198 if (status != DB_SUCCESS) {
199 cm_msg(MERROR,
"hv_fug_trip_rate_source_changed",
"hv_fug_scfe: Couldn't find %s", str);
202 db_close_record(hDB, hKey);
205 strcpy(str,
"/Equipment/Scaler/Variables/RATE/MCP1");
206 status = db_find_key(hDB, 0, str, &hKey);
207 if (status != DB_SUCCESS) {
208 cm_msg(MERROR,
"hv_fug_trip_rate_source_changed",
"hv_fug_scfe: Couldn't find %s", str);
213 if (status != DB_SUCCESS) {
214 cm_msg(MERROR,
"hv_fug_trip_rate_source_changed",
"hv_fug_scfe: Couldn't establish hotlink to %s", str);
219 cm_msg(MINFO,
"hv_fug_trip_rate_source_changed",
"hv_fug_scfe: Switched to the MCP1 rate for the HV trip monitoring");
222 cm_msg(MERROR,
"hv_fug_trip_rate_source_changed",
"hv_fug_scfe: %s not allowed, will switch to TD",
hv_fug_trip_rate_source);
223 strcpy(str,
"/Equipment/HV/Monitoring/Trip Rate Source");
224 status = db_find_key(hDB, 0, str, &hKey);
225 if (status != DB_SUCCESS) {
226 cm_msg(MERROR,
"hv_fug_trip_rate_source_changed",
"hv_fug_scfe: Couldn't find %s", str);
229 strcpy(svalue,
"TD");
230 db_set_data(hDB, hKey, svalue,
sizeof(svalue), 1, TID_STRING);
248 INT status, size, i, run_state;
250 float hv_demand_value[
FUG_CHS];
251 HNDLE demandKey, runStateKey;
258 strcpy(str,
"/Equipment/HV/Variables/Demand");
259 status = db_find_key(hDB, 0, str, &demandKey);
260 if (status != DB_SUCCESS) {
261 cm_msg(MERROR,
"hv_fug_check_trip_level",
"Couldn't find %s", str);
264 status = db_get_key(hDB, demandKey, &key);
265 if (status != DB_SUCCESS) {
266 cm_msg(MERROR,
"hv_fug_check_trip_level",
"Couldn't get key info of %s", str);
270 size =
sizeof(hv_demand_value);
271 db_get_data(hDB, demandKey, &hv_demand_value, &size, TID_FLOAT);
272 for (i=0; i < key.num_values; i++) {
273 if (hv_demand_value[i] != 0)
277 if (i<key.num_values) {
280 for (i=0; i < key.num_values; i++)
281 db_set_data_index(hDB, demandKey, &value,
sizeof(value), i, TID_FLOAT);
284 sprintf(str,
"HV tripped due to too high rate (TD=%d/trip level=%d)",
287 sprintf(str,
"HV tripped due to too high rate (MCP1=%d/trip level=%d)",
290 cm_msg(MERROR,
"hv_fug_check_trip_level", str);
292 al_trigger_alarm(
"hv_fug_check_trip_level", str,
"Warning",
"High Voltage tripped. Will also close KV61, KV62!", AT_INTERNAL);
297 strcpy(str,
"/Runinfo/State");
298 status = db_find_key(hDB, 0, str, &runStateKey);
299 if (status != DB_SUCCESS) {
300 cm_msg(MERROR,
"hv_fug_check_trip_level",
"Couldn't find %s", str);
303 size =
sizeof(run_state);
304 db_get_data(hDB, runStateKey, &run_state, &size, TID_INT);
305 if (run_state == STATE_RUNNING) {
307 status = cm_transition(TR_PAUSE, 0, str,
sizeof(str), TR_SYNC, 0);
308 if (status != CM_SUCCESS) {
309 cm_msg(MERROR,
"hv_fug_check_trip_level",
"%s", str);
315 strcpy(str,
"/Equipment/Beamline/Variables/Demand");
316 status = db_find_key(hDB, 0, str, &demandKey);
317 if (status != DB_SUCCESS) {
318 cm_msg(MERROR,
"hv_fug_check_trip_level",
"Couldn't find %s", str);
356 hv_measured = (
float *)hv;
360 if (fabs(hv_measured[i]) < 0.1f) {
372 cm_msg(MERROR,
"hv_fug_scfe_monitoring",
"TD HV off!! Will switch off all HV :-(");
373 strcpy(str,
"/Equipment/HV/Variables/Demand");
374 status = db_find_key(hDB, 0, str, &demandKey);
375 if (status != DB_SUCCESS) {
376 cm_msg(MERROR,
"hv_fug_scfe_monitoring",
"Couldn't find %s", str);
379 status = db_get_key(hDB, demandKey, &key);
380 if (status != DB_SUCCESS) {
381 cm_msg(MERROR,
"hv_fug_scfe_monitoring",
"Couldn't get key info of %s", str);
385 for (i=0; i < key.num_values; i++)
386 db_set_data_index(hDB, demandKey, &value,
sizeof(value), i, TID_FLOAT);
418 strcpy(str,
"/Equipment/HV/Variables/Demand");
419 status = db_find_key(hDB, 0, str, &fug_hKey);
420 if (status != DB_SUCCESS) {
421 cm_msg(MERROR,
"hv_fug_scfe_gas_inlet",
"Couldn't find %s", str);
429 db_set_data_index(hDB, fug_hKey, &value,
sizeof(value), i, TID_FLOAT);
435 if (ival & LEMVAC_GAS_INLET_ON) {
437 strcpy(str,
"/Equipment/HV/Variables/Demand");
438 status = db_find_key(hDB, 0, str, &fug_hKey);
439 if (status != DB_SUCCESS) {
440 cm_msg(MERROR,
"hv_fug_scfe_gas_inlet",
"Couldn't find %s", str);
448 db_set_data_index(hDB, fug_hKey, &value,
sizeof(value), i, TID_FLOAT);
454 if (ival & LEMVAC_GAS_INLET_ON) {
456 strcpy(str,
"/Equipment/HV/Variables/Demand");
457 status = db_find_key(hDB, 0, str, &fug_hKey);
458 if (status != DB_SUCCESS) {
459 cm_msg(MERROR,
"hv_fug_scfe_gas_inlet",
"Couldn't find %s", str);
467 db_set_data_index(hDB, fug_hKey, &value,
sizeof(value), i, TID_FLOAT);
503 cm_deregister_transition(TR_START);
504 cm_deregister_transition(TR_STOP);
505 cm_deregister_transition(TR_PAUSE);
506 cm_deregister_transition(TR_RESUME);
534 cm_get_experiment_database(&hDB, NULL);
540 strcpy(str,
"/Equipment/HV/Monitoring/FUG Monitoring");
541 status = db_find_key(hDB, 0, str, &hKey);
542 if (status != DB_SUCCESS) {
543 cm_msg(MINFO,
"frontend_init",
"hv_fug_scfe: Couldn't find %s. Will try to generate it.", str);
546 if (status != DB_SUCCESS) {
547 cm_msg(MERROR,
"frontend_init",
"hv_fug_scfe: **ERROR** Couldn't find %s", str);
554 MODE_READ, NULL, NULL);
555 if (status != DB_SUCCESS) {
556 cm_msg(MERROR,
"frontend_init",
"hv_fug_scfe: Couldn't establish hotlink to %s", str);
561 strcpy(str,
"/Equipment/HV/Monitoring/Trip Rate Source");
562 status = db_find_key(hDB, 0, str, &hKey);
563 if (status != DB_SUCCESS) {
564 cm_msg(MERROR,
"frontend_init",
"hv_fug_scfe: Couldn't find %s", str);
569 if (status != DB_SUCCESS) {
570 cm_msg(MERROR,
"frontend_init",
"hv_fug_scfe: Couldn't establish hotlink to %s", str);
575 strcpy(str,
"/Equipment/HV/Monitoring/Trip Enabled");
576 status = db_find_key(hDB, 0, str, &hKey);
577 if (status != DB_SUCCESS) {
578 cm_msg(MERROR,
"frontend_init",
"hv_fug_scfe: Couldn't find %s", str);
582 MODE_READ, NULL, NULL);
583 if (status != DB_SUCCESS) {
584 cm_msg(MERROR,
"frontend_init",
"hv_fug_scfe: Couldn't establish hotlink to %s", str);
589 strcpy(str,
"/Equipment/HV/Monitoring/Trip Level");
590 status = db_find_key(hDB, 0, str, &hKey);
591 if (status != DB_SUCCESS) {
592 cm_msg(MERROR,
"frontend_init",
"hv_fug_scfe: Couldn't find %s", str);
596 MODE_READ, NULL, NULL);
597 if (status != DB_SUCCESS) {
598 cm_msg(MERROR,
"frontend_init",
"hv_fug_scfe: Couldn't establish hotlink to %s", str);
603 cm_msg(MINFO,
"frontend_init",
"hv_fug_scfe: will used TD rate for HV rate monitoring");
604 strcpy(str,
"/Equipment/Scaler/Variables/RATE/TD");
606 cm_msg(MINFO,
"frontend_init",
"hv_fug_scfe: will used MCP1 rate for HV rate monitoring");
607 strcpy(str,
"/Equipment/Scaler/Variables/RATE/MCP1");
609 status = db_find_key(hDB, 0, str, &hKey);
610 if (status != DB_SUCCESS) {
611 cm_msg(MERROR,
"frontend_init",
"hv_fug_scfe: Couldn't find %s", str);
616 if (status != DB_SUCCESS) {
617 cm_msg(MERROR,
"frontend_init",
"hv_fug_scfe: Couldn't establish hotlink to %s", str);
622 strcpy(str,
"/Equipment/HV Detectors/Variables/Measured");
623 status = db_find_key(hDB, 0, str, &hKey);
624 if (status != DB_SUCCESS) {
625 cm_msg(MERROR,
"frontend_init",
"hv_fug_scfe: Couldn't find %s", str);
628 status = db_get_key(hDB, hKey, &keyInfo);
629 if (status != DB_SUCCESS) {
630 cm_msg(MERROR,
"frontend_init",
"hv_fug_scfe: Couldn't get key info of %s", str);
637 keyInfo.num_values*
sizeof(
float),
639 if (status != DB_SUCCESS) {
640 cm_msg(MERROR,
"frontend_init",
"hv_fug_scfe: Couldn't establish hotlink to %s", str);
645 strcpy(str,
"/Equipment/HV/Variables/Measured");
646 status = db_find_key(hDB, 0, str, &hKey);
647 if (status != DB_SUCCESS) {
648 cm_msg(MERROR,
"frontend_init",
"hv_fug_scfe: Couldn't find %s", str);
654 strcpy(str,
"/Equipment/LEMVAC/Variables/Input");
655 status = db_find_key(hDB, 0, str, &hKey);
656 if (status != DB_SUCCESS) {
657 cm_msg(MERROR,
"frontend_init",
"hv_fug_scfe: Couldn't find %s", str);
665 strcpy(str,
"/Equipment/HV/Variables/Demand");
666 status = db_find_key(hDB, 0, str, &hKey);
667 if (status != DB_SUCCESS) {
668 cm_msg(MERROR,
"frontend_init",
"hv_fug_scfe: Couldn't find %s", str);
697 cm_get_experiment_database(&hDB, NULL);
700 strcpy(str,
"/Equipment/HV/Monitoring/FUG Monitoring");
701 status = db_find_key(hDB, 0, str, &hKey);
702 if (status != DB_SUCCESS) {
703 cm_msg(MERROR,
"frontend_exit",
"hv_fug_scfe: Couldn't find %s, status=%d", str, status);
706 db_close_record(hDB, hKey);
709 strcpy(str,
"/Equipment/HV/Monitoring/Trip Rate Source");
710 status = db_find_key(hDB, 0, str, &hKey);
711 if (status != DB_SUCCESS) {
712 cm_msg(MERROR,
"frontend_exit",
"hv_fug_scfe: Couldn't find %s, status=%d", str, status);
715 db_close_record(hDB, hKey);
718 strcpy(str,
"/Equipment/HV/Monitoring/Trip Enabled");
719 status = db_find_key(hDB, 0, str, &hKey);
720 if (status != DB_SUCCESS) {
721 cm_msg(MERROR,
"frontend_exit",
"hv_fug_scfe: Couldn't find %s, status=%d", str, status);
724 db_close_record(hDB, hKey);
727 strcpy(str,
"/Equipment/HV/Monitoring/Trip Level");
728 status = db_find_key(hDB, 0, str, &hKey);
729 if (status != DB_SUCCESS) {
730 cm_msg(MERROR,
"frontend_exit",
"hv_fug_scfe: Couldn't find %s, status=%d", str, status);
733 db_close_record(hDB, hKey);
737 strcpy(str,
"/Equipment/Scaler/Variables/RATE/TD");
738 status = db_find_key(hDB, 0, str, &hKey);
739 if (status != DB_SUCCESS) {
740 cm_msg(MERROR,
"frontend_exit",
"hv_fug_scfe: Couldn't find %s, status=%d", str, status);
743 db_close_record(hDB, hKey);
745 strcpy(str,
"/Equipment/Scaler/Variables/RATE/MCP1");
746 status = db_find_key(hDB, 0, str, &hKey);
747 if (status != DB_SUCCESS) {
748 cm_msg(MERROR,
"frontend_exit",
"hv_fug_scfe: Couldn't find %s, status=%d", str, status);
751 db_close_record(hDB, hKey);
755 strcpy(str,
"/Equipment/HV Detectors/Variables/Measured");
756 status = db_find_key(hDB, 0, str, &hKey);
757 if (status != DB_SUCCESS) {
758 cm_msg(MERROR,
"frontend_exit",
"hv_fug_scfe: Couldn't find %s, status=%d", str, status);
761 db_close_record(hDB, hKey);
768 strcpy(str,
"/Equipment/LEMVAC/Variables/Input");
769 status = db_find_key(hDB, 0, str, &hKey);
770 if (status != DB_SUCCESS) {
771 cm_msg(MERROR,
"frontend_exit",
"hv_fug_scfe: Couldn't find %s, status=%d", str, status);
774 db_close_record(hDB, hKey);
777 strcpy(str,
"/Equipment/HV/Variables/Demand");
778 status = db_find_key(hDB, 0, str, &hKey);
779 if (status != DB_SUCCESS) {
780 cm_msg(MERROR,
"frontend_exit",
"hv_fug_scfe: Couldn't find %s, status=%d", str, status);
783 db_close_record(hDB, hKey);
800 char name[NAME_LENGTH];
808 cm_msg(MINFO,
"frontend_loop",
"hv_fug_scfe: time to do something ...");
816 cm_msg(MINFO,
"frontend_loop",
"hv_fug_scfe: will read hv measured");
820 size =
sizeof(measured);
827 cm_msg(MINFO,
"frontend_loop",
"hv_fug_scfe: ch = %d, drop counter = %d", i,
hv_fug_drop_counter[i]);
831 strcpy(str,
"/Equipment/HV/Settings/Names");
834 db_get_data_index(
hv_fug_hDB, hKey, name, &size, i, TID_STRING);
835 sprintf(str,
"HV FUG %s: measured = %f, demand = %f, check!!",
837 al_trigger_alarm(
"hv_fug_scfe", str,
"Warning", str, AT_INTERNAL);
INT interrupt_configure(INT cmd, INT source, PTYPE adr)
DWORD hv_fug_demand_changed_timer
#define LEMVAC_MC_STATUS_WORD_2
char * frontend_name
experiment specific ODB structures
INT max_event_size_frag
maximum event size for fragmented events (EQ_FRAGMENTED)
#define FUG_BEAMLINE_KV61_CH
DWORD hv_fug_check_timestamp
void hv_fug_trip_rate_source_changed(INT hDB, INT hKey, void *dummy)
DEVICE_DRIVER hv_driver[]
device driver list
float hv_fug_demand[FUG_CHS]
void hv_fug_demand_changed(INT hDB, INT hKey, void *dummy)
void hv_fug_check_trip_level(INT, INT, void *)
INT end_of_run(INT run_number, char *error)
int hv_fug_chamber_flag[FUG_CHS]
INT hv_fug_hvAlreadyOff
HV already switched off.
INT hv_fug_tripRate
hotlink variable holding the TD trip rate
BOOL frontend_call_loop
frontend_loop is called periodically if this variable is TRUE
#define FUG_BEAMLINE_KV62_CH
INT max_event_size
maximum event size produced by this frontend
INT pause_run(INT run_number, char *error)
int hv_fug_drop_counter[FUG_CHS]
float * hv_detectors_measured
hotlink variable holding the measured TD HV's
const char * hv_fug_monitoring_str
char hv_fug_trip_rate_source[NAME_LENGTH]
hotlink variable holding the name of the detector which is to monitor the rate
INT event_buffer_size
buffer size to hold events
HNDLE hv_fug_measured_hKey
INT hv_fug_detector_rate
hotlink variable holding the TD or MCP1 rate
char * frontend_file_name
The frontend file name, don't change it.
INT poll_event(INT source, INT count, BOOL test)
float lemvac_in[27]
holds the lemvac input variables
#define LEMVAC_GAS_INLET_ON
INT hv_fug_tripEnabled
hotlink variable holding the trip enabled flag
INT hv_fug_monitoring_enabled
hotlink variable holding the monitoring enabled flag
void hv_fug_scfe_monitoring(INT hDB, INT hKey, void *hv)
INT begin_of_run(INT run_number, char *error)
#define FUG_DEMAND_CHANGED_TIMEOUT
#define LEMVAC_TC_STATUS_WORD_2
#define LEMVAC_SC_STATUS_WORD_2
INT display_period
a frontend status page is displayed with this frequency in ms
void hv_fug_scfe_gas_inlet(INT hDB, INT hKey, void *dummy)
INT resume_run(INT run_number, char *error)