20 #define LV_HV_NO_INTERLOCK_FLAG 128
21 #define LV_GAS_INLET_FLAG 128
24 #define LV_BIT0 0x0100
25 #define LV_BIT1 0x0200
26 #define LV_BIT2 0x0400
27 #define LV_BIT3 0x0800
28 #define LV_BIT4 0x1000
29 #define LV_BIT5 0x2000
30 #define LV_BIT6 0x4000
31 #define LV_BIT7 0x8000
32 #define LV_BIT8 0x0001
33 #define LV_BIT9 0x0002
34 #define LV_BIT10 0x0004
35 #define LV_BIT11 0x0008
36 #define LV_BIT12 0x0010
37 #define LV_BIT13 0x0020
38 #define LV_BIT14 0x0040
39 #define LV_BIT15 0x0080
71 #define LV_BPVX_ENABLED 0
73 #define LV_BPVY_ENABLED 2
75 #define LV_SC_PUMP_CMD_ENABLED 4
76 #define LV_SC_PUMP_CMD 5
77 #define LV_SC_VENT_CMD_ENABLED 6
78 #define LV_SC_VENT_CMD 7
81 #define LV_BPV_CMD_IDLE 0.0
82 #define LV_BPV_CMD_TOGGLE 1.0
83 #define LV_BPV_CMD_OPEN 2.0
84 #define LV_BPV_CMD_CLOSE 3.0
86 #define SPS_MAX_BYTES 680
87 #define LEMVAC_TIME_CONST 0
88 #define LEMVAC_TIMEOUT_ERROR 3600
91 #define LEMVAC_SC_PENDING_CMD_IDLE 0
92 #define LEMVAC_SC_PENDING_CMD_STOP 1
93 #define LEMVAC_SC_PENDING_CMD_VENT 2
95 #define VENT_STATE_HV_BIT 0
96 #define VENT_STATE_TEMP_BIT 1
97 #define VENT_STATE_BPVY_BIT 2
98 #define VENT_STATE_PUMP_BIT 3
100 #define VENT_CMD_STOP 0
101 #define VENT_CMD_START 1
104 #define FUG_SC_RAL_IDX 11
105 #define FUG_SC_RAR_IDX 12
106 #define FUG_SC_RAT_IDX 13
107 #define FUG_SC_RAB_IDX 14
108 #define FUG_SC_SAMPLE_IDX 15
111 #define SAMPLE_IN_CF1_IDX 0
112 #define SAMPLE_OUT_SET_POINT_IDX 1
113 #define SAMPLE_OUT_LS_RAMP 7
114 #define SAMPLE_OUT_BH1_FLOW_IDX 8
115 #define SAMPLE_OUT_BH2_FLOW_IDX 10
123 #define LAMVAC_INTERN_STR "\
124 Detailed Messages = INT : 0\n\
134 #define LEMVAC_NAMES_STR "\
135 Input Names = STRING[27] : \n\
139 [32] MC_GJ Penning\n\
140 [32] MC_GJ2 Penning\n\
143 [32] TC_GJ Penning\n\
144 [32] TC_GJ2 Penning\n\
147 [32] SC_GJ Penning\n\
148 [32] SC_GJ2 Penning\n\
150 [32] MC Status Word 1\n\
151 [32] MC Status Word 2\n\
152 [32] MC Status Word 3\n\
153 [32] TC Status Word 1\n\
154 [32] TC Status Word 2\n\
155 [32] TC Status Word 3\n\
156 [32] SC Status Word 1\n\
157 [32] SC Status Word 2\n\
158 [32] SC Status Word 3\n\
159 [32] PZ Status Word 1\n\
160 [32] PZ Status Word 2\n\
161 [32] BPVX Status Word\n\
162 [32] BPVY Status Word\n\
163 Output Names = STRING[8] : \n\
165 [32] BPVX toggle cmd\n\
167 [32] BPVY toggle cmd\n\
168 [32] SC pump cmd enabled\n\
170 [32] SC vent enabled\n\
180 INT (*bd)(INT cmd, ...);
185 char handshake_cmd[32];
186 int handshake_err_count[4];
242 cm_get_experiment_database(&hDB, NULL);
245 status = db_find_key(hDB, 0,
"/Equipment/HV/Variables/Demand", &hKey);
246 if (status != DB_SUCCESS) {
247 cm_msg(MERROR,
"lemvac_check_sample_hv",
"lemvac_check_sample_hv: lemvac_scfe: **ERROR** couldn't get FUG key from the ODB to check the sample HV.");
252 size =
sizeof(float);
255 db_get_data_index(hDB, hKey, &fval, &size, i, TID_FLOAT);
280 cm_get_experiment_database(&hDB, NULL);
283 status = db_find_key(hDB, 0,
"/Equipment/SampleCryo/Variables/Input", &hKey);
284 if (status != DB_SUCCESS) {
285 cm_msg(MERROR,
"lemvac_check_sample_temp",
"lemvac_check_sample_temp: lemvac_scfe: **ERROR** couldn't get SampleCryo key from the ODB to check the sample CF1 temp.");
289 size =
sizeof(float);
311 db_find_key(info->
hDB, 0,
"/Equipment/HV/Variables/Demand", &hKey);
313 cm_msg(MINFO,
"lemvac_shutdown_sc_hv",
"lemvac_shutdown_sc_hv: shut down sample chamber HVs.");
316 size =
sizeof(float);
319 db_set_data_index(info->
hDB, hKey, &fval, size, i, TID_FLOAT);
337 db_find_key(info->
hDB, 0,
"/Equipment/SampleCryo/Variables/Output", &hKey);
339 cm_msg(MINFO,
"lemvac_forced_warmup",
"lemvac_forced_warmup: initiate forced warmup of the sample cryo.");
342 size =
sizeof(float);
348 size =
sizeof(float);
398 if (buffer[0] & 0x80)
399 val = (buffer[0] &0x7f) << 8;
401 val = buffer[0] << 8;
403 if (buffer[1] & 0x80)
404 val += (buffer[1] &0x7f) + 128;
421 short val = buffer[0];
439 return exp(log(10.f)*(-11.f+0.8571*analog/100.f));
453 double volt[30] = {0.0, 0.1, 0.201, 0.4523, 0.7035, 0.9146, 1.1055,
454 2.0653, 2.5377, 2.9045, 3.2111, 3.4623, 4.1106,
455 4.6583, 5.0251, 5.3618, 5.5879, 6.1457, 6.6181,
456 7.0553, 7.3970, 7.6935, 8.6683, 9.2462, 9.4975,
457 9.6080, 9.7085, 9.8543, 9.9497, 10.0};
459 double p[30] = {1.0e-4, 1.0e-3, 0.002, 0.004, 0.006, 0.008, 0.01,
460 0.02, 0.04, 0.06, 0.08, 0.1, 0.2, 0.4, 0.6, 0.8,
461 1.0, 2.0, 4.0, 6.0, 8.0, 10.0, 20.0, 40.0, 60.0,
462 80.0, 100.0, 200.0, 400.0, 1000.0};
464 if (analog > 32512) {
468 double u = analog/100.f;
473 for (i=0; i<30; i++) {
481 pressure = p[i-1]+(p[i]-p[i-1])*(u-volt[i-1])/(volt[i]-volt[i-1]);
498 if ((buffer[4] != 65) || (buffer[5] != 66))
543 int status, cmd, cmd_tag;
549 status = sscanf(info->
handshake_cmd,
"%d;%d", &cmd, &cmd_tag);
551 cm_msg(MINFO,
"lemvac_deal_with_handshake",
"lemvac_deal_with_handshake: **ERROR** when tokenize handshake command ('%s').", info->
handshake_cmd);
567 cm_msg(MINFO,
"lemvac_deal_with_handshake",
"lemvac_deal_with_handshake: **WARNING** toggle BPVX failed.");
582 cm_msg(MINFO,
"lemvac_deal_with_handshake",
"lemvac_deal_with_handshake: **WARNING** toggle BPVY failed.");
588 if ((cmd_tag == 1) &&
602 cm_msg(MINFO,
"lemvac_deal_with_handshake",
"lemvac_deal_with_handshake: **WARNING** pump cmd failed.");
607 if ((cmd_tag == 1) && ((
int)info->
lemvac_buffer[416] != 0)) {
618 cm_msg(MINFO,
"lemvac_deal_with_handshake",
"lemvac_deal_with_handshake: **WARNING** pump/vent cmd failed.");
623 cm_msg(MINFO,
"lemvac_deal_with_handshake",
"lemvac_deal_with_handshake: **ERROR** you never should have reached this point.");
647 float delta = ss_time()-info->
time;
653 delta = ss_time()-info->
errTime;
657 cm_msg(MINFO,
"lemvac_get_all",
658 "lemvac_get_all: No of tcpip open errors = %d, tcpip read errors =%d of %d readings in the last %d secs.",
672 status = info->
bd(CMD_READ, info->
bd_info, &data[0],
sizeof(data), 3000);
674 cm_msg(MDEBUG,
"lemvac_get_all",
"lemvac_get_all: get data (status=%d)", status);
681 cm_msg(MINFO,
"lemvac_get_all",
"lemvac_get_all: get.data.status=%d", status);
704 info->
time = ss_time();
743 al_trigger_alarm(
"lemvac_get_all",
"MC High Voltage Interlock Activated",
"Alarm",
744 "Manual Reset Needed", AT_INTERNAL);
751 al_trigger_alarm(
"lemvac_get_all",
"TC High Voltage Interlock Activated",
"Alarm",
752 "Manual Reset Needed", AT_INTERNAL);
760 al_trigger_alarm(
"lemvac_get_all",
"SC High Voltage Interlock Activated",
"Alarm",
761 "Manual Reset Needed", AT_INTERNAL);
784 cm_msg(MDEBUG,
"lemvac_write_cmd",
"lemvac_write_cmd: write data (status=%d)", status);
801 int status, size, odb_idx;
811 status = db_find_key(info->
hDB, 0,
"/Equipment/LEMVAC/Variables/Output", &hKey);
812 if (status != DB_SUCCESS) {
813 cm_msg(MINFO,
"lemvac_set_sliding_valve",
"lemvac_set_sliding_valve: couldn't get the output variable key.");
820 }
else if (valve == 3) {
833 size =
sizeof(float);
839 status = db_set_data_index(info->
hDB, hKey, &fval, size, odb_idx, TID_FLOAT);
842 if ((open == TRUE) && (value == 2.0))
844 if ((open == FALSE) && (value == 3.0))
856 sprintf(cmd,
"%d;%d", valve, (
int)value);
873 cm_msg(MDEBUG,
"lemvac_start_sc_pump",
"lemvac_start_sc_pump: will start SC pump.");
879 cm_msg(MDEBUG,
"lemvac_start_sc_pump",
"lemvac_start_sc_pump: SC pump already running. Will do nothing.");
886 sprintf(cmd,
"%d;%d", 5, 1);
891 db_find_key(info->
hDB, 0,
"/Equipment/LEMVAC/Variables/Output", &hKey);
892 size =
sizeof(float);
914 cm_msg(MDEBUG,
"lemvac_stop_sc_pump",
"lemvac_stop_sc_pump: will stop SC pump.");
919 cm_msg(MDEBUG,
"lemvac_stop_sc_pump",
"lemvac_stop_sc_pump: SC pump already stopped. Will do nothing.");
926 sprintf(cmd,
"%d;%d", 5, 0);
932 db_find_key(info->
hDB, 0,
"/Equipment/LEMVAC/Variables/Output", &hKey);
933 size =
sizeof(float);
965 if (forced == TRUE) {
968 cm_msg(MINFO,
"lemvac_prepare_stop_sc_pump",
"lemvac_prepare_stop_sc_pump: CF1 T<90K, will stop the SC pump as soon as T>=90K. But you need to initiate it.");
999 if (forced == TRUE) {
1002 cm_msg(MINFO,
"lemvac_prepare_venting_sc",
"lemvac_prepare_venting_sc: CF1 T<90K, will start venting the SC as soon as T>=90K. But you need to initiate it.");
1029 sprintf(cmdStr,
"%d;%d", 7, cmd);
1036 sprintf(cmdStr,
"%d;%d", 7, cmd);
1039 cm_msg(MDEBUG,
"lemvac_vent_sc",
"lemvac_vent_sc: **ERROR** recived unkown vent command.");
1044 status = db_find_key(info->
hDB, 0,
"/Equipment/LEMVAC/Variables/Output", &hKey);
1045 if (status != DB_SUCCESS) {
1046 cm_msg(MERROR,
"lemvac_vent_sc",
"lemvac_vent_sc: **ERROR** couldn't get lemvac output variable key.");
1051 size =
sizeof(float);
1059 cm_msg(MINFO,
"lemvac_vent_sc",
"lemvac_vent_sc: sample chamber vented.");
1061 cm_msg(MINFO,
"lemvac_vent_sc",
"lemvac_vent_sc: stop venting the sample chamber.");
1084 INT status, size, i;
1093 cm_get_experiment_database(&hDB, NULL);
1099 status = db_find_key(hDB, hKey,
"DD/intern", &hkeydd);
1100 if (status != DB_SUCCESS) {
1103 if ((status != DB_SUCCESS) && (status != DB_OPEN_RECORD)) {
1104 cm_msg(MERROR,
"lemvac_init",
"lemvac_init: Error creating lemvac intern record in ODB, status=%d", status);
1109 db_find_key(hDB, hKey,
"DD/intern", &hkeydd);
1110 size =
sizeof(gInfo->
intern);
1111 status = db_get_record(hDB, hkeydd, &gInfo->
intern, &size, 0);
1113 status = db_open_record(hDB, hkeydd, &gInfo->
intern, size, MODE_READ, NULL, NULL);
1117 if ((status != DB_SUCCESS) && (status != DB_OPEN_RECORD)) {
1118 cm_msg(MERROR,
"lemvac_init",
"lemvac_init: Error creating lemvac Names record in ODB, status=%d", status);
1122 db_find_key(hDB, hKey,
"DD/Names", &hkeydd);
1124 db_get_record(hDB, hkeydd, &gInfo->
lemvac_names, &size, 0);
1128 status = db_find_key(hDB, hKey,
"DD/DB_Buffer", &hkeydd);
1129 if (status != DB_SUCCESS) {
1131 strcpy(str,
"DB_Buffer = BYTE[680] : \n");
1134 status = db_create_record(hDB, hKey,
"DD/DB_Buffer", str);
1135 if ((status != DB_SUCCESS) && (status != DB_OPEN_RECORD)) {
1136 cm_msg(MERROR,
"lemvac_init",
"lemvac_init: Error creating lemvac DB_Buffer record in ODB, status=%d", status);
1142 db_find_key(hDB, hKey,
"DD/DB_Buffer", &hkeydd);
1144 status = db_get_record(hDB, hkeydd, &gInfo->
lemvac_buffer, &size, 0);
1146 status = db_open_record(hDB, hkeydd, &gInfo->
lemvac_buffer, size, MODE_WRITE, NULL, NULL);
1159 gInfo->
time = ss_time();
1175 cm_msg(MDEBUG,
"lemvac_init",
"lemvac_init: open tcpip connection (status=%d)", status);
1178 if (status != SUCCESS) {
1181 cm_msg(MINFO,
"lemvac_init",
"lemvac_init: open bounced off");
1184 return FE_ERR_DRIVER;
1188 cm_msg(MINFO,
"lemvac_init",
"lemvac initialized ...");
1279 cm_msg(MERROR,
"lemvac_set",
"lemvac_set: **WARNING** pump cmd not enabled! Will do nothing!");
1284 }
else if (value == 1.0) {
1289 }
else if (value == 2.0) {
1291 }
else if (value == 3.0) {
1294 cm_msg(MERROR,
"lemvac_set",
"lemvac_set: **ERROR** found unsupported SC pump cmd %d. Will do nothing.", (
int)value);
1303 cm_msg(MERROR,
"lemvac_set",
"lemvac_set: **WARNING** vent cmd not enabled! Will do nothing!");
1308 }
else if (value == 1.0) {
1310 }
else if (value == 2.0) {
1312 }
else if (value == 3.0) {
1315 cm_msg(MERROR,
"lemvac_set",
"lemvac_set: **ERROR** found unsupported SC vent cmd %d. Will do nothing.", (
int)value);
1373 cm_msg(MDEBUG,
"lemvac_get",
"in lemvac_get ...");
1379 cm_msg(MDEBUG,
"lemvac_get",
"in lemvac_get and will call lemvac_get_all(info)");
1396 INT channel, status;
1402 va_start(argptr, cmd);
1403 status = FE_SUCCESS;
1407 hKey = va_arg(argptr, HNDLE);
1408 info = va_arg(argptr,
void *);
1409 channel = va_arg(argptr, INT);
1410 flags = va_arg(argptr, DWORD);
1411 bd = va_arg(argptr,
void *);
1416 info = va_arg(argptr,
void *);
1421 info = va_arg(argptr,
void *);
1422 channel = va_arg(argptr, INT);
1423 pvalue = va_arg(argptr,
float*);
1428 info = va_arg(argptr,
void *);
1429 channel = va_arg(argptr, INT);
1430 name = va_arg(argptr,
char *);
1448 INT channel, status;
1454 va_start(argptr, cmd);
1455 status = FE_SUCCESS;
1459 hKey = va_arg(argptr, HNDLE);
1460 info = va_arg(argptr,
void *);
1461 channel = va_arg(argptr, INT);
1462 flags = va_arg(argptr, DWORD);
1463 bd = va_arg(argptr,
void *);
1468 info = va_arg(argptr,
void *);
1469 channel = va_arg(argptr, INT);
1470 name = va_arg(argptr,
char *);
1475 info = va_arg(argptr,
void *);
1476 channel = va_arg(argptr, INT);
1477 value = (float) va_arg(argptr,
double);
INT(* bd)(INT cmd,...)
bus driver entry function for reading
int handshake_err_count[4]
handshake command error counters
INT read_error
how often there has been a read error
#define SAMPLE_IN_CF1_IDX
void lemvac_shutdown_sc_hv(LEMVAC_INFO *info)
void lemvac_forced_warmup(LEMVAC_INFO *info)
INT lemvac_out_get_label(LEMVAC_INFO *info, INT channel, char *name)
void lemvac_deal_with_handshake(LEMVAC_INFO *info)
void lemvac_write_cmd(LEMVAC_INFO *info)
INT lemvac_check_sample_temp()
void * bd_info
pointer to the BD info structure of the input channels
#define LEMVAC_NAMES_STR
Initializing string for the struct LEMVAC_NAMES.
INT lemvac_in_init(HNDLE hKey, void **pinfo, INT channels, INT(*bd)(INT cmd,...))
int sc_vent_cmd_enabled
holds enable flag for SC vent command
void lemvac_get_all(LEMVAC_INFO *info)
INT lemvac_in_get_label(LEMVAC_INFO *info, INT channel, char *name)
LEMVAC_NAMES lemvac_names
stores the internal DD settings
#define FUG_SC_SAMPLE_IDX
char out_name[LEMVAC_OUT_VARS][NAME_LENGTH]
Names of the output variable names as found in the ODB.
int bpv_enabled[2]
holds enable flag for BPVX and BPVY
double penning_ikr070(int analog)
float lemvac_data[LEMVAC_IN_VARS]
stores decoded values from SPS-DB
#define LV_SC_VENT_CMD_ENABLED
#define LEMVAC_TIMEOUT_ERROR
after what time (sec.) read errors should be reported
INT lemvac_get(LEMVAC_INFO *info, INT channel, float *pvalue)
void lemvac_vent_sc(LEMVAC_INFO *info, INT cmd)
Stores DD specific internal information.
#define SAMPLE_OUT_BH2_FLOW_IDX
void lemvac_start_sc_pump(LEMVAC_INFO *info)
INT lemvac_pending_sc_cmd
INT lemvac_set(LEMVAC_INFO *info, INT channel, float value)
HNDLE hKey_DB_Buffer
handle to the raw SPS-DB data
LEMVAC_INFO * gInfo
global info structure, in/out-init routines need the same structure
#define LV_SC_PUMP_CMD_ENABLED
#define LEMVAC_OUT_VARS
number of variables in the set list
#define VENT_STATE_HV_BIT
#define LEMVAC_TIME_CONST
trigger time constant for read out of the SPS
#define VENT_STATE_TEMP_BIT
INT lemvac_out(INT cmd,...)
HNDLE hKey_in
main device driver handle for input channels
int spsToWord(unsigned char *buffer)
double pirani_tpr018(int analog)
INT startup_error
tag if there has been an error at startup
int sc_pump_cmd_enabled
holds enable flag for SC pump command
#define VENT_STATE_PUMP_BIT
HNDLE hKey_out
main device driver handle for output channels
#define LV_GAS_INLET_FLAG
INT lemvac_check_sample_hv()
#define LEMVAC_SC_PENDING_CMD_VENT
#define SPS_MAX_BYTES
length of the data structure exchanged between SPS and midas
void lemvac_stop_sc_pump(LEMVAC_INFO *info)
void lemvac_check_pending_cmd(LEMVAC_INFO *info)
#define VENT_STATE_BPVY_BIT
char in_name[LEMVAC_IN_VARS][NAME_LENGTH]
Names of the input variable names as found in the ODB.
#define SAMPLE_OUT_BH1_FLOW_IDX
INT detailed_msg
flag indicating if detailed status/error messages are wanted
This structure contains private variables for the device driver.
short spsToNumber(unsigned char *buffer)
INT read_counts
total no of tcpip reading attempts
float lemvac_in[27]
holds the lemvac input variables
void lemvac_prepare_venting_sc(LEMVAC_INFO *info, BOOL forced)
BOOL lemvac_decode_data(LEMVAC_INFO *info, const char *buffer)
void lemvac_prepare_stop_sc_pump(LEMVAC_INFO *info, BOOL forced)
#define LEMVAC_SC_PENDING_CMD_STOP
#define LEMVAC_IN_VARS
number of variables in the get list
#define SAMPLE_OUT_LS_RAMP
void lemvac_set_sliding_valve(LEMVAC_INFO *info, INT valve, float value)
#define LV_HV_NO_INTERLOCK_FLAG
char handshake_cmd[32]
handshake command
LEMVAC_INTERN intern
stores DD specific internal settings
DWORD errTime
timer for error handling concerning tcpip communication
INT lemvac_out_init(HNDLE hKey, void **pinfo, INT channels, INT(*bd)(INT cmd,...))
#define LAMVAC_INTERN_STR
Initializing string for the struct LEMVAC_INTERN.
DWORD last_success
timer of last read success
INT tcpip_open_error
how often the attempt to open the tcpip communication failed
#define SAMPLE_OUT_SET_POINT_IDX
char lemvac_buffer[SPS_MAX_BYTES]
SPS-DB byte buffer.
#define LEMVAC_SC_PENDING_CMD_IDLE
INT lemvac_exit(LEMVAC_INFO *info)
Stores the names of the various channels which are than transferred form the DD to the variable names...