27 #include "lemSCWatchdog.h"
31 #define LS340_SHUTDOWN -999
33 #define LS340_MAX_SENSORS 10
34 #define LS340_DELTA_R 2.0
35 #define LS340_TIME_OUT 2000
38 #define LS340_MAX_ERROR 3
39 #define LS340_DELTA_TIME_ERROR 3600
40 #define LS340_MAX_TRY_MANY 10
41 #define LS340_MAX_TRY_LESS 3
43 #define LS340_WAIT 500
45 #define LS340_INIT_ERROR -2
46 #define LS340_READ_ERROR -1
48 #define LS340_MAX_AVG 100
55 #define LS340_MAX_READBACK_FAILURE 5
56 #define LS340_MAX_RECONNECTION_FAILURE 5
59 #define LS340_ETS_LOGOUT_SLEEP 10000
81 #define LS340_SENSORS_STR "\
82 Date and Time = STRING : [32] \n\
83 Sensor Type = INT[10]: \n\
94 Calibration Curve = INT[10]: \n\
105 Channel = STRING[10]: \n\
116 Sensor Name = STRING[10]: \n\
127 Raw Input Ch 1 = FLOAT : 0.0\n\
128 Raw Input Ch 2 = FLOAT : 0.0\n\
129 Raw Input Ch 3 = FLOAT : 0.0\n\
130 Raw Input Ch 4 = FLOAT : 0.0\n\
131 Raw Input Ch 5 = FLOAT : 0.0\n\
132 Raw Input Ch 6 = FLOAT : 0.0\n\
133 Raw Input Ch 7 = FLOAT : 0.0\n\
134 Raw Input Ch 8 = FLOAT : 0.0\n\
135 Raw Input Ch 9 = FLOAT : 0.0\n\
136 Raw Input Ch 10 = FLOAT : 0.0\n\
151 #define LS340_LOOP1_STR "\
152 CTRL_CH = STRING : [4] A\n\
153 SetPoint Limit = FLOAT : 350.f\n\
154 Max. Current Tag = INT : 4\n\
155 Max. User Current = FLOAT : 0.85\n\
156 Max. Heater Range = INT : 5\n\
157 Heater Resistance = FLOAT : 25.0\n\
171 char odb_output[2*NAME_LENGTH];
177 #define LS340_INTERNAL_STR "\
178 Detailed Messages = INT : 0\n\
179 ETS_IN_USE = INT : 1\n\
180 SCW_IN_USE = INT : 0\n\
181 No Connection = INT : 1\n\
182 Reconnection Timeout = INT : 10\n\
183 Read Timeout = INT : 5\n\
184 Read Raw Data = BOOL : FALSE\n\
185 ODB Offset = INT : 0\n\
186 ODB Output Path = STRING : [64] /Equipment/LS340 Moddy/Variables/Output\n\
188 # Sensors = INT : 7\n\
198 #define LS340_ZONE_STR "\
199 Zone = STRING[10]: \n\
200 [32] 1, 1, 7, 500, 300, 0, 0, 3\n\
201 [32] 1, 2, 10, 500, 200, 2, 0, 4\n\
202 [32] 1, 3, 15, 500, 100, 2, 0, 4\n\
203 [32] 1, 4, 20, 500, 50, 2, 0, 4\n\
204 [32] 1, 5, 30, 500, 20, 2, 0, 4\n\
205 [32] 1, 6, 320, 500, 20, 2, 0, 5\n\
206 [32] 1, 7, 320, 500, 20, 2, 0, 5\n\
207 [32] 1, 8, 320, 500, 20, 2, 0, 5\n\
208 [32] 1, 9, 320, 500, 20, 2, 0, 5\n\
209 [32] 1, 10, 320, 500, 20, 2, 0, 5\n\
219 char zone[10*NAME_LENGTH];
226 char ls_name[NAME_LENGTH];
227 char names_in[8][NAME_LENGTH];
228 char names_out[8][NAME_LENGTH];
232 #define LS340_ODB_NAMES_STR "\
233 LakeShore 340 Name = STRING : [32] Moderator\n\
234 Names In = STRING[8] : \n\
236 [32] LS_SetPoint (read back)\n\
237 [32] LS_Gain P (read back)\n\
238 [32] LS_Reset I (read back)\n\
239 [32] LS_Rate D (read back)\n\
240 [32] LS_HeaterRange (read back)\n\
241 [32] LS_ControlMode (read back)\n\
242 [32] LS_Ramp (read back)\n\
243 Names Out = STRING[8] : \n\
244 [32] LS_Remote (1/0)\n\
245 [32] LS_SetPoint (K)\n\
249 [32] LS_HeaterRange\n\
250 [32] LS_ControlMode\n\
255 #define LS340_SCW_STR "\
256 Proc Name = STRING : [32]\n\
258 Log Name = STRING : [64]\n\
259 DD Name = STRING : [32]\n\
260 Last Updated = DWORD : 0\n\
261 Timeout = DWORD : 180\n\
272 char cryo_name[NAME_LENGTH];
277 HNDLE hkey_raw_value[10];
280 INT (*bd)(INT cmd, ...);
282 DWORD read_timer[20];
286 DWORD last_value[15];
317 INT status, status_yield, i;
329 cm_msg(MINFO,
"ls340_send_rcv",
"LS340: %s: trial %d, status = %d, str = %s",
334 status_yield = cm_yield(10);
335 if ((status_yield == RPC_SHUTDOWN) || (status_yield == SS_ABORT)) {
336 cm_msg(MINFO,
"ls340_send_rcv",
"ls340_send_rcv: status of cm_yield = %d", status_yield);
342 }
while ((status<=0) && (i < max_try));
364 if (ch < info->ls340_settings.intern.no_of_sensors) {
377 (ch <= info->ls340_settings.intern.no_of_sensors+4)) {
429 char cmd[128], qry[128], rcv[128];
432 cm_get_experiment_database(&hDB, NULL);
436 if (status != FE_SUCCESS) {
437 cm_msg(MERROR,
"ls340_force_update",
"ls340_force_update: %s. Couldn't get the Output key.",
442 size =
sizeof(float);
446 sprintf(cmd,
"SETP 1, %05.2f\r\n", value[0]);
448 sprintf(qry,
"SETP? 1\r\n");
452 cm_msg(MERROR,
"ls340_force_update",
"ls340_force_update: %s: Failed to query %s",
455 cm_msg(MINFO,
"ls340_force_update",
"ls340_force_update: %s: Result of query %s = %s",
460 control_mode = (int) value[0];
461 sprintf(cmd,
"CMODE 1, %d\r\n", (
int)value[0]);
462 sprintf(qry,
"CMODE? 1\r\n");
466 cm_msg(MERROR,
"ls340_force_update",
"ls340_force_update: %s: Failed to query %s",
469 cm_msg(MINFO,
"ls340_force_update",
"ls340_force_update: %s: Result of query %s = %s",
473 if (control_mode != 2) {
477 sprintf(cmd,
"PID 1, %d, %d, %d\r\n", (
int)value[0], (
int)value[1], (
int)value[2]);
478 sprintf(qry,
"PID? 1\r\n");
482 cm_msg(MERROR,
"ls340_force_update",
"ls340_force_update: %s: Failed to query %s",
485 cm_msg(MINFO,
"ls340_force_update",
"ls340_force_update: %s: Result of query %s = %s",
490 sprintf(cmd,
"RANGE %d\r\n", (
int)value[0]);
491 sprintf(qry,
"RANGE?\r\n");
495 cm_msg(MERROR,
"ls340_force_update",
"ls340_force_update: %s: Failed to query %s",
498 cm_msg(MINFO,
"ls340_force_update",
"ls340_force_update: %s: Result of query %s = %s",
508 sprintf(cmd,
"RAMP 1, %d, %d\r\n", (
int)value[1], (
int)value[0]);
509 sprintf(qry,
"RAMP? 1\r\n");
513 cm_msg(MERROR,
"ls340_force_update",
"ls340_force_update: %s: Failed to query %s",
516 cm_msg(MINFO,
"ls340_force_update",
"ls340_force_update: %s: Result of query %s = %s",
578 int i, ch_no, value[4];
581 float heater_resistance;
582 int sensor_type[10], calib_curve[10];
583 char str[128], cmd[128];
584 char sensor_name[10*NAME_LENGTH], channel[10*NAME_LENGTH], zone[10*NAME_LENGTH];
585 char ch[NAME_LENGTH+1];
586 HNDLE
hKey, hWorkKey, hSubKey;
587 INT loop, zone_no, range, zone_diff=0;;
588 float top_temp, pid_p, pid_i, pid_d, man_out;
589 float zone_dd[6], zone_ls340[6];
593 if (strstr(info->
cryo_name,
"no cryostat"))
598 cm_msg(MINFO,
"ls340_cryo_name_changed",
"cryo name = %s", info->
cryo_name);
601 sprintf(str,
"DD/Cryos/%s", info->
cryo_name);
602 status = db_find_key(info->
hDB, info->
hkey, str, &hKey);
603 if (status != DB_SUCCESS) {
604 cm_msg(MINFO,
"ls340_cryo_name_changed",
"couldn't find ../%s in the ODB", str);
611 status = db_find_key(info->
hDB, hKey,
"Heater Resistance", &hSubKey);
612 if (status != DB_SUCCESS) {
613 cm_msg(MINFO,
"ls340_cryo_name_changed",
"couldn't find 'Heater Resistance' key!");
618 size =
sizeof(float);
619 status = db_get_data(info->
hDB, hSubKey, (
void*)&heater_resistance, &size, TID_FLOAT);
622 status = db_find_key(info->
hDB, info->
hkey,
"DD/Loop1/Heater Resistance", &hWorkKey);
623 if (status != DB_SUCCESS) {
624 cm_msg(MINFO,
"ls340_cryo_name_changed",
"couldn't find 'DD/Loop1/Heater Resistance' key!");
627 db_set_data(info->
hDB, hWorkKey, (
void *)&heater_resistance,
sizeof(
float), 1, TID_FLOAT);
632 status = db_find_key(info->
hDB, hKey,
"Max. Current Tag", &hSubKey);
633 if (status != DB_SUCCESS) {
634 cm_msg(MINFO,
"ls340_cryo_name_changed",
"couldn't find 'Max. Current Tag' key!");
639 size =
sizeof(float);
640 status = db_get_data(info->
hDB, hSubKey, (
void*)&value[0], &size, TID_INT);
643 status = db_find_key(info->
hDB, info->
hkey,
"DD/Loop1/Max. Current Tag", &hWorkKey);
644 if (status != DB_SUCCESS) {
645 cm_msg(MINFO,
"ls340_cryo_name_changed",
"couldn't find 'DD/Loop1/Max. Current Tag' key!");
648 db_set_data(info->
hDB, hWorkKey, (
void *)&value[0],
sizeof(
int), 1, TID_INT);
653 status = db_find_key(info->
hDB, hKey,
"Max. User Current", &hSubKey);
654 if (status != DB_SUCCESS) {
655 cm_msg(MINFO,
"ls340_cryo_name_changed",
"couldn't find 'Max. User Current' key!");
660 size =
sizeof(float);
661 status = db_get_data(info->
hDB, hSubKey, (
void*)&fvalue, &size, TID_FLOAT);
664 status = db_find_key(info->
hDB, info->
hkey,
"DD/Loop1/Max. User Current", &hWorkKey);
665 if (status != DB_SUCCESS) {
666 cm_msg(MINFO,
"ls340_cryo_name_changed",
"couldn't find 'DD/Loop1/Max. User Current' key!");
669 db_set_data(info->
hDB, hWorkKey, (
void *)&fvalue,
sizeof(
float), 1, TID_FLOAT);
674 status = db_find_key(info->
hDB, hKey,
"Max. Heater Range", &hSubKey);
675 if (status != DB_SUCCESS) {
676 cm_msg(MINFO,
"ls340_cryo_name_changed",
"couldn't find 'Max. Heater Range' key!");
681 size =
sizeof(float);
682 status = db_get_data(info->
hDB, hSubKey, (
void*)&value[0], &size, TID_INT);
685 status = db_find_key(info->
hDB, info->
hkey,
"DD/Loop1/Max. Heater Range", &hWorkKey);
686 if (status != DB_SUCCESS) {
687 cm_msg(MINFO,
"ls340_cryo_name_changed",
"couldn't find 'DD/Loop1/Max. Heater Range' key!");
690 db_set_data(info->
hDB, hWorkKey, (
void *)&value[0],
sizeof(
int), 1, TID_INT);
695 status = db_find_key(info->
hDB, hKey,
"Sensor Type", &hSubKey);
696 if (status != DB_SUCCESS) {
697 cm_msg(MINFO,
"ls340_cryo_name_changed",
"couldn't find 'Sensor Type' key!");
702 size =
sizeof(sensor_type);
703 status = db_get_data(info->
hDB, hSubKey, (
void*)&sensor_type, &size, TID_INT);
706 status = db_find_key(info->
hDB, info->
hkey,
"DD/Sensors/Sensor Type", &hWorkKey);
707 if (status != DB_SUCCESS) {
708 cm_msg(MINFO,
"ls340_cryo_name_changed",
"couldn't find 'DD/Sensors/Sensor Type' key!");
711 db_set_data(info->
hDB, hWorkKey, (
void *)&sensor_type,
sizeof(sensor_type), 10, TID_INT);
717 status = db_find_key(info->
hDB, hKey,
"Calibration Curve", &hSubKey);
718 if (status != DB_SUCCESS) {
719 cm_msg(MINFO,
"ls340_cryo_name_changed",
"couldn't find 'Calibration Curve' key!");
724 size =
sizeof(calib_curve);
725 status = db_get_data(info->
hDB, hSubKey, (
void*)&calib_curve, &size, TID_INT);
728 status = db_find_key(info->
hDB, info->
hkey,
"DD/Sensors/Calibration Curve", &hWorkKey);
729 if (status != DB_SUCCESS) {
730 cm_msg(MINFO,
"ls340_cryo_name_changed",
"couldn't find 'DD/Sensors/Calibration Curve' key!");
733 db_set_data(info->
hDB, hWorkKey, (
void *)&calib_curve,
sizeof(calib_curve), 10, TID_INT);
738 status = db_find_key(info->
hDB, hKey,
"Channel", &hSubKey);
739 if (status != DB_SUCCESS) {
740 cm_msg(MINFO,
"ls340_cryo_name_changed",
"couldn't find 'Channel' key!");
745 size =
sizeof(channel);
746 status = db_get_data(info->
hDB, hSubKey, (
void*)&channel, &size, TID_STRING);
749 status = db_find_key(info->
hDB, info->
hkey,
"DD/Sensors/Channel", &hWorkKey);
750 if (status != DB_SUCCESS) {
751 cm_msg(MINFO,
"ls340_cryo_name_changed",
"couldn't find 'DD/Sensors/Channel' key!");
754 for (i=0; i<10; i++) {
755 memset(ch, 0,
sizeof(ch));
756 memcpy(ch, &channel[i*NAME_LENGTH], NAME_LENGTH*
sizeof(
char));
757 db_set_data_index(info->
hDB, hWorkKey, (
void *)&ch, 4*
sizeof(
char), i, TID_STRING);
763 status = db_find_key(info->
hDB, hKey,
"Sensor Name", &hSubKey);
764 if (status != DB_SUCCESS) {
765 cm_msg(MINFO,
"ls340_cryo_name_changed",
"couldn't find 'Sensor Name' key!");
770 size =
sizeof(sensor_name);
771 status = db_get_data(info->
hDB, hSubKey, (
void*)&sensor_name, &size, TID_STRING);
774 status = db_find_key(info->
hDB, info->
hkey,
"DD/Sensors/Sensor Name", &hWorkKey);
775 if (status != DB_SUCCESS) {
776 cm_msg(MINFO,
"ls340_cryo_name_changed",
"couldn't find 'DD/Sensors/Sensor Name' key!");
779 for (i=0; i<10; i++) {
780 memset(ch, 0,
sizeof(ch));
781 memcpy(ch, &sensor_name[i*NAME_LENGTH], NAME_LENGTH*
sizeof(
char));
782 db_set_data_index(info->
hDB, hWorkKey, (
void *)&ch, NAME_LENGTH*
sizeof(
char), i, TID_STRING);
786 status = db_find_key(info->
hDB, info->
hkey,
"../../Names Input", &hWorkKey);
787 if (status != DB_SUCCESS) {
788 cm_msg(MINFO,
"ls340_cryo_name_changed",
"couldn't find 'Settings/Names Input' key!");
792 memset(ch, 0,
sizeof(ch));
793 memcpy(ch, &sensor_name[i*NAME_LENGTH], NAME_LENGTH*
sizeof(
char));
794 db_set_data_index(info->
hDB, hWorkKey, (
void *)&ch, NAME_LENGTH*
sizeof(
char),
802 status = db_find_key(info->
hDB, hKey,
"Zone", &hSubKey);
803 if (status != DB_SUCCESS) {
804 cm_msg(MINFO,
"ls340_cryo_name_changed",
"couldn't find 'Zone' key!");
810 status = db_get_data(info->
hDB, hSubKey, (
void*)&zone, &size, TID_STRING);
813 status = db_find_key(info->
hDB, info->
hkey,
"DD/Zone/Zone", &hWorkKey);
814 if (status != DB_SUCCESS) {
815 cm_msg(MINFO,
"ls340_cryo_name_changed",
"couldn't find 'DD/Zone/Zone' key!");
818 for (i=0; i<10; i++) {
819 memset(ch, 0,
sizeof(ch));
820 memcpy(ch, &zone[i*NAME_LENGTH], NAME_LENGTH*
sizeof(
char));
821 db_set_data_index(info->
hDB, hWorkKey, (
void *)&ch, NAME_LENGTH*
sizeof(
char), i, TID_STRING);
829 memset(ch, 0,
sizeof(ch));
830 memcpy(ch, &channel[i*NAME_LENGTH], NAME_LENGTH*
sizeof(
char));
831 sprintf(cmd,
"INTYPE %s, %d\r\n", ch, sensor_type[i]);
833 sprintf(cmd,
"INTYPE? %s\r\n", ch);
836 cm_msg(MERROR,
"ls340_cryo_name_changed",
"LS340: %s: Error getting channel %s type assignment.",
842 sprintf(cmd,
"INCRV %s, %d\r\n", ch, calib_curve[i]);
844 sprintf(cmd,
"INCRV? %s\r\n", ch);
847 cm_msg(MERROR,
"ls340_cryo_name_changed",
"LS340: %s: Error getting channel %s curve assignment.",
853 sscanf(str,
"%d", &ch_no);
854 sprintf(cmd,
"CRVHDR? %d\r\n", ch_no);
857 cm_msg(MERROR,
"ls340_cryo_name_changed",
"LS340: %s: Error getting channel %s curve header.",
863 cm_msg(MINFO,
"ls340_cryo_name_changed",
864 "LS340: %s: Channel %s curve = (ODB=%d,LS340=%d).\n LS340=%d -> %s",
869 sprintf(cmd,
"CDISP 1,1,%d\r\n", (
int)truncf(heater_resistance));
870 cm_msg(MINFO,
"ls340_cryo_name_changed",
"LS340: %s: going to set the heater resistance to %d(Ohm)",
874 sprintf(cmd,
"CDISP? 1\r\n");
877 cm_msg(MERROR,
"ls340_cryo_name_changed",
"LS340: %s: Failed reading the heater resistance settings of loop1.",
881 sscanf(str,
"%d,%d,%d,%d", &value[0], &value[1], &value[2], &value[3]);
882 fvalue = (float)value[1];
884 cm_msg(MERROR,
"ls340_cryo_name_changed",
885 "LS340: %s: Controll loop1 heater resistance: ODB entry %2.0f(Ohm) is inconsistent with readback value %2.0f(Ohm)",
889 sprintf(cmd,
"CSET 1, , 1, 1\r\n");
891 sprintf(cmd,
"CSET? 1\r\n");
894 cm_msg(MERROR,
"ls340_cryo_name_changed",
895 "LS340: %s: Error in configuring control loop parameter.",
899 cm_msg(MINFO,
"ls340_cryo_name_changed",
900 "LS340: %s: Controll loop1 settings: %s",
907 sprintf(cmd,
"CLIMIT? 1\r\n");
910 cm_msg(MERROR,
"ls340_cryo_name_changed",
"LS340: %s: Error in configuring control loop limit parameter.",
913 cm_msg(MINFO,
"ls340_cryo_name_changed",
"LS340: %s: Control loop1 limits: %s", info->
ls340_odb_names.
ls_name, str);
920 sprintf(cmd,
"CLIMI?\r\n");
923 cm_msg(MERROR,
"LS340_in_init",
"LS340: %s: Error in configuring control loop max. user current.",
926 cm_msg(MINFO,
"ls340_cryo_name_changed",
"LS340: %s: Control max. user current: %s (A)", info->
ls340_odb_names.
ls_name, str);
931 for (i=0; i<10; i++) {
932 memset(str, 0,
sizeof(str));
933 memcpy(str, &zone[i*NAME_LENGTH], NAME_LENGTH*
sizeof(
char));
934 status = sscanf(str,
"%d, %d, %f, %f, %f, %f, %f, %d",
935 &loop, &zone_no, &top_temp, &pid_p, &pid_i, &pid_d, &man_out, &range);
937 cm_msg(MINFO,
"ls340_cryo_name_changed",
"%s. Couldn't get the zone settings from the DD.",
940 sprintf(cmd,
"ZONE %d, %d, %0.1f, %0.1f, %0.1f, %0.1f, %0.1f, %d\r\n",
941 loop, zone_no, top_temp, pid_p, pid_i, pid_d, man_out, range);
947 for (i=0; i<10; i++) {
948 sprintf(cmd,
"ZONE? 1, %d\r\n", i+1);
951 memset(cmd, 0,
sizeof(cmd));
952 memcpy(cmd, &zone[i*NAME_LENGTH], NAME_LENGTH*
sizeof(
char));
953 sscanf(cmd,
"%d, %d, %f, %f, %f, %f, %f, %d",
954 &loop, &zone_no, &top_temp, &pid_p, &pid_i, &pid_d, &man_out, &range);
955 zone_dd[0] = top_temp;
959 zone_dd[4] = man_out;
962 sscanf(str,
"%f, %f, %f, %f, %f, %d",
963 &top_temp, &pid_p, &pid_i, &pid_d, &man_out, &range);
964 zone_ls340[0] = top_temp;
965 zone_ls340[1] = pid_p;
966 zone_ls340[2] = pid_i;
967 zone_ls340[3] = pid_d;
968 zone_ls340[4] = man_out;
969 zone_ls340[5] = range;
971 if ((zone_dd[0] != zone_ls340[0]) || (zone_dd[1] != zone_ls340[1]) || (zone_dd[2] != zone_ls340[2]) ||
972 (zone_dd[3] != zone_ls340[3]) || (zone_dd[4] != zone_ls340[4]) || (zone_dd[5] != zone_ls340[5])) {
973 cm_msg(MINFO,
"ls340_cryo_name_changed",
974 "%s. Zone settings from the DD and from the LS340 are different.",
980 cm_msg(MINFO,
"ls340_cryo_name_changed",
981 "%s. Zone settings successfully transferred to the LS340.",
984 cm_msg(MINFO,
"ls340_cryo_name_changed",
"successfully switched to %s",
1002 INT status, size, i, ch, value[4];
1003 INT loop, zone, range, zone_diff=0;;
1004 float top_temp, pid_p, pid_i, pid_d, man_out;
1005 float zone_dd[6], zone_ls340[6];
1007 char str[128], cmd[128];
1012 cm_get_experiment_database(&hDB, NULL);
1020 if ((status != DB_SUCCESS) && (status != DB_OPEN_RECORD)) {
1021 cm_msg(MERROR,
"ls340_in_init",
"ls340_in_init: Couldn't create DD/ODB Names in ODB: status=%d", status);
1028 if ((status != DB_SUCCESS) && (status != DB_OPEN_RECORD)) {
1029 cm_msg(MERROR,
"ls340_in_init",
"ls340_in_init: Couldn't create DD/Internal in ODB: status=%d", status);
1036 if ((status != DB_SUCCESS) && (status != DB_OPEN_RECORD)) {
1037 cm_msg(MERROR,
"ls340_in_init",
"ls340_in_init: Couldn't create DD/Sensors in ODB: status=%d", status);
1044 if ((status != DB_SUCCESS) && (status != DB_OPEN_RECORD)) {
1045 cm_msg(MERROR,
"ls340_in_init",
"ls340_in_init: Couldn't create DD/Loop1 in ODB: status=%d", status);
1051 if ((status != DB_SUCCESS) && (status != DB_OPEN_RECORD)) {
1052 cm_msg(MERROR,
"ls340_in_init",
"ls340_in_init: Couldn't create DD/Zone in ODB: status=%d", status);
1058 status = db_create_record(hDB, hKey,
"DD/SCW",
LS340_SCW_STR);
1059 if ((status != DB_SUCCESS) && (status != DB_OPEN_RECORD)) {
1060 cm_msg(MERROR,
"ls340_in_init",
"ls340_in_init: Couldn't create DD/SCW in ODB: status=%d", status);
1066 db_find_key(hDB, hKey,
"DD/ODB Names/LakeShore 340 Name", &hkeydd);
1067 db_open_record(hDB, hkeydd, (
void *)&info->
cryo_name,
sizeof(info->
cryo_name), MODE_READ,
1069 db_find_key(hDB, hKey,
"DD/ODB Names", &hkeydd);
1071 MODE_READ, NULL, NULL);
1072 db_find_key(hDB, hKey,
"DD/Internal", &hkeydd);
1074 MODE_READ, NULL, NULL);
1075 db_find_key(hDB, hKey,
"DD/Sensors", &hkeydd);
1077 MODE_READ, NULL, NULL);
1078 db_find_key(hDB, hKey,
"DD/Loop1", &hkeydd);
1080 MODE_READ, NULL, NULL);
1081 db_find_key(hDB, hKey,
"DD/Zone", &hkeydd);
1083 MODE_READ, NULL, NULL);
1084 db_find_key(hDB, hKey,
"DD/SCW", &hkeydd);
1085 db_open_record(hDB, hkeydd, (
void *)&info->
scw,
sizeof(info->
scw),
1086 MODE_READ, NULL, NULL);
1094 for (i=1; i<18; i++)
1115 cm_msg(MINFO,
"LS340_in_init",
"LS340_in_init: ctrl loop channel %s is not allowed, will set it to A. Only channels A/B/C1-C4/D1-D4 are possible.", info->
ls340_settings.
loop1.
ctrl_ch);
1126 status = db_find_key(hDB, hKey,
"DD/Sensors/Date and Time", &info->
hkey_datetime);
1128 status = db_find_key(hDB, hKey,
"DD/Internal/No Connection", &info->
hkey_no_connection);
1131 sprintf(str,
"DD/Sensors/Raw Input Ch %d", i+1);
1139 status = info->
bd(CMD_INIT, hKey, &info->
bd_info);
1140 if (status != FE_SUCCESS) {
1149 strcpy(cmd,
"*IDN?\r\n");
1152 cm_msg(MERROR,
"LS340_in_init",
"Error getting device query from LS340, %s",info->
ls340_odb_names.
ls_name);
1156 cm_msg(MINFO,
"LS340_in_init",
"Device query of LS340 yields %s = %s", info->
ls340_odb_names.
ls_name,str);
1161 tm = *localtime(&tt);
1162 sprintf(cmd,
"DATETIME %d, %d, %d, %d, %d, %d, %d", tm.tm_mon+1, tm.tm_mday, tm.tm_year+1900, tm.tm_hour, tm.tm_min, tm.tm_sec, 0);
1163 cm_msg(MDEBUG,
"ls340_in_init",
"ls340_in_init: set date and time to %s", cmd);
1176 cm_msg(MERROR,
"LS340_in_init",
"LS340: %s: Error getting channel %s type assignment.",
1189 cm_msg(MERROR,
"LS340_in_init",
"LS340: %s: Error getting channel %s curve assignment.",
1197 sscanf(str,
"%d", &ch);
1198 sprintf(cmd,
"CRVHDR? %d\r\n", ch);
1201 cm_msg(MERROR,
"LS340_in_init",
"LS340: %s: Error getting channel %s curve header.",
1209 cm_msg(MINFO,
"LS340_in_init",
"LS340: %s: Channel %s curve = (ODB=%d,LS340=%d).\n LS340=%d -> %s",
1219 sprintf(cmd,
"CSET? 1\r\n");
1222 cm_msg(MERROR,
"LS340_in_init",
"LS340: %s: Error in configuring control loop parameter.",
1228 cm_msg(MINFO,
"LS340_in_init",
"LS340: %s: Control loop1 settings: %s", info->
ls340_odb_names.
ls_name, str);
1235 sprintf(cmd,
"CLIMIT? 1\r\n");
1238 cm_msg(MERROR,
"LS340_in_init",
"LS340: %s: Error in configuring control loop limit parameter.",
1243 cm_msg(MINFO,
"LS340_in_init",
"LS340: %s: Control loop1 limits: %s", info->
ls340_odb_names.
ls_name, str);
1251 sprintf(cmd,
"CLIMI?\r\n");
1254 cm_msg(MERROR,
"LS340_in_init",
"LS340: %s: Error in configuring control loop max. user current.",
1259 cm_msg(MINFO,
"LS340_in_init",
"LS340: %s: Control max. user current: %s (A)", info->
ls340_odb_names.
ls_name, str);
1265 sprintf(cmd,
"CDISP? 1\r\n");
1268 cm_msg(MERROR,
"LS340_in_init",
"LS340: %s: Reading the heater resistance settings of loop1.",
1274 sscanf(str,
"%d,%d,%d,%d", &value[0], &value[1], &value[2], &value[3]);
1275 fvalue = (float)value[1];
1277 cm_msg(MERROR,
"LS340_in_init",
1278 "LS340: %s: Controll loop1 heater resistance: ODB entry %2.0f(Ohm) is inconsistent with readback value %2.0f(Ohm)",
1284 for (i=0; i<10; i++) {
1285 memset(str, 0,
sizeof(str));
1287 status = sscanf(str,
"%d, %d, %f, %f, %f, %f, %f, %d",
1288 &loop, &zone, &top_temp, &pid_p, &pid_i, &pid_d, &man_out, &range);
1290 cm_msg(MINFO,
"LS340_in_init",
"%s. Couldn't get the zone settings from the DD.",
1294 sprintf(cmd,
"ZONE %d, %d, %0.1f, %0.1f, %0.1f, %0.1f, %0.1f, %d\r\n",
1295 loop, zone, top_temp, pid_p, pid_i, pid_d, man_out, range);
1301 for (i=0; i<10; i++) {
1302 sprintf(cmd,
"ZONE? 1, %d\r\n", i+1);
1305 memset(cmd, 0,
sizeof(str));
1307 sscanf(cmd,
"%d, %d, %f, %f, %f, %f, %f, %d",
1308 &loop, &zone, &top_temp, &pid_p, &pid_i, &pid_d, &man_out, &range);
1309 zone_dd[0] = top_temp;
1313 zone_dd[4] = man_out;
1316 sscanf(str,
"%f, %f, %f, %f, %f, %d",
1317 &top_temp, &pid_p, &pid_i, &pid_d, &man_out, &range);
1318 zone_ls340[0] = top_temp;
1319 zone_ls340[1] = pid_p;
1320 zone_ls340[2] = pid_i;
1321 zone_ls340[3] = pid_d;
1322 zone_ls340[4] = man_out;
1323 zone_ls340[5] = range;
1325 if ((zone_dd[0] != zone_ls340[0]) || (zone_dd[1] != zone_ls340[1]) || (zone_dd[2] != zone_ls340[2]) ||
1326 (zone_dd[3] != zone_ls340[3]) || (zone_dd[4] != zone_ls340[4]) || (zone_dd[5] != zone_ls340[5])) {
1327 cm_msg(MINFO,
"LS340_in_init",
"%s. Zone settings from the DD and from the LS340 are different.",
1333 cm_msg(MINFO,
"LS340_in_init",
"%s. Zone settings successfully transferred to the LS340.", info->
ls340_odb_names.
ls_name);
1340 db_find_key(hDB, hKey,
"DD/SCW", &hkeydd);
1342 size =
sizeof(info->
scw);
1343 db_get_record(hDB, hkeydd, &info->
scw, &size, 0);
1345 info->
scw.pid = ss_getpid();
1346 info->
scw.last_updated = ss_time();
1349 db_set_record(hDB, hkeydd, &info->
scw,
sizeof(info->
scw), 0);
1352 status = lem_scw_init(&info->
scw);
1353 if (status != LEM_SCW_SUCCESS) {
1354 cm_msg(MINFO,
"ls340_in_init",
"Couldn't register with lem watchdog");
1395 lem_scw_exit(&info->
scw);
1414 char str[128], qry[128], rcv[128];
1444 cm_msg(MINFO,
"LS340_set",
1445 "LS340_set: %s: set values not possible at the moment, since the bus driver is not available!",
1469 cm_msg(MERROR,
"LS340_set",
"LS340: %s: Max. allowed setpoint is set to %f",
1472 sprintf(str,
"SETP 1, %.3f\r\n", value);
1474 sprintf(qry,
"SETP? 1\r\n");
1477 if ( value > 1000.f || value < 0.f)
1479 sprintf(str,
"PID 1, %d\r\n", (
int)value);
1480 sprintf(qry,
"PID? 1\r\n");
1483 if ( value > 1000.f || value < 1.f)
1485 sprintf(str,
"PID 1, , %d\r\n", (
int)value);
1486 sprintf(qry,
"PID? 1\r\n");
1489 if ( value > 1000.f || value < 1.f)
1491 sprintf(str,
"PID 1, , , %d\r\n", (
int)value);
1492 sprintf(qry,
"PID? 1\r\n");
1497 cm_msg(MERROR,
"LS340_set",
"LS340_set: %s: The heater range must be in the integer range [0,%d]",
1500 sprintf(str,
"RANGE %d\r\n", (
int)value);
1501 sprintf(qry,
"RANGE?\r\n");
1505 if ( value > 6.f || value < 1.f )
1507 sprintf(str,
"CMODE 1, %d\r\n", (
int)value);
1508 sprintf(qry,
"CMODE? 1\r\n");
1511 if (value > 100.f) {
1513 cm_msg(MERROR,
"LS340_set",
1514 "LS340_set: %s: setpoint ramping only in the range [0.1, 100] (K/min) possible",
1518 sprintf(str,
"RAMP 1, 0, 0.1\r\n");
1520 sprintf(str,
"RAMP 1, 1, %0.1f\r\n", value);
1521 sprintf(qry,
"RAMP? 1\r\n");
1542 cm_msg(MINFO,
"LS340_set",
"LS340_set: %s: Result of query %s = %s", info->
ls340_odb_names.
ls_name, qry, rcv);
1555 char cmd[128], str[128], *s;
1556 INT status, value[4], i;
1557 float loop, zone_no, top_temp, pid_p, pid_i, pid_d, man_out;
1564 strcpy(cmd,
"HTRST?\r\n");
1569 cm_msg(MINFO,
"ls340_check_heater",
1570 "%s: ls340_check_heater: WARNING: couldn't check heater state",
1575 sscanf(str,
"%d", &value[0]);
1579 cm_msg(MERROR,
"ls340_check_heater",
"%s: power supply over voltage",
1583 cm_msg(MERROR,
"ls340_check_heater",
"%s: power supply under voltage",
1587 cm_msg(MERROR,
"ls340_check_heater",
"%s: output DAC error",
1591 cm_msg(MERROR,
"ls340_check_heater",
"%s: current limit DAC error",
1595 cm_msg(MERROR,
"ls340_check_heater",
"%s: open heater load",
1599 cm_msg(MERROR,
"ls340_check_heater",
"%s: heater load less than 10 ohms",
1607 strcpy(cmd,
"CSET? 1\r\n");
1611 cm_msg(MINFO,
"ls340_check_heater",
1612 "%s: ls340_check_heater: WARNING: couldn't check control loop 1 parameters",
1616 s = strstr(str,
",");
1619 sscanf(s,
",%d,%d,%d", &value[0], &value[1], &value[2]);
1621 if (value[1] == 0) {
1622 cm_msg(MERROR,
"ls340_check_heater",
1623 "%s: heater output disabled. Will try to switch it on again. NO guarantee that it will work. CHECK it!", info->
ls340_odb_names.
ls_name);
1625 strcpy(cmd,
"CSET 1,,1,1\r\n");
1632 strcpy(cmd,
"RANGE?\r\n");
1634 sscanf(str,
"%d", &value[0]);
1641 cm_msg(MINFO,
"ls340_check_heater",
1642 "%s, heater range readback is %d, should be %d, will set it to its demand value",
1648 strcpy(cmd,
"RANGE?\r\n");
1652 cm_msg(MINFO,
"ls340_check_heater",
1653 "%s: ls340_check_heater: WARNING: couldn't check heater range",
1657 sscanf(str,
"%d", &value[0]);
1659 if (info->
cmode != 2) {
1666 cm_msg(MINFO,
"ls340_check_heater",
1667 "%s, heater range readback is %d, should be %d, will set it to its demand value",
1672 for (i=0; i<10; i++) {
1673 memset(str, 0,
sizeof(str));
1675 sscanf(str,
"%f, %f, %f, %f, %f, %f, %f, %d",
1676 &loop, &zone_no, &top_temp, &pid_p, &pid_i, &pid_d, &man_out, &range);
1681 if (value[0] != range) {
1683 sprintf(cmd,
"RANGE %d\r\n", range);
1686 cm_msg(MINFO,
"ls340_check_heater",
1687 "%s, heater range readback is %d, should be %d, will set it to its demand value",
1703 char str[128], cmd[128], datetime[32];
1704 INT cmd_tag, sub_tag, status;
1705 int size, i, enabled;
1706 float pid_p, pid_i, pid_d, fvalue;
1707 DWORD nowtime, difftime;
1719 nowtime = ss_millitime();
1727 nowtime = ss_time();
1738 cm_msg(MERROR,
"LS340_get",
"too many reconnection failures, bailing out :-(");
1746 info->
scw.last_updated = ss_time();
1747 lem_scw_update(&info->
scw);
1762 strcpy(cmd,
"HTR?\r\n");
1765 strcpy(cmd,
"SETP? 1\r\n");
1768 strcpy(cmd,
"PID? 1\r\n");
1771 strcpy(cmd,
"RANGE?\r\n");
1774 strcpy(cmd,
"CMODE? 1\r\n");
1777 strcpy(cmd,
"RAMP? 1\r\n");
1794 if (info->
ihis != 0)
1795 *pvalue /= info->
ihis;
1813 cm_msg(MERROR,
"LS340_get",
"LS340: %s: LakeShore340 does not respond.",
1824 status = info->
bd(CMD_EXIT, info->
bd_info);
1826 cm_msg(MINFO,
"LS340_get",
"LS340: %s: try to disconnect and reconnect the bus driver (status = %d)",
1838 if (status != FE_SUCCESS) {
1840 cm_msg(MINFO,
"LS340_get",
"LS340: %s: reconnection attempted failed (status = %d)",
1861 sscanf(str,
"%f,%f,%f", &pid_p, &pid_i, &pid_d);
1864 if (strlen(str)==20)
1870 if (strlen(str)==20)
1876 if (strlen(str)==20)
1885 }
else if (cmd_tag == 6) {
1886 sscanf(str,
"%d, %f", &enabled, &fvalue);
1891 }
else if (cmd_tag == 4) {
1892 sscanf(str,
"%f", pvalue);
1893 if (*pvalue != 0.0) {
1899 if (channel < info->ls340_settings.intern.no_of_sensors) {
1900 if (!(strlen(str)==13) || !(str[0]=
'+')) {
1904 cm_msg(MINFO,
"LS340_get",
"LS340_get: WARNING: Too many temp. readback errors! Please check %s",
1920 sscanf(str,
"%f", pvalue);
1927 info->
cmode = *pvalue;
1933 strcpy(cmd,
"DATETIME?\r\n");
1939 strncpy(datetime, str, 32);
1940 size = strlen(datetime);
1941 if (strstr(datetime,
"\r\n"))
1943 db_set_data(info->
hDB, info->
hkey_datetime, datetime,
sizeof(datetime), 1, TID_STRING);
1955 sscanf(str,
"%f", &fvalue);
1956 size =
sizeof(fvalue);
1978 if (channel < info->ls340_settings.intern.no_of_sensors) {
2006 INT channel, status;
2012 va_start(argptr, cmd);
2013 status = FE_SUCCESS;
2018 hKey = va_arg(argptr, HNDLE);
2019 info = va_arg(argptr,
void *);
2020 channel = va_arg(argptr, INT);
2021 flags = va_arg(argptr, DWORD);
2022 bd = va_arg(argptr,
void *);
2027 info = va_arg(argptr,
void *);
2032 info = va_arg(argptr,
void *);
2033 channel = va_arg(argptr, INT);
2034 pvalue = va_arg(argptr,
float*);
2035 status =
ls340_get(info, channel, pvalue);
2039 info = va_arg(argptr,
void *);
2040 channel = va_arg(argptr, INT);
2041 name = va_arg(argptr,
char *);
2057 INT channel, status;
2063 va_start(argptr, cmd);
2064 status = FE_SUCCESS;
2069 hKey = va_arg(argptr, HNDLE);
2070 info = va_arg(argptr,
void *);
2071 channel = va_arg(argptr, INT);
2072 flags = va_arg(argptr, DWORD);
2073 bd = va_arg(argptr,
void *);
2078 info = va_arg(argptr,
void *);
2079 channel = va_arg(argptr, INT);
2080 value = (float) va_arg(argptr,
double);
2081 status =
ls340_set(info, channel, value);
2085 info = va_arg(argptr,
void *);
2086 channel = va_arg(argptr, INT);
2087 name = va_arg(argptr,
char *);
#define LS340_MAX_RECONNECTION_FAILURE
INT read_timeout
get data every read_timeout (sec), if zero midas has the timing control
INT detailed_msg
flag indicating if detailed status/error messages are wanted
float max_user_current
max. current (in A) for user current tag 5
BOOL read_raw_data
flag indicating if raw data shall be read
char names_out[8][NAME_LENGTH]
names of the out-channels
INT ls340_force_update(LS340_INFO *info)
DWORD lasterrtime
timer for error handling
float raw_value_7
raw sensor reading channel 7
char names_in[8][NAME_LENGTH]
names of the in-channels
#define LS340_ODB_NAMES_STR
initializing string for LS340_ODB_NAMES
stores internal informations within the DD.
#define LS340_INIT_ERROR
initialize error tag
#define LS340_SENSORS_STR
initializing string for LS340_SENSORS
INT ls340_out_init(HNDLE hKey, void **pinfo, INT channels, INT(*bd)(INT cmd,...))
INT ls340_get_decode(LS340_INFO *info, INT ch, int *sub_tag)
INT ls340_in(INT cmd,...)
float raw_value_2
raw sensor reading channel 2
void ls340_check_heater(LS340_INFO *info)
char name[LS340_MAX_SENSORS][NAME_LENGTH]
name for each channel
void * bd_info
private info of bus driver
INT ls340_out_get_label(LS340_INFO *info, INT channel, char *name)
HNDLE hkey_raw_value[10]
handle to the raw value input DD entry
INT errorcount
error counter
HNDLE hDB
main handle to the ODB
#define LS340_MAX_TRY_MANY
maximum number of communication attempts for important reads
float history[LS340_MAX_AVG]
stores last temperatures of sensor 1
INT ls340_send_rcv(LS340_INFO *info, char *cmd, char *str, int max_try)
INT num_channels_in
number of in-channels
int ets_logout(void *info, int wait, int detailed_msg)
float raw_value_8
raw sensor reading channel 8
#define LS340_MAX_READBACK_FAILURE
maximum number of readback failures before a reconnect will take place
HNDLE hkey_datetime
handle to the date and time DD entry
#define LS340_TIME_OUT
time out in msecs for read (rs232)
INT ls340_in_get_label(LS340_INFO *info, INT channel, char *name)
DWORD read_timer[20]
timer telling the system when to read data (via LS340_get, in (ms))
DWORD last_value[15]
stores the last valid value
INT curve[LS340_MAX_SENSORS]
sensor calibration curve: see LakeShore340 manual, p.9-33
BOOL his_full
flag used to indicate that the history buffer is full
LEM_SC_WATCHDOG scw
slowcontrol watchdog info structure
INT no_of_sensors
number of sensors used
int max_current_tag
1->0.25A, 2->0.5A, 3->1.0A, 4->2.0A, 5->User
INT(* bd)(INT cmd,...)
bus driver entry function
float raw_value_10
raw sensor reading channel 10
INT heater_setting
current output heater setting
#define LS340_INTERNAL_STR
initializing string for LS340_INTERNAL
#define LS340_MAX_TRY_LESS
maximum number of communication attempts for less important reads
INT scw_in_use
flag indicating if the slowcontrol watchdog shall be used
char odb_output[2 *NAME_LENGTH]
odb output variable path. Needed by the forced update routine
INT readback_failure
counts the number of readback failures
int max_heater_range
upper limit for the heater range (see LakeShore340 manual, 6-9, 9-27)
char zone[10 *NAME_LENGTH]
char cryo_name[NAME_LENGTH]
name of the LS340
#define LS340_MAX_AVG
max. length of the average array
float raw_value_4
raw sensor reading channel 4
INT readback_err
number of readback errors for the temperature reading
stores internal informations within the DD.
INT odb_offset
odb offset for the output variables. Needed by the forced update routine
float raw_value_9
raw sensor reading channel 9
#define LS340_WAIT
time (ms) to wait between commands
INT ls340_exit(LS340_INFO *info)
#define LS340_MAX_ERROR
maximum number of error messages
float heater_resistance
heater resistance in OhmLakeShore340.sav
char ls_name[NAME_LENGTH]
name of the LS340
float setpoint_limit
in Kelvin
INT num_channels_out
number of out-channels
INT ls340_set(LS340_INFO *info, INT channel, float value)
#define LS340_DELTA_R
max. allowed deviation between ODB heater resistance and LS340 readback
#define LS340_DELTA_TIME_ERROR
reset error counter after LS340_DELTA_TIME_ERROR seconds
#define LS340_SCW_STR
defines the slowcontrol default watchdog info structure
float cmode
prevailing control mode
INT ets_in_use
flag indicating if the rs232 terminal server is in use
INT ls340_get(LS340_INFO *info, INT channel, float *pvalue)
stores internal informations within the DD.
INT reconnect_timeout
reconnection timeout in (sec)
void ls340_no_connection(LS340_INFO *info, INT value)
int set_startup_counter
counter to supress setting of PID and Range at startup
char ctrl_ch[4]
which channel is used for control loop (A/B/C1-C4/D1-D4 possible)
float raw_value_1
raw sensor reading channel 1
#define LS340_DEBUG
debug tag, if set to TRUE, additional messages will be displayed at execution time ...
LS340_SETTINGS ls340_settings
ODB data for the DD.
INT startup_error
startup error tag
char channel[LS340_MAX_SENSORS][4]
which channel: A, B, C1-C4, D1-D4
INT no_connection
flag showing that there is no connection at the moment
INT type[LS340_MAX_SENSORS]
sensor type: 1-12, see LakeShore340 manual, p.9-33
LS340_ODB_NAMES ls340_odb_names
ODB data for the DD.
HNDLE hkey
handle to the BD key
HNDLE hkey_no_connection
handle to the no connection flag
void ls340_cryo_name_changed(HNDLE hDB, HNDLE dummy, void *pinfo)
int bd_connected
flag showing if bus driver is connected
#define LS340_MAX_SENSORS
max. number of possible input sensors
float raw_value_6
raw sensor reading channel 6
float raw_value_5
raw sensor reading channel 5
float raw_value_3
raw sensor reading channel 3
stores internal informations within the DD.
stores internal informations within the DD.
INT remote
stores if the LS340 is computer controlled of not
INT reconnection_failures
how many reconnection failures took place
float setpoint
prevailing setpoint
INT ls340_in_init(HNDLE hKey, void **pinfo, INT channels, INT(*bd)(INT cmd,...))
#define LS340_READ_ERROR
read error tag
INT ls340_out(INT cmd,...)
int first_bd_error
flag showing if the bus driver error message is already given
#define LS340_ETS_LOGOUT_SLEEP
sleep time (us) between the telnet commands of the ets_logout
DWORD last_reconnect
timer for bus driver reconnect error handlingLakeShore340.sav
#define LS340_LOOP1_STR
initializing string for LS340_LOOP1