Rev 326 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 326 | Rev 357 | ||
---|---|---|---|
Line 655... | Line 655... | ||
655 | if (sa02Verbose) { |
655 | if (sa02Verbose) { |
656 | sa02Printf("Data in the file:%s\n", filename); |
656 | sa02Printf("Data in the file:%s\n", filename); |
657 | } |
657 | } |
658 | if (gFp) { |
658 | if (gFp) { |
659 | fp=gFp; |
659 | fp=gFp; |
- | 660 | } |
|
660 |
|
661 | else { |
661 | if (append) { |
662 | if (append) { |
662 | fp=fopen(filename,"ab"); |
663 | fp=fopen(filename,"ab"); |
- | 664 | } |
|
663 |
|
665 | else { |
664 | fp=fopen(filename,"wb"); |
666 | fp=fopen(filename,"wb"); |
665 | } |
667 | } |
666 | } |
668 | } |
667 | output=1; |
669 | output=1; |
668 | // run header |
670 | // run header |
Line 676... | Line 678... | ||
676 | runinfo.ch = ch; |
678 | runinfo.ch = ch; |
677 | runinfo.neve= toread; |
679 | runinfo.neve= toread; |
678 | runinfo.writemode= towrite; |
680 | runinfo.writemode= towrite; |
679 | sa02Printf("RUNINFO x0=%d nx=%d dx=%d\n", runinfo.x0,runinfo.dx,runinfo.nx); |
681 | sa02Printf("RUNINFO x0=%d nx=%d dx=%d\n", runinfo.x0,runinfo.dx,runinfo.nx); |
680 | nbtotal+=fwrite(&runinfo, 1,sizeof(runinfo),fp); //gzip |
682 | nbtotal+=fwrite(&runinfo, 1,sizeof(runinfo),fp); //gzip |
- | 683 | } |
|
681 |
|
684 | else { |
682 | if (sa02Verbose) { |
685 | if (sa02Verbose) { |
683 | sa02Printf("Data are not written to the file!\n"); |
686 | sa02Printf("Data are not written to the file!\n"); |
684 | } |
687 | } |
685 | } |
688 | } |
686 | 689 | ||
687 | if (!neve & (towrite || toread) ) { |
690 | if (!neve & (towrite || toread) ) { |
688 | neve=1; |
691 | neve=1; |
689 | } |
692 | } |
690 | 693 | ||
691 | 694 | ||
Line 714... | Line 717... | ||
714 | int icfa_visible=0; |
717 | int icfa_visible=0; |
715 | int icfa_add=0; |
718 | int icfa_add=0; |
716 | GetPanelAttribute (p6h, ATTR_VISIBLE, &icfa_visible); |
719 | GetPanelAttribute (p6h, ATTR_VISIBLE, &icfa_visible); |
717 | GetCtrlVal (p6h, MINIRICH_ADD, &icfa_add); |
720 | GetCtrlVal (p6h, MINIRICH_ADD, &icfa_add); |
718 | if (icfa_visible) { |
721 | if (icfa_visible) { |
719 | icfa_Init(); |
722 | icfa_Init(); |
720 | icfa_Histo(); |
723 | icfa_Histo(); |
721 | } |
724 | } |
722 | /////////////////////////////////////////////////////////////// |
725 | /////////////////////////////////////////////////////////////// |
723 | SetCtrlAttribute (p1h, P1_GRAPH2D, ATTR_LABEL_TEXT , title); |
726 | SetCtrlAttribute (p1h, P1_GRAPH2D, ATTR_LABEL_TEXT , title); |
724 | H2DInit(h2, "h2d",title, 144*4, 0,1,neve,data0, dstep); |
727 | H2DInit(h2, "h2d",title, 144*4, 0,1,neve,data0, dstep); |
725 | H2DSetTitleY(h2,scmd); |
728 | H2DSetTitleY(h2,scmd); |
726 | 729 | ||
727 | sa02Printf("H2D nx=%d ny=%d i=%d neve=%d\n", H2DGetNbinsX(h2),H2DGetNbinsY(h2), i, neve); |
730 | sa02Printf("H2D nx=%d ny=%d i=%d neve=%d\n", H2DGetNbinsX(h2),H2DGetNbinsY(h2), i, neve); |
728 | 731 | ||
729 | 732 | ||
730 | plot2d(h2,1); |
733 | plot2d(h2,1); |
731 | for (i=0; i<neve; i++) { |
734 | for (i=0; i<neve; i++) { |
732 | int nb = sizeof(uint32_t); |
735 | int nb = sizeof(uint32_t); |
733 | int count=0; |
736 | int count=0; |
734 | 737 | ||
735 | 738 | ||
736 | for (board=0; board<4; board++) { |
739 | for (board=0; board<4; board++) { |
737 | 740 | ||
738 | switch (towrite) { |
741 | switch (towrite) { |
739 | case 1: { |
742 | case 1: { |
740 | rdata[count+2]= data; |
743 | rdata[count+2]= data; |
Line 756... | Line 759... | ||
756 | break; |
759 | break; |
757 | } |
760 | } |
758 | } |
761 | } |
759 | if (towrite==3) { |
762 | if (towrite==3) { |
760 | SetCtrlVal(p1h,P1_SETVALUE, chip*36+ch ); |
763 | SetCtrlVal(p1h,P1_SETVALUE, chip*36+ch ); |
- | 764 | } |
|
761 |
|
765 | else { |
762 | SetCtrlVal(p1h,P1_SETVALUE, data); |
766 | SetCtrlVal(p1h,P1_SETVALUE, data); |
763 | } |
767 | } |
764 | 768 | ||
765 | 769 | ||
766 | 770 | ||
767 | } |
771 | } |
768 | 772 | ||
769 | Sa02SetNeve(toread); |
773 | Sa02SetNeve(toread); |
770 | sa02Reset(); |
774 | sa02Reset(); |
771 | 775 | ||
772 | // for ( j=0; j< toread; j++) |
776 | // for ( j=0; j< toread; j++) |
773 | { |
777 | { |
774 | int eventerror = 0; |
778 | int eventerror = 0; |
775 | 779 | ||
776 | if ( (count +2 +dsize) >= maxsize) { |
780 | if ( (count +2 +dsize) >= maxsize) { |
Line 781... | Line 785... | ||
781 | } |
785 | } |
782 | 786 | ||
783 | do { |
787 | do { |
784 | if (sendswtrg == 1) Sa02SoftwareTrigger(); |
788 | if (sendswtrg == 1) Sa02SoftwareTrigger(); |
785 | nb = sa02Read(mask, &rdata[count+2] ); |
789 | nb = sa02Read(mask, &rdata[count+2] ); |
- | 790 | } |
|
786 |
|
791 | while ( nb==0 && !ctrl_c); |
787 | if (nb==0) sa02Printf("nb==0 LINE=%d\n",__LINE__); |
792 | if (nb==0) sa02Printf("nb==0 LINE=%d\n",__LINE__); |
788 | 793 | ||
789 | if (testfixeddata && nb>0) { |
794 | if (testfixeddata && nb>0) { |
790 | int len = nb / sizeof(uint32_t); |
795 | int len = nb / sizeof(uint32_t); |
791 | for (ir=0; ir<len; ir++) { |
796 | for (ir=0; ir<len; ir++) { |
Line 800... | Line 805... | ||
800 | readerror++; |
805 | readerror++; |
801 | if (readerror==3) { |
806 | if (readerror==3) { |
802 | ctrl_c = 1; |
807 | ctrl_c = 1; |
803 | system("date >> firmware.lock"); |
808 | system("date >> firmware.lock"); |
804 | } |
809 | } |
- | 810 | } |
|
805 |
|
811 | else { |
806 | readerror= 0; |
812 | readerror= 0; |
807 | } |
813 | } |
808 | 814 | ||
809 | for (ich=0; ich<144*4; ich++) { |
815 | for (ich=0; ich<144*4; ich++) { |
810 | int xch = (143 - ich%144) + ich/144*144; |
816 | int xch = (143 - ich%144) + ich/144*144; |
811 | H2DFillBin(h2, xch,i,rdata[count+2+ich]); |
817 | H2DFillBin(h2, xch,i,rdata[count+2+ich]); |
812 | } |
818 | } |
813 | 819 | ||
814 | if (icfa_visible) icfa_Event(&rdata[count+2], icfa_add ); |
820 | if (icfa_visible) icfa_Event(&rdata[count+2], icfa_add ); |
815 | 821 | ||
816 | /* |
822 | /* |
817 | for (ich=0; ich<144; ich++) { |
823 | for (ich=0; ich<144; ich++) { |
818 | // id=(35-ich/4)+gBoardNumber*36; |
824 | // id=(35-ich/4)+gBoardNumber*36; |
819 | // shft=(ich%4)*8; |
825 | // shft=(ich%4)*8; |
820 | id=(17-ich/8)+sa02BoardNumber*18; |
826 | id=(17-ich/8)+sa02BoardNumber*18; |
Line 826... | Line 832... | ||
826 | } |
832 | } |
827 | if (sa02Verbose>2) { |
833 | if (sa02Verbose>2) { |
828 | sa02Printf("%02X ",(rdata[count+2+id]>> shft)& 0xF ); |
834 | sa02Printf("%02X ",(rdata[count+2+id]>> shft)& 0xF ); |
829 | // sa02Printf("%02X ",(rdata[count+2+id]>> shft)& 0xFF ); |
835 | // sa02Printf("%02X ",(rdata[count+2+id]>> shft)& 0xFF ); |
830 | } |
836 | } |
831 | } |
837 | } |
832 | */ |
838 | */ |
833 | 839 | ||
834 | if (sa02Verbose>2) sa02Printf("\n" ); |
840 | if (sa02Verbose>2) sa02Printf("\n" ); |
835 | if (nb>=0) count+=module_header(0x3,&rdata[count],nb/sizeof(uint32_t)); // recid 0x3 |
841 | if (nb>=0) count+=module_header(0x3,&rdata[count],nb/sizeof(uint32_t)); // recid 0x3 |
836 | 842 | ||
Line 850... | Line 856... | ||
850 | sa02Printf("%d events in %2.2f min (%d s) TIMEOUTS=%d %s",ncount, (double)(t-tstart)/60.,t-tstart, nerrors, ctime(&t)); |
856 | sa02Printf("%d events in %2.2f min (%d s) TIMEOUTS=%d %s",ncount, (double)(t-tstart)/60.,t-tstart, nerrors, ctime(&t)); |
851 | } |
857 | } |
852 | if (aborttimeout && (t-tstart)>aborttimeout) { |
858 | if (aborttimeout && (t-tstart)>aborttimeout) { |
853 | sa02Printf("Abort timeout reached ....\n"); |
859 | sa02Printf("Abort timeout reached ....\n"); |
854 | ctrl_c=1; |
860 | ctrl_c=1; |
855 | break; |
861 | break; |
856 | } |
862 | } |
857 | told=t; |
863 | told=t; |
858 | if (nb==0) { |
864 | if (nb==0) { |
859 | nerrors++; |
865 | nerrors++; |
860 | //j--; /// kako potem pride cez zeljeno stevil ozadetkov? |
866 | //j--; /// kako potem pride cez zeljeno stevil ozadetkov? |
861 | } else { |
- | |
862 | ncount++; |
- | |
863 | } |
867 | } |
- | 868 | else { |
|
- | 869 | ncount++; |
|
- | 870 | } |
|
864 | } |
871 | } |
865 | if (externalcmd) { |
872 | if (externalcmd) { |
866 | char ecmd[256]; |
873 | char ecmd[256]; |
867 | sprintf(ecmd,"%s %u %u %u %u",externalcommand,(unsigned int) tstart,data, rdata[2], rdata[3]); |
874 | sprintf(ecmd,"%s %u %u %u %u",externalcommand,(unsigned int) tstart,data, rdata[2], rdata[3]); |
868 | if (sa02Verbose) { |
875 | if (sa02Verbose) { |
869 | sa02Printf("Executing external command %s\n",ecmd); |
876 | sa02Printf("Executing external command %s\n",ecmd); |
870 | } |
877 | } |
871 | system(ecmd); |
878 | system(ecmd); |
872 | } |
879 | } |
873 | 880 | ||
874 | if (output && Random(0,1)<fraction) { |
881 | if (output && Random(0,1)<fraction) { |
875 | evtrec.id = EVTREC_ID; |
882 | evtrec.id = EVTREC_ID; |
876 | evtrec.len=count*sizeof(uint32_t)+ sizeof(evtrec); |
883 | evtrec.len=count*sizeof(uint32_t)+ sizeof(evtrec); |
877 | evtrec.time= (uint32_t) time(NULL); |
884 | evtrec.time= (uint32_t) time(NULL); |
Line 882... | Line 889... | ||
882 | } |
889 | } |
883 | if (nb!= (int) evtrec.len) { |
890 | if (nb!= (int) evtrec.len) { |
884 | sa02Printf("Error writing! %d!=%d\n",nb,evtrec.len); |
891 | sa02Printf("Error writing! %d!=%d\n",nb,evtrec.len); |
885 | } |
892 | } |
886 | nbtotal+= nb; |
893 | nbtotal+= nb; |
887 | } |
894 | } |
888 | 895 | ||
889 | if (sa02Verbose==1) { |
896 | if (sa02Verbose==1) { |
890 | sa02Printf("[%d/%d] %u \t", i,count, (unsigned int) time(NULL)); |
897 | sa02Printf("[%d/%d] %u \t", i,count, (unsigned int) time(NULL)); |
891 | PrintData(rdata,count); |
898 | PrintData(rdata,count); |
892 | } |
899 | } |
Line 895... | Line 902... | ||
895 | ch += dstep; |
902 | ch += dstep; |
896 | if (ch>35) { |
903 | if (ch>35) { |
897 | ch-=36; |
904 | ch-=36; |
898 | chip++; |
905 | chip++; |
899 | } |
906 | } |
- | 907 | } |
|
900 |
|
908 | else { |
901 | data += dstep; |
909 | data += dstep; |
902 | } |
910 | } |
903 | if (ctrl_c ) { |
911 | if (ctrl_c ) { |
904 | if (!testfixeddata) { |
912 | if (!testfixeddata) { |
905 | sa02Printf("Ctrl+C Program interrupted ....\n"); |
913 | sa02Printf("Ctrl+C Program interrupted ....\n"); |
906 | } |
914 | } |
907 | break; |
915 | break; |
908 | } |
916 | } |
909 | } |
917 | } |
910 | plot2d(h2, i-1); |
918 | plot2d(h2, i-1); |
911 | if (icfa_visible) icfa_Draw(); |
919 | if (icfa_visible) icfa_Draw(); |
912 | 920 | ||
913 | if (output) { |
921 | if (output) { |
914 | sprintf(scmd,"channel;daqtime=%f", Timer()-t0 ); |
922 | sprintf(scmd,"channel;daqtime=%f", Timer()-t0 ); |
915 | H2DSetTitleX(h2,scmd); |
923 | H2DSetTitleX(h2,scmd); |
916 | H2DWrite2File(h2,fp); |
924 | H2DWrite2File(h2,fp); |
917 | if (!gFp) { |
925 | if (!gFp) { |
918 | fclose(fp); |
926 | fclose(fp); |
919 | } |
927 | } |
920 | } |
928 | } |
921 | if (sa02Verbose>1) sa02Printf("%d bytes written to file %s\n", nbtotal, filename); |
929 | if (sa02Verbose>1) sa02Printf("%d bytes written to file %s\n", nbtotal, filename); |
922 | time(&t); |
930 | time(&t); |
923 | if (toread && !testfixeddata) sa02Printf("%d events in %2.2f min (%f s) TIMEOUTS=%d %s",ncount, (double)(Timer()-t0)/60.,Timer()-t0, nerrors, ctime(&t)); |
931 | if (toread && !testfixeddata) sa02Printf("%d events in %2.2f min (%f s) TIMEOUTS=%d %s",ncount, (double)(Timer()-t0)/60.,Timer()-t0, nerrors, ctime(&t)); |
924 | free(rdata); |
932 | free(rdata); |
925 | 933 | ||
926 | return 0; |
934 | return 0; |
927 | } |
935 | } |
928 | 936 | ||
929 | int CVICALLBACK quit (int panel, int event, void *callbackData, |
937 | int CVICALLBACK quit (int panel, int event, void *callbackData, |
930 | int eventData1, int eventData2) { |
938 | int eventData1, int eventData2) { |
931 | switch (event) { |
939 | switch (event) { |
932 | case EVENT_CLOSE: |
940 | case EVENT_CLOSE: |
933 | // Stop timer callbacks |
941 | // Stop timer callbacks |
Line 945... | Line 953... | ||
945 | quit(0,0,NULL,0,0); |
953 | quit(0,0,NULL,0,0); |
946 | exit(0); |
954 | exit(0); |
947 | } |
955 | } |
948 | return 0; |
956 | return 0; |
949 | } |
957 | } |
950 | 958 | ||
951 | int SetParametersFromFile( const char *fname) { |
959 | int SetParametersFromFile( const char *fname) { |
952 | uint32_t gdata; |
960 | uint32_t gdata; |
953 | uint32_t cdata; |
961 | uint32_t cdata; |
954 | 962 | ||
955 | sa02AsicGlobalRegister *greg = (sa02AsicGlobalRegister *) &gdata ; |
963 | sa02AsicGlobalRegister *greg = (sa02AsicGlobalRegister *) &gdata ; |
Line 976... | Line 984... | ||
976 | sa02Printf("Error! Cannot open file %s\n",fname); |
984 | sa02Printf("Error! Cannot open file %s\n",fname); |
977 | return -1; |
985 | return -1; |
978 | } |
986 | } |
979 | for (i=0; i<8*144*4; i++) { |
987 | for (i=0; i<8*144*4; i++) { |
980 | cregdata[i]=0; |
988 | cregdata[i]=0; |
981 | } |
989 | } |
982 | for (i=0; i<7*4*4; i++) { |
990 | for (i=0; i<7*4*4; i++) { |
983 | gregdata[i]=0; |
991 | gregdata[i]=0; |
984 | } |
992 | } |
985 | gdata=0; |
993 | gdata=0; |
986 | cdata=0; |
994 | cdata=0; |
Line 1001... | Line 1009... | ||
1001 | if (strcmp(cmd,"MUXASIC")==0) { |
1009 | if (strcmp(cmd,"MUXASIC")==0) { |
1002 | asic = sa02MuxMap(asic); |
1010 | asic = sa02MuxMap(asic); |
1003 | } |
1011 | } |
1004 | switch (nb) { |
1012 | switch (nb) { |
1005 | case 1: { |
1013 | case 1: { |
1006 | if ( sa02code ) { |
1014 | if ( sa02code ) { |
1007 | SetCtrlVal(p3h,P3_FPGAPAR,line); |
1015 | SetCtrlVal(p3h,P3_FPGAPAR,line); |
1008 | 1016 | ||
1009 | break; |
1017 | break; |
1010 | } |
1018 | } |
1011 | break; |
1019 | break; |
1012 | } |
1020 | } |
1013 | case 2: { |
1021 | case 2: { |
1014 | if ( sa02code ) { |
1022 | if ( sa02code ) { |
1015 | SetCtrlVal(p3h,P3_FPGAPAR,line); |
1023 | SetCtrlVal(p3h,P3_FPGAPAR,line); |
1016 | 1024 | ||
1017 | break; |
1025 | break; |
1018 | } |
1026 | } |
1019 | if (strcmp(cmd,"param_board")==0) { |
1027 | if (strcmp(cmd,"param_board")==0) { |
1020 | board= asic; |
1028 | board= asic; |
1021 | } |
1029 | } |
1022 | if (strcmp(cmd,"load_global")==0) { |
1030 | if (strcmp(cmd,"load_global")==0) { |
1023 | row= asic+1; |
1031 | row= asic+1; |
Line 1036... | Line 1044... | ||
1036 | gregdata[(board*4+asic)*7+2] = greg->shapingtime; |
1044 | gregdata[(board*4+asic)*7+2] = greg->shapingtime; |
1037 | gregdata[(board*4+asic)*7+3] = greg->comparator; |
1045 | gregdata[(board*4+asic)*7+3] = greg->comparator; |
1038 | gregdata[(board*4+asic)*7+4] = greg->vrdrive; |
1046 | gregdata[(board*4+asic)*7+4] = greg->vrdrive; |
1039 | gregdata[(board*4+asic)*7+5] = greg->monitor; |
1047 | gregdata[(board*4+asic)*7+5] = greg->monitor; |
1040 | gregdata[(board*4+asic)*7+6] = greg->id; |
1048 | gregdata[(board*4+asic)*7+6] = greg->id; |
1041 | 1049 | ||
1042 | break; |
1050 | break; |
1043 | } |
1051 | } |
1044 | break; |
1052 | break; |
1045 | } |
1053 | } |
1046 | case 3: { |
1054 | case 3: { |
1047 | if ( sa02code) { |
1055 | if ( sa02code) { |
1048 | SetCtrlVal(p3h,P3_FPGAPAR,line); |
1056 | SetCtrlVal(p3h,P3_FPGAPAR,line); |
Line 1068... | Line 1076... | ||
1068 | greg->comparator = gval; |
1076 | greg->comparator = gval; |
1069 | break; |
1077 | break; |
1070 | } |
1078 | } |
1071 | if (strcmp(cmd,"vrdrive")==0) { |
1079 | if (strcmp(cmd,"vrdrive")==0) { |
1072 | greg->vrdrive = gval; |
1080 | greg->vrdrive = gval; |
1073 | break; |
1081 | break; |
1074 | } |
1082 | } |
1075 | if (strcmp(cmd,"monitor")==0) { |
1083 | if (strcmp(cmd,"monitor")==0) { |
1076 | greg->monitor = gval; |
1084 | greg->monitor = gval; |
1077 | break; |
1085 | break; |
1078 | } |
1086 | } |
1079 | if (strcmp(cmd,"load_ch")==0) { |
1087 | if (strcmp(cmd,"load_ch")==0) { |
Line 1100... | Line 1108... | ||
1100 | cdata=0; |
1108 | cdata=0; |
1101 | break; |
1109 | break; |
1102 | } |
1110 | } |
1103 | if (strcmp(cmd,"select")==0) { |
1111 | if (strcmp(cmd,"select")==0) { |
1104 | sa02Printf ("%s not implemeted yet\n", cmd); |
1112 | sa02Printf ("%s not implemeted yet\n", cmd); |
1105 | break; |
1113 | break; |
1106 | } |
1114 | } |
1107 | break; |
1115 | break; |
1108 | } |
1116 | } |
1109 | case 4: { |
1117 | case 4: { |
1110 | if (strcmp(cmd,"param_ch")==0) { |
1118 | if (strcmp(cmd,"param_ch")==0) { |
1111 | cdata = 0; |
1119 | cdata = 0; |
1112 | break; |
1120 | break; |
1113 | } |
1121 | } |
1114 | if (strcmp(cmd,"decaytime")==0) { |
1122 | if (strcmp(cmd,"decaytime")==0) { |
1115 | creg->decaytime = cval; |
1123 | creg->decaytime = cval; |
1116 | break; |
1124 | break; |
1117 | } |
1125 | } |
1118 | if (strcmp(cmd,"offset")==0) { |
1126 | if (strcmp(cmd,"offset")==0) { |
1119 | creg->offset = cval; |
1127 | creg->offset = cval; |
1120 | break; |
1128 | break; |
1121 | } |
1129 | } |
1122 | if (strcmp(cmd,"fineadj_unipol")==0) { |
1130 | if (strcmp(cmd,"fineadj_unipol")==0) { |
1123 | creg->fineadj_unipol = cval; |
1131 | creg->fineadj_unipol = cval; |
1124 | break; |
1132 | break; |
1125 | } |
1133 | } |
1126 | if (strcmp(cmd,"fineadj_diff")==0) { |
1134 | if (strcmp(cmd,"fineadj_diff")==0) { |
1127 | creg->fineadj_diff = cval; |
1135 | creg->fineadj_diff = cval; |
1128 | break; |
1136 | break; |
1129 | } |
1137 | } |
1130 | if (strcmp(cmd,"tpenb")==0) { |
1138 | if (strcmp(cmd,"tpenb")==0) { |
1131 | creg->tpenb = cval; |
1139 | creg->tpenb = cval; |
1132 | break; |
1140 | break; |
1133 | } |
1141 | } |
Line 1162... | Line 1170... | ||
1162 | case MENU_OPERATIO_LASER: |
1170 | case MENU_OPERATIO_LASER: |
1163 | DisplayPanel(p5h); |
1171 | DisplayPanel(p5h); |
1164 | break; |
1172 | break; |
1165 | case MENU_MINIRICH: |
1173 | case MENU_MINIRICH: |
1166 | DisplayPanel(p6h); |
1174 | DisplayPanel(p6h); |
1167 | break; |
1175 | break; |
1168 | case MENU_OPERATIO_EXIT : |
1176 | case MENU_OPERATIO_EXIT : |
1169 | quit(0,0,NULL,0,0); |
1177 | quit(0,0,NULL,0,0); |
1170 | exit(0); |
1178 | exit(0); |
1171 | //loop_on=0; |
1179 | //loop_on=0; |
1172 | break; |
1180 | break; |
Line 1210... | Line 1218... | ||
1210 | told=t; |
1218 | told=t; |
1211 | for ( j=0; j< neve; j++) { |
1219 | for ( j=0; j< neve; j++) { |
1212 | do { |
1220 | do { |
1213 | if (sendswtrg==1) Sa02SoftwareTrigger(); |
1221 | if (sendswtrg==1) Sa02SoftwareTrigger(); |
1214 | nb = sa02Read(mask, data ); |
1222 | nb = sa02Read(mask, data ); |
- | 1223 | } |
|
1215 |
|
1224 | while ( nb==0 && !ctrl_c); |
1216 | if (nb==0) sa02Printf("nb==0 LINE=%d\n",__LINE__); |
1225 | if (nb==0) sa02Printf("nb==0 LINE=%d\n",__LINE__); |
1217 | 1226 | ||
1218 | if (ctrl_c==1) break; |
1227 | if (ctrl_c==1) break; |
1219 | 1228 | ||
1220 | for (ch=0; ch<144*4; ch++) { |
1229 | for (ch=0; ch<144*4; ch++) { |
Line 1253... | Line 1262... | ||
1253 | GetCtrlVal(p1h,P1_PLOTEACHEVENT, &ploteachevent); |
1262 | GetCtrlVal(p1h,P1_PLOTEACHEVENT, &ploteachevent); |
1254 | SetCtrlVal(p1h,P1_CUREVE, j); |
1263 | SetCtrlVal(p1h,P1_CUREVE, j); |
1255 | ProcessSystemEvents (); |
1264 | ProcessSystemEvents (); |
1256 | ProcessSystemEvents (); |
1265 | ProcessSystemEvents (); |
1257 | } |
1266 | } |
1258 | 1267 | ||
1259 | told=t; |
1268 | told=t; |
1260 | 1269 | ||
1261 | } |
1270 | } |
1262 | 1271 | ||
1263 | plot2d(h2, nbit); |
1272 | plot2d(h2, nbit); |
1264 | SetCtrlVal(p1h,P1_CUREVE, j); |
1273 | SetCtrlVal(p1h,P1_CUREVE, j); |
1265 | 1274 | ||
1266 | return 0; |
1275 | return 0; |
1267 | } |
1276 | } |
1268 | 1277 | ||
1269 | int CVICALLBACK LoadParameters (int panel, int control, int event, |
1278 | int CVICALLBACK LoadParameters (int panel, int control, int event, |
1270 | void *callbackData, int eventData1, int eventData2) { |
1279 | void *callbackData, int eventData1, int eventData2) { |
1271 | char fname[0xFF]; |
1280 | char fname[0xFF]; |
1272 | uint16_t mask; |
1281 | uint16_t mask; |
1273 | switch (event) { |
1282 | switch (event) { |
1274 | case EVENT_COMMIT: |
1283 | case EVENT_COMMIT: |
1275 | mask=GetConnectedFebMask(); |
1284 | mask=GetConnectedFebMask(); |
1276 | sa02Printf("LoadParameters 0x%0x\n", mask); |
1285 | sa02Printf("LoadParameters 0x%0x\n", mask); |
1277 | GetCtrlVal(p3h, P3_INPUTFILE, fname); |
1286 | GetCtrlVal(p3h, P3_INPUTFILE, fname); |
1278 | GetCtrlVal(p1h,P1_BOARDTYPE,&sa02BoardType); |
1287 | GetCtrlVal(p1h,P1_BOARDTYPE,&sa02BoardType); |
Line 1561... | Line 1570... | ||
1561 | SetCtrlVal(p1h,P1_SETSINGLEVALUE,k); |
1570 | SetCtrlVal(p1h,P1_SETSINGLEVALUE,k); |
1562 | SetCtrlVal(p1h,P1_CUREVE,k); |
1571 | SetCtrlVal(p1h,P1_CUREVE,k); |
1563 | retval=sa02Cmd(board, FEB_VTH1 , k , chip, channel ,1, response); |
1572 | retval=sa02Cmd(board, FEB_VTH1 , k , chip, channel ,1, response); |
1564 | val=sa02Cmd(board, FEB_ADC_READ, data, chip, channel ,1,response); |
1573 | val=sa02Cmd(board, FEB_ADC_READ, data, chip, channel ,1,response); |
1565 | if (sa02BoardType>2) |
1574 | if (sa02BoardType>2) |
1566 | doubleval = |
1575 | doubleval = sa02adc2Vm(val); |
1567 | else |
1576 | else |
- | 1577 | doubleval = sa02adc2V(val); |
|
- | 1578 | // doubleval = (2*((val & 0xFFF) + 0.5)/0x1000 - 1.) * 3.3; |
|
- | 1579 | // else |
|
1568 |
|
1580 | // doubleval = ((val & 0xFFF) + 0.5)/0x1000 * 3.3; |
1569 | - | ||
1570 | - | ||
1571 | H1DFillBin(h1+board, k, doubleval); |
1581 | H1DFillBin(h1+board, k, doubleval); |
1572 | if (t!=told || k==kmax-1 ||k==0 ) { |
1582 | if (t!=told || k==kmax-1 ||k==0 ) { |
1573 | H1DDraw(h1+board,p1h, P1_GRAPH, &phandle[board]); |
1583 | H1DDraw(h1+board,p1h, P1_GRAPH, &phandle[board]); |
1574 | sa02Printf("[%d] set VTH1=%d ADC(VTH1)= %6.3f V\n",board, k, doubleval); |
1584 | sa02Printf("[%d] set VTH1=%d ADC(VTH1)= %6.3f V\n",board, k, doubleval); |
1575 | SetCtrlVal(p1h,P1_CUREVE, k); |
1585 | SetCtrlVal(p1h,P1_CUREVE, k); |
Line 1659... | Line 1669... | ||
1659 | } |
1669 | } |
1660 | } |
1670 | } |
1661 | switch (cmd & (~ FEB_RO)) { |
1671 | switch (cmd & (~ FEB_RO)) { |
1662 | case FEB_ADC_READ: |
1672 | case FEB_ADC_READ: |
1663 | case FEB_ADC_RESET: |
1673 | case FEB_ADC_RESET: |
- | 1674 | doubleval = sa02adc2V(val); |
|
1664 |
|
1675 | // doubleval = ((val & 0xFFF) + 0.5)/0x1000 * 3.3; |
1665 | sa02Printf("ADC %f, 0x%08x\n", doubleval, val ) ; |
1676 | sa02Printf("ADC %f, 0x%08x\n", doubleval, val ) ; |
1666 | break; |
1677 | break; |
1667 | case FEB_TMON1: |
1678 | case FEB_TMON1: |
1668 | case FEB_TMON0: |
1679 | case FEB_TMON0: |
1669 | doubleval = ( (val >>2 ) & 0xFFF ) * 0.0625; |
1680 | doubleval = ( (val >>2 ) & 0xFFF ) * 0.0625; |
Line 1680... | Line 1691... | ||
1680 | else |
1691 | else |
1681 | val=0x30; |
1692 | val=0x30; |
1682 | val=sa02Cmd(board, FEB_MUX, val, 0, 0 ,1,response); |
1693 | val=sa02Cmd(board, FEB_MUX, val, 0, 0 ,1,response); |
1683 | val=sa02Cmd(board, FEB_ADC_READ, 0, 0, 0, 1,response); |
1694 | val=sa02Cmd(board, FEB_ADC_READ, 0, 0, 0, 1,response); |
1684 | if (sa02BoardType>2) |
1695 | if (sa02BoardType>2) |
- | 1696 | doubleval = sa02adc2Vm(val); |
|
1685 |
|
1697 | // doubleval = (2*((val & 0xFFF) + 0.5)/0x1000 - 1.) * 3.3; |
1686 | else |
1698 | else |
- | 1699 | doubleval = sa02adc2V(val); |
|
1687 |
|
1700 | // doubleval = ((val & 0xFFF) + 0.5)/0x1000 * 3.3; |
1688 | sa02Printf("%5d %6.3f\n",data, doubleval); |
1701 | sa02Printf("%5d %6.3f\n",data, doubleval); |
1689 | break; |
1702 | break; |
1690 | case SA0x_ASIC0_GREG: |
1703 | case SA0x_ASIC0_GREG: |
1691 | if (cmd & FEB_RO) { |
1704 | if (cmd & FEB_RO) { |
1692 | sa02PrintGREG(&val,"Returned GREG data->"); |
1705 | sa02PrintGREG(&val,"Returned GREG data->"); |
1693 | } |
1706 | } |
1694 | break; |
1707 | break; |
1695 | case SA0x_ASIC0_CREG: |
1708 | case SA0x_ASIC0_CREG: |
1696 | if (cmd & FEB_RO) { |
1709 | if (cmd & FEB_RO) { |
Line 1806... | Line 1819... | ||
1806 | id= P1_GRAPHY; |
1819 | id= P1_GRAPHY; |
1807 | sprintf(name,"Y"); |
1820 | sprintf(name,"Y"); |
1808 | break; |
1821 | break; |
1809 | } |
1822 | } |
1810 | h2=0; |
1823 | h2=0; |
- | 1824 | } |
|
1811 |
|
1825 | else { |
1812 | switch (control) { |
1826 | switch (control) { |
1813 | case P2_PRINTXY: |
1827 | case P2_PRINTXY: |
1814 | id= P2_GRAPH_1; |
1828 | id= P2_GRAPH_1; |
1815 | sprintf(name,"XY"); |
1829 | sprintf(name,"XY"); |
1816 | break; |
1830 | break; |
1817 | } |
1831 | } |
1818 | h2=1; |
1832 | h2=1; |
1819 | } |
1833 | } |
1820 | GetSystemDate (&month,&day ,&year ); |
1834 | GetSystemDate (&month,&day ,&year ); |
1821 | GetSystemTime(&hours, &minutes, &seconds); |
1835 | GetSystemTime(&hours, &minutes, &seconds); |
1822 | if (id>=0) { |
1836 | if (id>=0) { |
1823 | if( ( (panel == p1h)&&(control == P1_PRINT2D) ) || ((panel == p2h)&&(control == P2_GRAPH_1))) { |
1837 | if( ( (panel == p1h)&&(control == P1_PRINT2D) ) || ((panel == p2h)&&(control == P2_GRAPH_1))) { |
1824 | sprintf(dfile ,"data/%d_%d_%d_%d_%d_%s.th2d",year,month,day,hours,minutes, name ); |
1838 | sprintf(dfile ,"data/%d_%d_%d_%d_%d_%s.th2d",year,month,day,hours,minutes, name ); |
1825 | H2DWrite(h2,dfile,"wb"); |
1839 | H2DWrite(h2,dfile,"wb"); |
1826 | sa02Printf("sizeof H2D %d \n",sizeof(H2D)); |
1840 | sa02Printf("sizeof H2D %d \n",sizeof(H2D)); |
1827 | sa02Printf("H2D image saved as %s\n", dfile); |
1841 | sa02Printf("H2D image saved as %s\n", dfile); |
1828 | sprintf(name ,"C:\\root\\bin\\root.exe ..\\macros\\H2Dload.cxx(\\\"%s\\\")", dfile); |
1842 | sprintf(name ,"C:\\root\\bin\\root.exe ..\\macros\\H2Dload.cxx(\\\"%s\\\")", dfile); |
1829 | LaunchExecutable(name); |
1843 | LaunchExecutable(name); |
- | 1844 | } |
|
1830 |
|
1845 | else { |
1831 | sprintf(dfile ,"data/%d_%d_%d_%d_%d_%s.bmp",year,month,day,hours,minutes, name ); |
1846 | sprintf(dfile ,"data/%d_%d_%d_%d_%d_%s.bmp",year,month,day,hours,minutes, name ); |
1832 | SaveCtrlDisplayToFile (panel,id, 0, -1, -1, dfile); |
1847 | SaveCtrlDisplayToFile (panel,id, 0, -1, -1, dfile); |
1833 | sa02Printf("bmp image saved as %s\n", dfile); |
1848 | sa02Printf("bmp image saved as %s\n", dfile); |
1834 | } |
1849 | } |
1835 | } |
1850 | } |
Line 1955... | Line 1970... | ||
1955 | 1970 | ||
1956 | 1971 | ||
1957 | GetCtrlVal(panel,ctrlID, &ch); |
1972 | GetCtrlVal(panel,ctrlID, &ch); |
1958 | if (ch) { |
1973 | if (ch) { |
1959 | H3DDrawSliceXY(100+board,ch-1,panel,graph, plot); |
1974 | H3DDrawSliceXY(100+board,ch-1,panel,graph, plot); |
- | 1975 | } |
|
1960 |
|
1976 | else { |
1961 | H2DDraw(100+board,panel,graph, plot); |
1977 | H2DDraw(100+board,panel,graph, plot); |
1962 | } |
1978 | } |
1963 | } |
1979 | } |
1964 | break; |
1980 | break; |
1965 | } |
1981 | } |
Line 1988... | Line 2004... | ||
1988 | monrec.status[ii] = buf[0]; //status |
2004 | monrec.status[ii] = buf[0]; //status |
1989 | monrec.vmon[ii] = buf[1]*1000;//zapisano v mV |
2005 | monrec.vmon[ii] = buf[1]*1000;//zapisano v mV |
1990 | monrec.imon[ii] = buf[2]*1000;//zapisano v nA |
2006 | monrec.imon[ii] = buf[2]*1000;//zapisano v nA |
1991 | monrec.vset[ii] = buf[3]*1000;//zapisano v mV |
2007 | monrec.vset[ii] = buf[3]*1000;//zapisano v mV |
1992 | monrec.iset[ii] = buf[4]*1000;//zapisano v nA |
2008 | monrec.iset[ii] = buf[4]*1000;//zapisano v nA |
- | 2009 | } |
|
1993 |
|
2010 | else { |
1994 | buf[0]=(unsigned short) (channels[ii]<<8) | ReadStatus; |
2011 | buf[0]=(unsigned short) (channels[ii]<<8) | ReadStatus; |
1995 | if (gCAEN_V288) { |
2012 | if (gCAEN_V288) { |
1996 | V288_Send(0,SYS403mid,1,buf); |
2013 | V288_Send(0,SYS403mid,1,buf); |
1997 | retval=V288_Receive(0,255,buf); |
2014 | retval=V288_Receive(0,255,buf); |
1998 | } |
2015 | } |
Line 2006... | Line 2023... | ||
2006 | V288_Send(0,SYS403mid,1,buf); |
2023 | V288_Send(0,SYS403mid,1,buf); |
2007 | retval=V288_Receive(0,255,buf); |
2024 | retval=V288_Receive(0,255,buf); |
2008 | } |
2025 | } |
2009 | vset[ii] = monrec.vset[ii] = buf[7]*10;//zapisano v mV |
2026 | vset[ii] = monrec.vset[ii] = buf[7]*10;//zapisano v mV |
2010 | iset[ii] = monrec.iset[ii] = buf[10]*10;//zapisano v nA |
2027 | iset[ii] = monrec.iset[ii] = buf[10]*10;//zapisano v nA |
2011 | } |
2028 | } |
2012 | monrec.vset[ii] = vset[ii];//zapisano v mV |
2029 | monrec.vset[ii] = vset[ii];//zapisano v mV |
2013 | monrec.iset[ii] = iset[ii];//zapisano v nA |
2030 | monrec.iset[ii] = iset[ii];//zapisano v nA |
2014 | } |
2031 | } |
2015 | //sa02Printf("%04x \t %d \t %d \t %d \t %d *\n",monrec.status[ii],monrec.vmon[ii],monrec.vset[ii],monrec.imon[ii],monrec.iset[ii]); |
2032 | //sa02Printf("%04x \t %d \t %d \t %d \t %d *\n",monrec.status[ii],monrec.vmon[ii],monrec.vset[ii],monrec.imon[ii],monrec.iset[ii]); |
2016 | } |
2033 | } |
Line 2069... | Line 2086... | ||
2069 | 2086 | ||
2070 | SetCtrlAttribute (p2h, P2_DAQ, ATTR_DIMMED, 1); |
2087 | SetCtrlAttribute (p2h, P2_DAQ, ATTR_DIMMED, 1); |
2071 | ctrl_c=0; |
2088 | ctrl_c=0; |
2072 | 2089 | ||
2073 | GetCtrlVal(p1h,P1_BOARDTYPE,&sa02BoardType); |
2090 | GetCtrlVal(p1h,P1_BOARDTYPE,&sa02BoardType); |
2074 | 2091 | ||
2075 | GetCtrlVal (p1h, P1_SERIAL_1, serial[0]); |
2092 | GetCtrlVal (p1h, P1_SERIAL_1, serial[0]); |
2076 | GetCtrlVal (p1h, P1_SERIAL_2, serial[1]); |
2093 | GetCtrlVal (p1h, P1_SERIAL_2, serial[1]); |
2077 | GetCtrlVal (p1h, P1_SERIAL_3, serial[2]); |
2094 | GetCtrlVal (p1h, P1_SERIAL_3, serial[2]); |
2078 | GetCtrlVal (p1h, P1_SERIAL_4, serial[3]); |
2095 | GetCtrlVal (p1h, P1_SERIAL_4, serial[3]); |
2079 | 2096 | ||
Line 2100... | Line 2117... | ||
2100 | GetCtrlVal (p2h, P2_XC, &x0); |
2117 | GetCtrlVal (p2h, P2_XC, &x0); |
2101 | GetCtrlVal (p2h, P2_YC, &y0); |
2118 | GetCtrlVal (p2h, P2_YC, &y0); |
2102 | 2119 | ||
2103 | GetCtrlVal (p2h, P2_DIRECTION, &runrec.direction); |
2120 | GetCtrlVal (p2h, P2_DIRECTION, &runrec.direction); |
2104 | 2121 | ||
2105 | 2122 | ||
2106 | SetCtrlAttribute(p1h,P1_TRGHVMON,ATTR_ENABLED,1); |
2123 | SetCtrlAttribute(p1h,P1_TRGHVMON,ATTR_ENABLED,1); |
2107 | hvmonFirst = 0; |
2124 | hvmonFirst = 0; |
2108 | 2125 | ||
2109 | 2126 | ||
2110 | GetCtrlVal(p1h,P1_SENDSWTRIG,&sendswtrg); |
2127 | GetCtrlVal(p1h,P1_SENDSWTRIG,&sendswtrg); |
Line 2129... | Line 2146... | ||
2129 | GetCtrlVal (p2h, P2_NEWF, &fmax); |
2146 | GetCtrlVal (p2h, P2_NEWF, &fmax); |
2130 | fmax*=1000000;//fmax in Mega Bytes |
2147 | fmax*=1000000;//fmax in Mega Bytes |
2131 | } |
2148 | } |
2132 | time (&t0); |
2149 | time (&t0); |
2133 | sa02Printf("---->daq_scan\n"); |
2150 | sa02Printf("---->daq_scan\n"); |
2134 | 2151 | ||
2135 | if (dsave) { |
2152 | if (dsave) { |
2136 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
2153 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
2137 | //gFp = fopen (dfile, "ab"); |
2154 | //gFp = fopen (dfile, "ab"); |
2138 | gFp = fopen (dfile, "ab"); |
2155 | gFp = fopen (dfile, "ab"); |
2139 | if (gFp==NULL) sa02Printf("----> !!! gFp==NULL !!!\n"); |
2156 | if (gFp==NULL) sa02Printf("----> !!! gFp==NULL !!!\n"); |
2140 | if (ferror (gFp)) sa02Printf("----> !!! ferror (gFp) after fopen !!!\n"); |
2157 | if (ferror (gFp)) sa02Printf("----> !!! ferror (gFp) after fopen !!!\n"); |
2141 | //time ((time_t *) &runrec.time); |
2158 | //time ((time_t *) &runrec.time); |
2142 | time (&cas); |
2159 | time (&cas); |
2143 | runrec.time = (uint32_t) cas; |
2160 | runrec.time = (uint32_t) cas; |
2144 | status = (int) fwrite (&runrec, 1, runrec.len, gFp); |
2161 | status = (int) fwrite (&runrec, 1, runrec.len, gFp); |
2145 | if(status != runrec.len) sa02Printf("----> !!! status != runrec.len (= %d) !!!\n", status); |
2162 | if(status != runrec.len) sa02Printf("----> !!! status != runrec.len (= %d) !!!\n", status); |
2146 | if (ferror (gFp)) sa02Printf("----> !!! ferror (gFp) = %d !!!\n", ferror (gFp)); |
2163 | if (ferror (gFp)) sa02Printf("----> !!! ferror (gFp) = %d !!!\n", ferror (gFp)); |
2147 | 2164 | ||
2148 | } |
2165 | } |
2149 | 2166 | ||
2150 | 2167 | ||
2151 | for (i=0; i<4; i++) { |
2168 | for (i=0; i<4; i++) { |
2152 | sprintf(title,"HAPD%d Surface Scan single channels", i); |
2169 | sprintf(title,"HAPD%d Surface Scan single channels", i); |
Line 2156... | Line 2173... | ||
2156 | sprintf(hname,"hxy%d_sum", i); |
2173 | sprintf(hname,"hxy%d_sum", i); |
2157 | H2DInit(hxy+i,hname,runrec.serial, runrec.nx,runrec.x0, runrec.dx,runrec.ny,runrec.y0, runrec.dy); |
2174 | H2DInit(hxy+i,hname,runrec.serial, runrec.nx,runrec.x0, runrec.dx,runrec.ny,runrec.y0, runrec.dy); |
2158 | if (scanunitsx) { |
2175 | if (scanunitsx) { |
2159 | H2DSetTitleX(hxy+i,"x (channels)"); |
2176 | H2DSetTitleX(hxy+i,"x (channels)"); |
2160 | H3DSetTitleX(hxy+i,"x (channels)"); |
2177 | H3DSetTitleX(hxy+i,"x (channels)"); |
- | 2178 | } |
|
2161 |
|
2179 | else { |
2162 | H2DSetTitleX(hxy+i,"x (stage steps)"); |
2180 | H2DSetTitleX(hxy+i,"x (stage steps)"); |
2163 | H3DSetTitleX(hxy+i,"x (stage steps)"); |
2181 | H3DSetTitleX(hxy+i,"x (stage steps)"); |
2164 | } |
2182 | } |
2165 | if (scanunitsy) { |
2183 | if (scanunitsy) { |
2166 | H2DSetTitleY(hxy+i,"y (channels)"); |
2184 | H2DSetTitleY(hxy+i,"y (channels)"); |
2167 | H3DSetTitleY(hxy+i,"y (channels)"); |
2185 | H3DSetTitleY(hxy+i,"y (channels)"); |
- | 2186 | } |
|
2168 |
|
2187 | else { |
2169 | H2DSetTitleY(hxy+i,"y (stage steps)"); |
2188 | H2DSetTitleY(hxy+i,"y (stage steps)"); |
2170 | H3DSetTitleY(hxy+i,"y (stage steps)"); |
2189 | H3DSetTitleY(hxy+i,"y (stage steps)"); |
2171 | } |
2190 | } |
2172 | 2191 | ||
2173 | } |
2192 | } |
2174 | if (runrec.direction) { |
2193 | if (runrec.direction) { |
2175 | ny = runrec.ny; |
2194 | ny = runrec.ny; |
2176 | nx = runrec.nx; |
2195 | nx = runrec.nx; |
- | 2196 | } |
|
2177 |
|
2197 | else { |
2178 | ny = runrec.nx; |
2198 | ny = runrec.nx; |
2179 | nx = runrec.ny; |
2199 | nx = runrec.ny; |
2180 | } |
2200 | } |
2181 | rdata = malloc(sizeof(uint32_t)*maxsize); |
2201 | rdata = malloc(sizeof(uint32_t)*maxsize); |
2182 | 2202 | ||
Line 2192... | Line 2212... | ||
2192 | posrec.iy = iy; |
2212 | posrec.iy = iy; |
2193 | posrec.yset=runrec.y0+posrec.iy*runrec.dy; |
2213 | posrec.yset=runrec.y0+posrec.iy*runrec.dy; |
2194 | if (scanunitsy) { |
2214 | if (scanunitsy) { |
2195 | if (posrec.yset>5) { |
2215 | if (posrec.yset>5) { |
2196 | addgap=gapy * fx; |
2216 | addgap=gapy * fx; |
- | 2217 | } |
|
2197 |
|
2218 | else { |
2198 | addgap=0; |
2219 | addgap=0; |
2199 | } |
2220 | } |
2200 | posrec.yset = (int32_t)(y0+dy *fx * posrec.yset + addgap); |
2221 | posrec.yset = (int32_t)(y0+dy *fx * posrec.yset + addgap); |
2201 | } |
2222 | } |
2202 | if (gMIKRO_Y) { |
2223 | if (gMIKRO_Y) { |
Line 2205... | Line 2226... | ||
2205 | sa02Printf("->MIKRO_MoveTo (2, y);%d\n",posrec.yset); |
2226 | sa02Printf("->MIKRO_MoveTo (2, y);%d\n",posrec.yset); |
2206 | } |
2227 | } |
2207 | 2228 | ||
2208 | SetCtrlVal (p2h, P2_Y, posrec.yset); |
2229 | SetCtrlVal (p2h, P2_Y, posrec.yset); |
2209 | SetCtrlVal (p2h, P2_IY, posrec.iy); |
2230 | SetCtrlVal (p2h, P2_IY, posrec.iy); |
- | 2231 | } |
|
2210 |
|
2232 | else { |
2211 | posrec.ix = iy; |
2233 | posrec.ix = iy; |
2212 | posrec.xset=runrec.x0+posrec.ix*runrec.dx; |
2234 | posrec.xset=runrec.x0+posrec.ix*runrec.dx; |
2213 | if (scanunitsx) { |
2235 | if (scanunitsx) { |
2214 | if (posrec.xset>5) { |
2236 | if (posrec.xset>5) { |
2215 | addgap=gapx * fx; |
2237 | addgap=gapx * fx; |
- | 2238 | } |
|
2216 |
|
2239 | else { |
2217 | addgap=0; |
2240 | addgap=0; |
2218 | } |
2241 | } |
2219 | posrec.xset = (int32_t)(x0+dx *fx * posrec.xset + addgap); |
2242 | posrec.xset = (int32_t)(x0+dx *fx * posrec.xset + addgap); |
2220 | } |
2243 | } |
2221 | if (gMIKRO_Y) { |
2244 | if (gMIKRO_Y) { |
Line 2233... | Line 2256... | ||
2233 | posrec.ix = ix; |
2256 | posrec.ix = ix; |
2234 | posrec.xset=runrec.x0+posrec.ix*runrec.dx; |
2257 | posrec.xset=runrec.x0+posrec.ix*runrec.dx; |
2235 | if (scanunitsx) { |
2258 | if (scanunitsx) { |
2236 | if (posrec.xset>5) { |
2259 | if (posrec.xset>5) { |
2237 | addgap=gapx * fx; |
2260 | addgap=gapx * fx; |
- | 2261 | } |
|
2238 |
|
2262 | else { |
2239 | addgap=0; |
2263 | addgap=0; |
2240 | } |
2264 | } |
2241 | posrec.xset = (int32_t)(x0+dx *fx * posrec.xset + addgap); |
2265 | posrec.xset = (int32_t)(x0+dx *fx * posrec.xset + addgap); |
2242 | } |
2266 | } |
2243 | if (gMIKRO_X) { |
2267 | if (gMIKRO_X) { |
2244 | //sa02Printf("MIKRO_MoveTo (1, x);%d\n",posrec.x); |
2268 | //sa02Printf("MIKRO_MoveTo (1, x);%d\n",posrec.x); |
2245 | MIKRO_MoveTo (MIKRO_X, posrec.xset); |
2269 | MIKRO_MoveTo (MIKRO_X, posrec.xset); |
2246 | sa02Printf("->MIKRO_MoveTo (1, x);%d\n",posrec.xset); |
2270 | sa02Printf("->MIKRO_MoveTo (1, x);%d\n",posrec.xset); |
2247 | } |
2271 | } |
2248 | SetCtrlVal (p2h, P2_X, posrec.xset); |
2272 | SetCtrlVal (p2h, P2_X, posrec.xset); |
2249 | SetCtrlVal (p2h, P2_IX, posrec.ix); |
2273 | SetCtrlVal (p2h, P2_IX, posrec.ix); |
- | 2274 | } |
|
2250 |
|
2275 | else { |
2251 | posrec.iy = ix; |
2276 | posrec.iy = ix; |
2252 | posrec.yset=runrec.y0+posrec.iy*runrec.dy; |
2277 | posrec.yset=runrec.y0+posrec.iy*runrec.dy; |
2253 | if (scanunitsy) { |
2278 | if (scanunitsy) { |
2254 | if (posrec.yset>5) { |
2279 | if (posrec.yset>5) { |
2255 | addgap=gapy * fx; |
2280 | addgap=gapy * fx; |
- | 2281 | } |
|
2256 |
|
2282 | else { |
2257 | addgap=0; |
2283 | addgap=0; |
2258 | } |
2284 | } |
2259 | posrec.yset = (int32_t)(y0+dy *fx * posrec.yset + addgap); |
2285 | posrec.yset = (int32_t)(y0+dy *fx * posrec.yset + addgap); |
2260 | } |
2286 | } |
2261 | if (gMIKRO_X) { |
2287 | if (gMIKRO_X) { |
Line 2273... | Line 2299... | ||
2273 | if (fmax && (ftell(gFp) > fmax)) { |
2299 | if (fmax && (ftell(gFp) > fmax)) { |
2274 | fcount+=1; |
2300 | fcount+=1; |
2275 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
2301 | sprintf(dfile,"%s_file%02d.dat",dfile0,fcount); |
2276 | fclose(gFp); |
2302 | fclose(gFp); |
2277 | gFp = fopen (dfile, "ab"); |
2303 | gFp = fopen (dfile, "ab"); |
2278 | } |
2304 | } |
2279 | time (&cas); |
2305 | time (&cas); |
2280 | posrec.time = (uint32_t) cas; |
2306 | posrec.time = (uint32_t) cas; |
2281 | status = (int) fwrite (&posrec, 1, posrec.len, gFp); |
2307 | status = (int) fwrite (&posrec, 1, posrec.len, gFp); |
2282 | } |
2308 | } |
2283 | 2309 | ||
Line 2286... | Line 2312... | ||
2286 | 2312 | ||
2287 | for (board=0; board<4; board++) { |
2313 | for (board=0; board<4; board++) { |
2288 | if (mask & (1<<board)) { |
2314 | if (mask & (1<<board)) { |
2289 | sa02Cmd( board, FEB_VTH1, runrec.ped, 0,0,1,response); |
2315 | sa02Cmd( board, FEB_VTH1, runrec.ped, 0,0,1,response); |
2290 | Sa02TestPulseEnable(board,tpenb); // Enable/disable test pulse |
2316 | Sa02TestPulseEnable(board,tpenb); // Enable/disable test pulse |
2291 | } |
2317 | } |
2292 | } |
2318 | } |
2293 | 2319 | ||
2294 | Sa02SetNeve(runrec.nev); |
2320 | Sa02SetNeve(runrec.nev); |
2295 | 2321 | ||
2296 | evtrec.nev=1; |
2322 | evtrec.nev=1; |
2297 | 2323 | ||
2298 | 2324 | ||
2299 | sa02Reset(); |
2325 | sa02Reset(); |
2300 | 2326 | ||
2301 | if (ctrl_c) break; |
2327 | if (ctrl_c) break; |
2302 | 2328 | ||
2303 | if ( (count+2+dsize) >= maxsize) { |
2329 | if ( (count+2+dsize) >= maxsize) { |
2304 | maxsize*=2; |
2330 | maxsize*=2; |
2305 | sa02Printf("Increasing data buffer to %d elements\n", maxsize); |
2331 | sa02Printf("Increasing data buffer to %d elements\n", maxsize); |
2306 | rdata=realloc(rdata ,sizeof(uint32_t)*maxsize); |
2332 | rdata=realloc(rdata ,sizeof(uint32_t)*maxsize); |
2307 | } |
2333 | } |
2308 | 2334 | ||
2309 | data = &rdata[count+2]; |
2335 | data = &rdata[count+2]; |
2310 | do { |
2336 | do { |
2311 | //int k; |
2337 | //int k; |
2312 | //uint32_t inputtriggers; |
2338 | //uint32_t inputtriggers; |
Line 2315... | Line 2341... | ||
2315 | /* |
2341 | /* |
2316 | for (k=0; k<4; k++) c[k] = Sa02GetCounter ( k ,&e[k]); |
2342 | for (k=0; k<4; k++) c[k] = Sa02GetCounter ( k ,&e[k]); |
2317 | for (k=0; k<4; k++) sa02Printf(" CNTR%d=%d (ERR=%d)\t",k,c[k],e[k]); |
2343 | for (k=0; k<4; k++) sa02Printf(" CNTR%d=%d (ERR=%d)\t",k,c[k],e[k]); |
2318 | sa02Printf("\nsa02Read bytes = %d mask=%d neve=%d (%d # %d)\n", nb, mask, runrec.nev, Sa02GetNeve( &inputtriggers ) , inputtriggers); |
2344 | sa02Printf("\nsa02Read bytes = %d mask=%d neve=%d (%d # %d)\n", nb, mask, runrec.nev, Sa02GetNeve( &inputtriggers ) , inputtriggers); |
2319 | */ |
2345 | */ |
- | 2346 | } |
|
2320 |
|
2347 | while ( nb==0 && !ctrl_c); |
2321 | 2348 | ||
2322 | 2349 | ||
2323 | 2350 | ||
2324 | if (sa02TimerOut || nb==0) sa02Printf("sa02TimerOut || nb==0\n"); |
2351 | if (sa02TimerOut || nb==0) sa02Printf("sa02TimerOut || nb==0\n"); |
2325 | 2352 | ||
2326 | for (ich=0; ich<144*4; ich++) { |
2353 | for (ich=0; ich<144*4; ich++) { |
2327 | int brd = ich/144; |
2354 | int brd = ich/144; |
2328 | int xch = 143 - ich%144; |
2355 | int xch = 143 - ich%144; |
Line 2334... | Line 2361... | ||
2334 | } |
2361 | } |
2335 | } |
2362 | } |
2336 | sa02Printf("max couts = %d %d %d %d\n", xyval[0],xyval[1],xyval[2],xyval[3]); |
2363 | sa02Printf("max couts = %d %d %d %d\n", xyval[0],xyval[1],xyval[2],xyval[3]); |
2337 | if (nb>=0) { |
2364 | if (nb>=0) { |
2338 | count+=module_header(0x3,&rdata[count],nb/sizeof(uint32_t)); |
2365 | count+=module_header(0x3,&rdata[count],nb/sizeof(uint32_t)); |
2339 | } |
2366 | } |
2340 | 2367 | ||
2341 | 2368 | ||
2342 | /* |
2369 | /* |
2343 | for (ich=0; ich<144; ich++) { |
2370 | for (ich=0; ich<144; ich++) { |
2344 | 2371 | ||
2345 | // uint32_t mask=0xFF; |
2372 | // uint32_t mask=0xFF; |
Line 2349... | Line 2376... | ||
2349 | id=(17-ich/8)+board*18; |
2376 | id=(17-ich/8)+board*18; |
2350 | shft=(ich%8)*4; |
2377 | shft=(ich%8)*4; |
2351 | if ( data[id] & (mask <<shft) ) { |
2378 | if ( data[id] & (mask <<shft) ) { |
2352 | H3DFillBin(hxy, posrec.ix,posrec.iy,ich,1); |
2379 | H3DFillBin(hxy, posrec.ix,posrec.iy,ich,1); |
2353 | H2DFillBin(hxy, posrec.ix,posrec.iy,1); |
2380 | H2DFillBin(hxy, posrec.ix,posrec.iy,1); |
2354 | } |
2381 | } |
2355 | } |
2382 | } |
2356 | */ |
2383 | */ |
2357 | if (dsave) { |
2384 | if (dsave) { |
2358 | if (Random(0,1)<fraction) { |
2385 | if (Random(0,1)<fraction) { |
2359 | writeevents=1; |
2386 | writeevents=1; |
- | 2387 | } |
|
2360 |
|
2388 | else { |
2361 | writeevents=0; |
2389 | writeevents=0; |
2362 | } |
2390 | } |
2363 | if (writeevents) { |
2391 | if (writeevents) { |
2364 | evtrec.id = EVTREC_ID; |
2392 | evtrec.id = EVTREC_ID; |
2365 | evtrec.len=count*sizeof(uint32_t)+ sizeof(evtrec); |
2393 | evtrec.len=count*sizeof(uint32_t)+ sizeof(evtrec); |
2366 | 2394 | ||
Line 2390... | Line 2418... | ||
2390 | EstimatedFinish(p2h, P2_PROGRESS, P2_ETA, t0, done); |
2418 | EstimatedFinish(p2h, P2_PROGRESS, P2_ETA, t0, done); |
2391 | GetCtrlVal(p2h,P2_CH, &ch); |
2419 | GetCtrlVal(p2h,P2_CH, &ch); |
2392 | for (board=0; board<4; board++) { |
2420 | for (board=0; board<4; board++) { |
2393 | if (ch) { |
2421 | if (ch) { |
2394 | H3DDrawSliceXY(hxy+board,ch,p2h, p2graph[board], &p2plothandle[board]); |
2422 | H3DDrawSliceXY(hxy+board,ch,p2h, p2graph[board], &p2plothandle[board]); |
- | 2423 | } |
|
2395 |
|
2424 | else { |
2396 | H2DDraw(hxy+board,p2h, p2graph[board], &p2plothandle[board]); |
2425 | H2DDraw(hxy+board,p2h, p2graph[board], &p2plothandle[board]); |
2397 | } |
2426 | } |
2398 | } |
2427 | } |
2399 | ProcessSystemEvents (); |
2428 | ProcessSystemEvents (); |
2400 | SetCtrlVal(p2h,P2_CEVE, i); |
2429 | SetCtrlVal(p2h,P2_CEVE, i); |
2401 | sa02Printf("%d events in %2.2f min (%d s) %s",ncount, (double)(t-tstart)/60.,t-tstart, ctime(&t)); |
2430 | sa02Printf("%d events in %2.2f min (%d s) %s",ncount, (double)(t-tstart)/60.,t-tstart, ctime(&t)); |
2402 | 2431 | ||
2403 | } |
2432 | } |
2404 | told=t; |
2433 | told=t; |
2405 | 2434 | ||
2406 | 2435 | ||
2407 | 2436 | ||
Line 2461... | Line 2490... | ||
2461 | monrec.status[i] = buf[0]; //status |
2490 | monrec.status[i] = buf[0]; //status |
2462 | monrec.vmon[i] = buf[1]*1000;//zapisano v mV |
2491 | monrec.vmon[i] = buf[1]*1000;//zapisano v mV |
2463 | monrec.imon[i] = buf[2]*1000;//zapisano v nA |
2492 | monrec.imon[i] = buf[2]*1000;//zapisano v nA |
2464 | monrec.vset[i] = buf[3]*1000;//zapisano v mV |
2493 | monrec.vset[i] = buf[3]*1000;//zapisano v mV |
2465 | monrec.iset[i] = buf[4]*1000;//zapisano v nA |
2494 | monrec.iset[i] = buf[4]*1000;//zapisano v nA |
- | 2495 | } |
|
2466 |
|
2496 | else { |
2467 | buf[0]=(unsigned short) (channels[i]<<8) | ReadStatus; |
2497 | buf[0]=(unsigned short) (channels[i]<<8) | ReadStatus; |
2468 | if (gCAEN_V288) { |
2498 | if (gCAEN_V288) { |
2469 | V288_Send(0,SYS403mid,1,buf); |
2499 | V288_Send(0,SYS403mid,1,buf); |
2470 | odg=V288_Receive(0,255,buf); |
2500 | odg=V288_Receive(0,255,buf); |
2471 | } |
2501 | } |
2472 | monrec.vmon[i] = buf[1]*10;//zapisano v mV |
2502 | monrec.vmon[i] = buf[1]*10;//zapisano v mV |
2473 | monrec.imon[i] = buf[2]*10;//zapisano v nA |
2503 | monrec.imon[i] = buf[2]*10;//zapisano v nA |
2474 | monrec.status[i] = buf[3]; //status |
2504 | monrec.status[i] = buf[3]; //status |
2475 | if(!hvmonFirst) { |
2505 | if(!hvmonFirst) { |
2476 | buf[0]=(unsigned short) (channels[i]<<8) | ReadParameters; |
2506 | buf[0]=(unsigned short) (channels[i]<<8) | ReadParameters; |
Line 2486... | Line 2516... | ||
2486 | } |
2516 | } |
2487 | sa02Printf("%04x \t %.02f V \t %d V \t\t %.02f muA \t %d muA *\n",monrec.status[i],(float)monrec.vmon[i]/1000,monrec.vset[i]/1000,(float)monrec.imon[i]/1000,monrec.iset[i]/1000); |
2517 | sa02Printf("%04x \t %.02f V \t %d V \t\t %.02f muA \t %d muA *\n",monrec.status[i],(float)monrec.vmon[i]/1000,monrec.vset[i]/1000,(float)monrec.imon[i]/1000,monrec.iset[i]/1000); |
2488 | } |
2518 | } |
2489 | time (&t1); |
2519 | time (&t1); |
2490 | sa02Printf("Cas izvedbe:%g s.\n",difftime(t1,t0)); |
2520 | sa02Printf("Cas izvedbe:%g s.\n",difftime(t1,t0)); |
2491 | 2521 | ||
2492 | return 0; |
2522 | return 0; |
2493 | } |
2523 | } |
2494 | 2524 | ||
2495 | int CVICALLBACK set_dac(int OnOff) { |
2525 | int CVICALLBACK set_dac(int OnOff) { |
2496 | int val; |
2526 | int val; |
2497 | char name[MAX_PATHNAME_LEN]; |
2527 | char name[MAX_PATHNAME_LEN]; |
2498 | if (OnOff) { |
2528 | if (OnOff) { |
2499 | GetCtrlVal (p5h, P5_DAC_ON, &val); |
2529 | GetCtrlVal (p5h, P5_DAC_ON, &val); |
2500 | sprintf(name ,"%s -p %d",palaser, val); |
2530 | sprintf(name ,"%s -p %d",palaser, val); |
2501 | sa02Printf("%s\n", name); |
2531 | sa02Printf("%s\n", name); |
2502 | system(name); |
2532 | system(name); |
2503 | GetCtrlVal (p5h, P5_FREQUENCY_ON, &val); |
2533 | GetCtrlVal (p5h, P5_FREQUENCY_ON, &val); |
2504 | sprintf(name ,"%s -f %d",palaser, val); |
2534 | sprintf(name ,"%s -f %d",palaser, val); |
2505 | sa02Printf("%s\n", name); |
2535 | sa02Printf("%s\n", name); |
2506 | system(name); |
2536 | system(name); |
- | 2537 | } |
|
2507 |
|
2538 | else { |
2508 | GetCtrlVal (p5h, P5_DAC_OFF, &val); |
2539 | GetCtrlVal (p5h, P5_DAC_OFF, &val); |
2509 | sprintf(name ,"%s -p %d",palaser, val); |
2540 | sprintf(name ,"%s -p %d",palaser, val); |
2510 | sa02Printf("%s\n", name); |
2541 | sa02Printf("%s\n", name); |
2511 | system(name); |
2542 | system(name); |
2512 | GetCtrlVal (p5h, P5_FREQUENCY_OFF, &val); |
2543 | GetCtrlVal (p5h, P5_FREQUENCY_OFF, &val); |
Line 2537... | Line 2568... | ||
2537 | if((buf[0]&0x20)&&(buf[0]&0x20)) sa02Printf("Channel is ramping up \t Vmon: %d V \t Vset: %d \t status: 0x%x\n",buf[1],buf[3],buf[0]); |
2568 | if((buf[0]&0x20)&&(buf[0]&0x20)) sa02Printf("Channel is ramping up \t Vmon: %d V \t Vset: %d \t status: 0x%x\n",buf[1],buf[3],buf[0]); |
2538 | else if(buf[0]&0x40) sa02Printf("Channel is ramping down \t Vmon: %d V \t Vset: %d \t status: 0x%x\n",buf[1],buf[3],buf[0]); |
2569 | else if(buf[0]&0x40) sa02Printf("Channel is ramping down \t Vmon: %d V \t Vset: %d \t status: 0x%x\n",buf[1],buf[3],buf[0]); |
2539 | else if(buf[0]&0x1E) { |
2570 | else if(buf[0]&0x1E) { |
2540 | sa02Printf("status: 0x%x\n",buf[0]); |
2571 | sa02Printf("status: 0x%x\n",buf[0]); |
2541 | return -1; |
2572 | return -1; |
- | 2573 | } |
|
2542 |
|
2574 | else sa02Printf("status: 0x%x\n",buf[0]); |
2543 | Delay(2); |
2575 | Delay(2); |
2544 | buf[0]=(unsigned short) (channel<<8) | ReadOperationalParam; |
2576 | buf[0]=(unsigned short) (channel<<8) | ReadOperationalParam; |
2545 | V288_Send(0,N470mid,1,buf); |
2577 | V288_Send(0,N470mid,1,buf); |
2546 | ret=V288_Receive(0,255,buf); |
2578 | ret=V288_Receive(0,255,buf); |
2547 | } |
2579 | } |
Line 2709... | Line 2741... | ||
2709 | LoadParameters(p3h, P3_LOADPAR, EVENT_COMMIT, NULL, 0, 0); // load parameters from defaul.param to FEB |
2741 | LoadParameters(p3h, P3_LOADPAR, EVENT_COMMIT, NULL, 0, 0); // load parameters from defaul.param to FEB |
2710 | ProcessSystemEvents (); |
2742 | ProcessSystemEvents (); |
2711 | LoadParameters(p3h, P3_LOADPAR, EVENT_COMMIT, NULL, 0, 0); // load parameters from defaul.param to FEB |
2743 | LoadParameters(p3h, P3_LOADPAR, EVENT_COMMIT, NULL, 0, 0); // load parameters from defaul.param to FEB |
2712 | ProcessSystemEvents (); |
2744 | ProcessSystemEvents (); |
2713 | LoadParameters(p3h, P3_LOADPAR, EVENT_COMMIT, NULL, 0, 0); // load parameters from defaul.param to FEB |
2745 | LoadParameters(p3h, P3_LOADPAR, EVENT_COMMIT, NULL, 0, 0); // load parameters from defaul.param to FEB |
2714 | ProcessSystemEvents (); |
2746 | ProcessSystemEvents (); |
2715 | 2747 | ||
2716 | /****** MicroMini calibration ******/ |
2748 | /****** MicroMini calibration ******/ |
2717 | sa02Printf("Calibration *\n\n"); |
2749 | sa02Printf("Calibration *\n\n"); |
2718 | SetHome(p2h, P2_HO,EVENT_COMMIT,NULL, 0, 0); |
2750 | SetHome(p2h, P2_HO,EVENT_COMMIT,NULL, 0, 0); |
2719 | SetCtrlVal(p2h,P2_XC,gCENTER_X); |
2751 | SetCtrlVal(p2h,P2_XC,gCENTER_X); |
2720 | SetCtrlVal(p2h,P2_YC,gCENTER_Y); |
2752 | SetCtrlVal(p2h,P2_YC,gCENTER_Y); |
2721 | 2753 | ||
2722 | /****** Reads run number ******/ |
2754 | /****** Reads run number ******/ |
2723 | fp = fopen ("CompleteScan_RunNumber.txt","r"); |
2755 | fp = fopen ("CompleteScan_RunNumber.txt","r"); |
2724 | if (fp) { |
2756 | if (fp) { |
2725 | if (fgets(line,ndim,fp)!= NULL) current_run = atoi(line)+1; |
2757 | if (fgets(line,ndim,fp)!= NULL) current_run = atoi(line)+1; |
2726 | fclose(fp); |
2758 | fclose(fp); |
2727 | fp = NULL; |
2759 | fp = NULL; |
2728 | } |
2760 | } |
2729 | ProcessSystemEvents (); |
2761 | ProcessSystemEvents (); |
2730 | 2762 | ||
2731 | /****** Slow Control ******/ |
2763 | /****** Slow Control ******/ |
2732 | sprintf(line,"%04d_SlowControl.xml",current_run); |
2764 | sprintf(line,"%04d_SlowControl.xml",current_run); |
Line 2910... | Line 2942... | ||
2910 | 2942 | ||
2911 | daq_scan(NULL); |
2943 | daq_scan(NULL); |
2912 | 2944 | ||
2913 | sprintf(cmdCommand,"cmd.exe /c mkdir ..\\modules\\%04d & ..\\sa02read -i %s_file01.dat -o ..\\modules\\%04d\\%s.root", |
2945 | sprintf(cmdCommand,"cmd.exe /c mkdir ..\\modules\\%04d & ..\\sa02read -i %s_file01.dat -o ..\\modules\\%04d\\%s.root", |
2914 | current_run, line, current_run, buf); |
2946 | current_run, line, current_run, buf); |
2915 | LaunchExecutable(cmdCommand); |
2947 | LaunchExecutable(cmdCommand); |
- | 2948 | ||
2916 | 2949 | ||
2917 | 2950 | ||
2918 | - | ||
2919 | /****** 2D v X ******/ |
2951 | /****** 2D v X ******/ |
2920 | // Panel 2 settings |
2952 | // Panel 2 settings |
2921 | SetCtrlVal (p2h, P2_SCANUNITSX, 0); // Continuous scan over X (1 Ch, 0 Step) |
2953 | SetCtrlVal (p2h, P2_SCANUNITSX, 0); // Continuous scan over X (1 Ch, 0 Step) |
2922 | SetCtrlVal (p2h, P2_NX, 380/2); // Noumber of steps = 380 |
2954 | SetCtrlVal (p2h, P2_NX, 380/2); // Noumber of steps = 380 |
2923 | SetCtrlVal (p2h, P2_XSTEP, 2*500); // Step size = 500 |
2955 | SetCtrlVal (p2h, P2_XSTEP, 2*500); // Step size = 500 |
Line 2925... | Line 2957... | ||
2925 | SetCtrlVal (p2h, P2_SCANUNITSY, 1); // Only over the channel centers (1 Ch, 0 Step) |
2957 | SetCtrlVal (p2h, P2_SCANUNITSY, 1); // Only over the channel centers (1 Ch, 0 Step) |
2926 | SetCtrlVal (p2h, P2_NY, 12); // Noumber of steps = 12 |
2958 | SetCtrlVal (p2h, P2_NY, 12); // Noumber of steps = 12 |
2927 | SetCtrlVal (p2h, P2_YSTEP, 1); // Step size = 1 |
2959 | SetCtrlVal (p2h, P2_YSTEP, 1); // Step size = 1 |
2928 | SetCtrlVal (p2h, P2_YMIN, 0); // Start position = 0 |
2960 | SetCtrlVal (p2h, P2_YMIN, 0); // Start position = 0 |
2929 | SetCtrlVal (p2h, P2_DIRECTION, 1); // Set Y then scan X = 1 |
2961 | SetCtrlVal (p2h, P2_DIRECTION, 1); // Set Y then scan X = 1 |
2930 | 2962 | ||
2931 | SetCtrlVal (p2h, P2_NEVE, 1000); // Number of events for position scan |
2963 | SetCtrlVal (p2h, P2_NEVE, 1000); // Number of events for position scan |
2932 | SetCtrlVal (p2h, P2_PEDESTAL, ithr); // Treshold |
2964 | SetCtrlVal (p2h, P2_PEDESTAL, ithr); // Treshold |
2933 | 2965 | ||
2934 | SetCtrlVal (p2h, P2_DAQEXE, 0); // Execute at each position: nothing |
2966 | SetCtrlVal (p2h, P2_DAQEXE, 0); // Execute at each position: nothing |
2935 | 2967 | ||
2936 | sprintf(buf,"%04d_2_2DX",current_run); |
2968 | sprintf(buf,"%04d_2_2DX",current_run); |
2937 | sprintf(line,"..\\modules\\%s", buf); |
2969 | sprintf(line,"..\\modules\\%s", buf); |
2938 | SetCtrlVal (p2h, P2_DFILE, line); |
2970 | SetCtrlVal (p2h, P2_DFILE, line); |
2939 | 2971 | ||
2940 | 2972 | ||
2941 | daq_scan(NULL); |
2973 | daq_scan(NULL); |
2942 | 2974 | ||
Line 2953... | Line 2985... | ||
2953 | SetCtrlVal (p2h, P2_SCANUNITSY, 0); // Continuous scan over Y (1 Ch, 0 Step) |
2985 | SetCtrlVal (p2h, P2_SCANUNITSY, 0); // Continuous scan over Y (1 Ch, 0 Step) |
2954 | SetCtrlVal (p2h, P2_NY, 380/2); // Noumber of steps = 380 |
2986 | SetCtrlVal (p2h, P2_NY, 380/2); // Noumber of steps = 380 |
2955 | SetCtrlVal (p2h, P2_YSTEP, 2*500); // Step size = 500 |
2987 | SetCtrlVal (p2h, P2_YSTEP, 2*500); // Step size = 500 |
2956 | SetCtrlVal (p2h, P2_YMIN, 75000); // Start position = 7500 |
2988 | SetCtrlVal (p2h, P2_YMIN, 75000); // Start position = 7500 |
2957 | SetCtrlVal (p2h, P2_DIRECTION, 0); // Set X then scan Y = 0 |
2989 | SetCtrlVal (p2h, P2_DIRECTION, 0); // Set X then scan Y = 0 |
2958 | 2990 | ||
2959 | SetCtrlVal (p2h, P2_NEVE, 1000); // Number of events for position scan |
2991 | SetCtrlVal (p2h, P2_NEVE, 1000); // Number of events for position scan |
2960 | SetCtrlVal (p2h, P2_PEDESTAL, ithr); // Treshold |
2992 | SetCtrlVal (p2h, P2_PEDESTAL, ithr); // Treshold |
2961 | 2993 | ||
2962 | SetCtrlVal (p2h, P2_DAQEXE, 0); // Execute at each position: nothing |
2994 | SetCtrlVal (p2h, P2_DAQEXE, 0); // Execute at each position: nothing |
2963 | 2995 | ||
Line 2967... | Line 2999... | ||
2967 | 2999 | ||
2968 | 3000 | ||
2969 | daq_scan(NULL); |
3001 | daq_scan(NULL); |
2970 | 3002 | ||
2971 | sprintf(cmdCommand,"cmd.exe /c mkdir ..\\modules\\%04d & ..\\sa02read -i %s_file01.dat -o ..\\modules\\%04d\\%s.root ", current_run, line, current_run, buf); |
3003 | sprintf(cmdCommand,"cmd.exe /c mkdir ..\\modules\\%04d & ..\\sa02read -i %s_file01.dat -o ..\\modules\\%04d\\%s.root ", current_run, line, current_run, buf); |
2972 | system(cmdCommand); // wait here to finish to proceed to next step |
3004 | system(cmdCommand); // wait here to finish to proceed to next step |
2973 | 3005 | ||
2974 | sprintf(cmdCommand,"cmd.exe /c ..\\thisroot.bat & cd analysis & root script.c(%d)",current_run); |
3006 | sprintf(cmdCommand,"cmd.exe /c ..\\thisroot.bat & cd analysis & root script.c(%d)",current_run); |
2975 | LaunchExecutable(cmdCommand); |
3007 | LaunchExecutable(cmdCommand); |
2976 | 3008 | ||
2977 | SetCtrlVal (p2h, P2_ZSET, 300000); |
3009 | SetCtrlVal (p2h, P2_ZSET, 300000); |
2978 | SetCtrlVal (p2h, P2_XC, (uint32_t)(gCENTER_KX*0+gCENTER_X)); |
3010 | SetCtrlVal (p2h, P2_XC, (uint32_t)(gCENTER_KX*0+gCENTER_X)); |
Line 3040... | Line 3072... | ||
3040 | strcpy(gUirCtrlMap[gNUirCtrlMap].name, ctrl ); |
3072 | strcpy(gUirCtrlMap[gNUirCtrlMap].name, ctrl ); |
3041 | if (gNUirCtrlMap<MAX_UIRCTRLMAP_SIZE) { |
3073 | if (gNUirCtrlMap<MAX_UIRCTRLMAP_SIZE) { |
3042 | gUirCtrlMap[gNUirCtrlMap].id = ctrlid; |
3074 | gUirCtrlMap[gNUirCtrlMap].id = ctrlid; |
3043 | gUirCtrlMap[gNUirCtrlMap].handle = GetPanelHandle(ctrl); |
3075 | gUirCtrlMap[gNUirCtrlMap].handle = GetPanelHandle(ctrl); |
3044 | gNUirCtrlMap++; |
3076 | gNUirCtrlMap++; |
- | 3077 | } |
|
3045 |
|
3078 | else { |
3046 | sa02Printf("ERROR: Increase gNUirCtrlMap\n"); |
3079 | sa02Printf("ERROR: Increase gNUirCtrlMap\n"); |
3047 | } |
3080 | } |
3048 | } |
3081 | } |
3049 | } |
3082 | } |
3050 | fclose(fp); |
3083 | fclose(fp); |
Line 3086... | Line 3119... | ||
3086 | cache_sz_inc *= cache_sz_inc_factor; |
3119 | cache_sz_inc *= cache_sz_inc_factor; |
3087 | if (cache_sz_inc > cache_sz_inc_max) { |
3120 | if (cache_sz_inc > cache_sz_inc_max) { |
3088 | cache_sz_inc = cache_sz_inc_max; |
3121 | cache_sz_inc = cache_sz_inc_max; |
3089 | } |
3122 | } |
3090 | } |
3123 | } |
3091 | 3124 | ||
3092 | pos_cache[count-1] = pstr2 - str; |
3125 | pos_cache[count-1] = pstr2 - str; |
3093 | pstr = pstr2 + oldlen; |
3126 | pstr = pstr2 + oldlen; |
3094 | } |
3127 | } |
3095 | 3128 | ||
3096 | orglen = pstr - str + strlen(pstr); |
3129 | orglen = pstr - str + strlen(pstr); |
3097 | 3130 | ||
3098 | /* Allocate memory for the post-replacement string. */ |
3131 | /* Allocate memory for the post-replacement string. */ |
3099 | if (count > 0) { |
3132 | if (count > 0) { |
3100 | newlen = strlen(new); |
3133 | newlen = strlen(new); |
3101 | retlen = orglen + (newlen - oldlen) * count; |
3134 | retlen = orglen + (newlen - oldlen) * count; |
- | 3135 | } |
|
3102 |
|
3136 | else retlen = orglen; |
3103 | ret = malloc(retlen + 1); |
3137 | ret = malloc(retlen + 1); |
3104 | if (ret == NULL) { |
3138 | if (ret == NULL) { |
3105 | goto end_repl_str; |
3139 | goto end_repl_str; |
3106 | } |
3140 | } |
3107 | 3141 | ||
3108 | if (count == 0) { |
3142 | if (count == 0) { |
3109 | /* If no matches, then just duplicate the string. */ |
3143 | /* If no matches, then just duplicate the string. */ |
3110 | strcpy(ret, str); |
3144 | strcpy(ret, str); |
- | 3145 | } |
|
3111 |
|
3146 | else { |
3112 | /* Otherwise, duplicate the string whilst performing |
3147 | /* Otherwise, duplicate the string whilst performing |
3113 | * the replacements using the position cache. */ |
3148 | * the replacements using the position cache. */ |
3114 | pret = ret; |
3149 | pret = ret; |
3115 | memcpy(pret, str, pos_cache[0]); |
3150 | memcpy(pret, str, pos_cache[0]); |
3116 | pret += pos_cache[0]; |
3151 | pret += pos_cache[0]; |
Line 3135... | Line 3170... | ||
3135 | 3170 | ||
3136 | int CVICALLBACK run_script(void *functionData) { |
3171 | int CVICALLBACK run_script(void *functionData) { |
3137 | FILE *fp = NULL; |
3172 | FILE *fp = NULL; |
3138 | FILE *fpout =NULL; |
3173 | FILE *fpout =NULL; |
3139 | 3174 | ||
3140 | 3175 | ||
3141 | char *line; |
3176 | char *line; |
3142 | char buf[MAX_PATHNAME_LEN]; |
3177 | char buf[MAX_PATHNAME_LEN]; |
3143 | int status; |
3178 | int status; |
3144 | char type[MAX_PATHNAME_LEN]; |
3179 | char type[MAX_PATHNAME_LEN]; |
3145 | char param[MAX_PATHNAME_LEN]; |
3180 | char param[MAX_PATHNAME_LEN]; |
Line 3161... | Line 3196... | ||
3161 | if (!fp) { |
3196 | if (!fp) { |
3162 | sa02Printf("Error! Cannot open script file %s\n",scriptname); |
3197 | sa02Printf("Error! Cannot open script file %s\n",scriptname); |
3163 | return -1; |
3198 | return -1; |
3164 | } |
3199 | } |
3165 | while (fgets(buf,MAX_PATHNAME_LEN,fp)!=NULL ) { |
3200 | while (fgets(buf,MAX_PATHNAME_LEN,fp)!=NULL ) { |
3166 | 3201 | ||
3167 | if (buf[0]!='#' && strlen(buf)>2) { |
3202 | if (buf[0]!='#' && strlen(buf)>2) { |
3168 | if (strstr(buf, "%RUN%")!=NULL) { |
3203 | if (strstr(buf, "%RUN%")!=NULL) { |
3169 |
|
3204 | char srun[16]; |
3170 |
|
3205 | sprintf(srun,"%04d",runno); |
3171 |
|
3206 | line = str_replace(buf,"%RUN%", srun); |
3172 | } else { |
- | |
3173 | line = buf; |
- | |
3174 | } |
3207 | } |
- | 3208 | else { |
|
- | 3209 | line = buf; |
|
- | 3210 | } |
|
3175 | sa02Printf("#[%d] %s",strlen(buf),buf); |
3211 | sa02Printf("#[%d] %s",strlen(buf),buf); |
3176 | 3212 | ||
3177 | sscanf(line,"%s",type); |
3213 | sscanf(line,"%s",type); |
3178 | 3214 | ||
3179 | if (strstr(type,"SetCtrlVal")!=NULL) { |
3215 | if (strstr(type,"SetCtrlVal")!=NULL) { |
3180 | int pID; |
3216 | int pID; |
3181 | int rID; |
3217 | int rID; |
3182 | int datatype; |
3218 | int datatype; |
3183 | sscanf(line,"%*s%s%s",param,paramValue); |
3219 | sscanf(line,"%*s%s%s",param,paramValue); |
3184 | 3220 | ||
3185 | pID= GetPanelHandle(param); |
3221 | pID= GetPanelHandle(param); |
3186 | rID= GetControlID(param); |
3222 | rID= GetControlID(param); |
3187 | if (rID>0 && pID>0) { |
3223 | if (rID>0 && pID>0) { |
3188 | GetCtrlAttribute (pID, rID, ATTR_DATA_TYPE, &datatype); |
3224 | GetCtrlAttribute (pID, rID, ATTR_DATA_TYPE, &datatype); |
3189 | 3225 | ||
3190 | switch (datatype){ |
3226 | switch (datatype) { |
- | 3227 | case VAL_INTEGER: |
|
3191 |
|
3228 | SetCtrlVal (pID, rID, atoi(paramValue)); |
- | 3229 | break; |
|
- | 3230 | case VAL_UNSIGNED_INTEGER: |
|
3192 |
|
3231 | SetCtrlVal (pID, rID, strtoul(paramValue,NULL,0)); |
- | 3232 | break; |
|
- | 3233 | case VAL_SHORT_INTEGER: |
|
3193 |
|
3234 | SetCtrlVal (pID, rID, atoi(paramValue)); |
- | 3235 | break; |
|
- | 3236 | case VAL_UNSIGNED_SHORT_INTEGER: |
|
3194 |
|
3237 | SetCtrlVal (pID, rID, strtoul(paramValue,NULL,0)); |
- | 3238 | break; |
|
- | 3239 | case VAL_DOUBLE : |
|
3195 |
|
3240 | SetCtrlVal (pID, rID, atof(paramValue)); |
- | 3241 | break; |
|
- | 3242 | case VAL_STRING : |
|
3196 |
|
3243 | SetCtrlVal (pID, rID, paramValue ); |
- | 3244 | break; |
|
- | 3245 | default: |
|
3197 |
|
3246 | sa02Printf("[%s] ATTR_DATA_TYPE of the %s not supported datatype %d p4h=%d\n\n", type, param, datatype, p4h); |
3198 | } |
3247 | } |
3199 | //sa02Printf("[%s] SetCtrlVal %s %s panel=%d control=%d\n",type,param, paramValue,pID,rID); |
3248 | //sa02Printf("[%s] SetCtrlVal %s %s panel=%d control=%d\n",type,param, paramValue,pID,rID); |
- | 3249 | } |
|
3200 |
|
3250 | else { |
3201 |
|
3251 | sa02Printf("[%s] Invalid Ctrl %s %s panel=%d control=%d\n",type,param, paramValue,pID,rID); |
3202 | } |
3252 | } |
- | 3253 | ||
3203 | 3254 | } |
|
3204 |
|
3255 | else if (strstr(type,"2D")!=NULL) { |
3205 | sscanf(line,"%*s%d%d%d%d%d%d%d%d%d%d%d%s",&scx,&nx,&xstep,&xmin,&scy,&ny,&ystep,&ymin,&direction,&nevents,&tresh,outputFileSuffix); |
3256 | sscanf(line,"%*s%d%d%d%d%d%d%d%d%d%d%d%s",&scx,&nx,&xstep,&xmin,&scy,&ny,&ystep,&ymin,&direction,&nevents,&tresh,outputFileSuffix); |
3206 | sprintf(test,"%d %d %d %d %d %d %d %d %d %d %d %s *\n",scx,nx,xstep,xmin,scy,ny,ystep,ymin,direction,nevents,tresh,outputFileSuffix); |
3257 | sprintf(test,"%d %d %d %d %d %d %d %d %d %d %d %s *\n",scx,nx,xstep,xmin,scy,ny,ystep,ymin,direction,nevents,tresh,outputFileSuffix); |
3207 | sa02Printf("%s *\n\n",test); |
3258 | sa02Printf("%s *\n\n",test); |
3208 | SetCtrlVal (p2h, P2_SCANUNITSX, scx); |
3259 | SetCtrlVal (p2h, P2_SCANUNITSX, scx); |
3209 | SetCtrlVal (p2h, P2_NX, nx); |
3260 | SetCtrlVal (p2h, P2_NX, nx); |
Line 3223... | Line 3274... | ||
3223 | SetCtrlVal (p2h, P2_DFILE, outputFile); |
3274 | SetCtrlVal (p2h, P2_DFILE, outputFile); |
3224 | 3275 | ||
3225 | 3276 | ||
3226 | daq_scan(NULL); |
3277 | daq_scan(NULL); |
3227 | 3278 | ||
- | 3279 | } |
|
3228 |
|
3280 | else if (strstr(type,"Delay")!=NULL) { |
3229 | int idelay=0; |
3281 | int idelay=0; |
3230 | sscanf(line,"%*s%s",paramValue); |
3282 | sscanf(line,"%*s%s",paramValue); |
3231 | for (idelay=atoi(paramValue) ; idelay>0; idelay--) { |
3283 | for (idelay=atoi(paramValue) ; idelay>0; idelay--) { |
3232 | Delay(1); |
3284 | Delay(1); |
3233 | SetCtrlVal(p1h, P1_DELAY, idelay); |
3285 | SetCtrlVal(p1h, P1_DELAY, idelay); |
3234 | ProcessSystemEvents(); |
3286 | ProcessSystemEvents(); |
3235 | if (ctrl_c) break; |
3287 | if (ctrl_c) break; |
3236 | } |
3288 | } |
- | 3289 | } |
|
3237 |
|
3290 | else if (strstr(type,"ThresholdLinearity")!=NULL) { |
3238 | char *fname; |
3291 | char *fname; |
3239 | uint16_t mask = GetConnectedFebMask(); |
3292 | uint16_t mask = GetConnectedFebMask(); |
3240 | 3293 | ||
3241 | sscanf(line,"%*s%s",paramValue); |
3294 | sscanf(line,"%*s%s",paramValue); |
3242 | fname = paramValue; |
3295 | fname = paramValue; |
3243 | 3296 | ||
3244 | 3297 | ||
3245 | ThresholdLinearityCB (p1h, P1_THRVSADC, EVENT_COMMIT, NULL, 0, 0 ); |
3298 | ThresholdLinearityCB (p1h, P1_THRVSADC, EVENT_COMMIT, NULL, 0, 0 ); |
3246 | fpout = fopen(fname,"ab"); |
3299 | fpout = fopen(fname,"ab"); |
3247 | if(fpout) { |
3300 | if(fpout) { |
3248 | for (int board=0; board<4; board++) if ( mask &(1<<board)) H1DWrite2File(board,fpout); |
3301 | for (int board=0; board<4; board++) if ( mask &(1<<board)) H1DWrite2File(board,fpout); |
3249 | fclose(fpout); |
3302 | fclose(fpout); |
3250 | } |
3303 | } |
3251 | 3304 | ||
- | 3305 | } |
|
3252 |
|
3306 | else if (strstr(type,"LaunchExecutable")!=NULL) { |
3253 | int index = FindPattern (line, 0, -1, "LaunchExecutable", 0, 0) + 17; |
3307 | int index = FindPattern (line, 0, -1, "LaunchExecutable", 0, 0) + 17; |
3254 | 3308 | ||
3255 | char *cmd = &line[index]; |
3309 | char *cmd = &line[index]; |
3256 | sa02Printf("cmd %d=%s\n",index, cmd); |
3310 | sa02Printf("cmd %d=%s\n",index, cmd); |
3257 | if (strlen(cmd)>0) LaunchExecutable( cmd ); |
3311 | if (strlen(cmd)>0) LaunchExecutable( cmd ); |
- | 3312 | } |
|
3258 |
|
3313 | else if (strstr(type,"CAEN_V729")!=NULL) { |
3259 | char *fname; |
3314 | char *fname; |
3260 | //FILE *fpmon=NULL; |
3315 | //FILE *fpmon=NULL; |
3261 | 3316 | ||
3262 | sscanf(line,"%*s%s",paramValue); |
3317 | sscanf(line,"%*s%s",paramValue); |
3263 | fname=paramValue; |
3318 | fname=paramValue; |
3264 | 3319 | ||
3265 | fpout = fopen(fname,"ab"); |
3320 | fpout = fopen(fname,"ab"); |
3266 | if (fpout) { |
3321 | if (fpout) { |
3267 | 3322 | ||
3268 | V729_SetFilePointer(fpout); |
3323 | V729_SetFilePointer(fpout); |
3269 | V729_daq(NULL); |
3324 | V729_daq(NULL); |
3270 | fclose(fpout); |
3325 | fclose(fpout); |
3271 | } |
3326 | } |
- | 3327 | } |
|
3272 |
|
3328 | else if (strstr(type,"HvMonitor")!=NULL) { |
3273 | int nrepetitions; |
3329 | int nrepetitions; |
3274 | int delaytime; |
3330 | int delaytime; |
3275 | int k=0; |
3331 | int k=0; |
3276 | FILE *fpmon=NULL; |
3332 | FILE *fpmon=NULL; |
3277 | sscanf(line,"%*s%s%d%d",paramValue, &delaytime, &nrepetitions ); |
3333 | sscanf(line,"%*s%s%d%d",paramValue, &delaytime, &nrepetitions ); |
3278 | fpmon = fopen(paramValue,"ab"); |
3334 | fpmon = fopen(paramValue,"ab"); |
3279 | 3335 | ||
3280 | if ( fpmon ) { |
3336 | if ( fpmon ) { |
3281 | hvmonFirst = 0; |
3337 | hvmonFirst = 0; |
3282 | for (k=0; k<nrepetitions; k++) { |
3338 | for (k=0; k<nrepetitions; k++) { |
3283 | double thv0,thv1; |
3339 | double thv0,thv1; |
3284 | thv0 = Timer(); |
3340 | thv0 = Timer(); |
3285 | GetHvMonitor(); |
3341 | GetHvMonitor(); |
3286 | for (int board=0;board<4;board++){ |
3342 | for (int board=0; board<4; board++) { |
3287 | double sdata[12]; |
3343 | double sdata[12]; |
3288 | for (int k=0;k<6;k++){ |
3344 | for (int k=0; k<6; k++) { |
3289 |
|
3345 | sdata[k] = monrec.imon[k+4*board]; |
3290 |
|
3346 | sdata[k+6] = 0; |
3291 | } |
3347 | } |
3292 | 3348 | ||
3293 | SetAxisScalingMode (p1h, chart_control[board], VAL_LEFT_YAXIS, VAL_AUTOSCALE, 0, 1); |
3349 | SetAxisScalingMode (p1h, chart_control[board], VAL_LEFT_YAXIS, VAL_AUTOSCALE, 0, 1); |
3294 | SetAxisScalingMode (p1h, chart_control[board], VAL_RIGHT_YAXIS, VAL_AUTOSCALE, 0, 1); |
3350 | SetAxisScalingMode (p1h, chart_control[board], VAL_RIGHT_YAXIS, VAL_AUTOSCALE, 0, 1); |
3295 | PlotStripChart (p1h, chart_control[board], sdata, 12, 0, 0, VAL_DOUBLE); |
3351 | PlotStripChart (p1h, chart_control[board], sdata, 12, 0, 0, VAL_DOUBLE); |
3296 | } |
3352 | } |
3297 | monrec.id = MONREC_ID; |
3353 | monrec.id = MONREC_ID; |
3298 | monrec.len = sizeof(monrec); |
3354 | monrec.len = sizeof(monrec); |
3299 | thv1=Timer(); |
3355 | thv1=Timer(); |
3300 | status = (int) fwrite( &monrec, 1, sizeof(monrec),fpmon); |
3356 | status = (int) fwrite( &monrec, 1, sizeof(monrec),fpmon); |
3301 | sa02Printf("[%04d] HvMonitor dt= %f s status=%d\n", runno, thv1-thv0, status ); |
3357 | sa02Printf("[%04d] HvMonitor dt= %f s status=%d\n", runno, thv1-thv0, status ); |
3302 | for (int idelay=delaytime ; idelay>0; idelay--) { |
3358 | for (int idelay=delaytime ; idelay>0; idelay--) { |
3303 | Delay(1); |
3359 | Delay(1); |
3304 | SetCtrlVal(p1h, P1_DELAY, idelay); |
3360 | SetCtrlVal(p1h, P1_DELAY, idelay); |
3305 | ProcessSystemEvents(); |
3361 | ProcessSystemEvents(); |
3306 | if (ctrl_c) break; |
3362 | if (ctrl_c) break; |
3307 | } |
3363 | } |
3308 | if (ctrl_c) break; |
3364 | if (ctrl_c) break; |
3309 | } |
3365 | } |
3310 | fclose(fpmon); |
3366 | fclose(fpmon); |
- | 3367 | } |
|
3311 |
|
3368 | else { |
3312 | sa02Printf("%s cannot open file %s\n",param, paramValue ); |
3369 | sa02Printf("%s cannot open file %s\n",param, paramValue ); |
3313 | } |
3370 | } |
3314 | 3371 | ||
- | 3372 | } |
|
3315 |
|
3373 | else if (strstr(type,"GetRunNumberFromFile")!=NULL) { |
3316 | sscanf(line,"%*s%s",paramValue); |
3374 | sscanf(line,"%*s%s",paramValue); |
3317 | runno = GetRunNumberFromFile(paramValue); |
3375 | runno = GetRunNumberFromFile(paramValue); |
3318 | SetCtrlVal(p1h, P1_RUNNO, runno); |
3376 | SetCtrlVal(p1h, P1_RUNNO, runno); |
3319 | sa02Printf("%s %s run=>%d\n",type, paramValue, runno ); |
3377 | sa02Printf("%s %s run=>%d\n",type, paramValue, runno ); |
- | 3378 | } |
|
3320 |
|
3379 | else if (strstr(type,"IncreaseNumberInFile")!=NULL) { |
3321 | sscanf(line,"%*s%s",paramValue); |
3380 | sscanf(line,"%*s%s",paramValue); |
3322 | runno = IncreaseRunNumberInFile(paramValue); |
3381 | runno = IncreaseRunNumberInFile(paramValue); |
3323 | sa02Printf("%s %s run=>%d\n",type, paramValue, runno ); |
3382 | sa02Printf("%s %s run=>%d\n",type, paramValue, runno ); |
3324 | SetCtrlVal(p1h, P1_RUNNO, runno); |
3383 | SetCtrlVal(p1h, P1_RUNNO, runno); |
- | 3384 | } |
|
3325 |
|
3385 | else if (strstr(type,"LoadParameters")!=NULL) { |
3326 | LoadParameters(p3h, P3_LOADPAR,EVENT_COMMIT,NULL,0,0); |
3386 | LoadParameters(p3h, P3_LOADPAR,EVENT_COMMIT,NULL,0,0); |
3327 | sa02Printf("Loading parameters *\n\n"); |
3387 | sa02Printf("Loading parameters *\n\n"); |
- | 3388 | } |
|
3328 |
|
3389 | else if (strstr(type,"QueueUserEvent")!=NULL || strstr(type,"ProcessUserEvent")!=NULL) { |
3329 | char scontrol[0xFF]; |
3390 | char scontrol[0xFF]; |
3330 | int panelHandle=0; |
3391 | int panelHandle=0; |
3331 | int controlID; |
3392 | int controlID; |
3332 | sscanf(line,"%*s%s",scontrol); |
3393 | sscanf(line,"%*s%s",scontrol); |
3333 | panelHandle = GetPanelHandle(scontrol); |
3394 | panelHandle = GetPanelHandle(scontrol); |
3334 | controlID = GetControlID(scontrol); |
3395 | controlID = GetControlID(scontrol); |
3335 | sa02Printf("UserEvent %s panelHandle %d controlID %d\n",scontrol, panelHandle, controlID ); |
3396 | sa02Printf("UserEvent %s panelHandle %d controlID %d\n",scontrol, panelHandle, controlID ); |
3336 | if (panelHandle>=0 && controlID >=0 ) { |
3397 | if (panelHandle>=0 && controlID >=0 ) { |
3337 | if (strstr(type,"ProcessUserEvent")!=NULL) { |
3398 | if (strstr(type,"ProcessUserEvent")!=NULL) { |
3338 | ProcessUserEvent(panelHandle, controlID,0); |
3399 | ProcessUserEvent(panelHandle, controlID,0); |
- | 3400 | } |
|
3339 |
|
3401 | else { |
3340 | data[1] = controlID; |
3402 | data[1] = controlID; |
3341 | data[0] = panelHandle; |
3403 | data[0] = panelHandle; |
3342 | 3404 | ||
3343 | status = CmtWriteTSQData (pTSQ, data, 1, TSQ_INFINITE_TIMEOUT, NULL); |
3405 | status = CmtWriteTSQData (pTSQ, data, 1, TSQ_INFINITE_TIMEOUT, NULL); |
3344 | } |
3406 | } |
3345 | } |
3407 | } |
3346 | 3408 | ||
- | 3409 | } |
|
3347 |
|
3410 | else if (strstr(type,"SetPositionAndMux")!=NULL) { |
3348 | int ix,iy; |
3411 | int ix,iy; |
3349 | sscanf(line,"%*s%d%d",&ix,&iy); |
3412 | sscanf(line,"%*s%d%d",&ix,&iy); |
3350 | sa02Printf("SetPositionAndMux %d %d \n", ix,iy); |
3413 | sa02Printf("SetPositionAndMux %d %d \n", ix,iy); |
3351 | 3414 | ||
3352 | SetCtrlVal (p2h, P2_CHX, ix); |
3415 | SetCtrlVal (p2h, P2_CHX, ix); |
3353 | SetCtrlVal (p2h, P2_CHY, iy); |
3416 | SetCtrlVal (p2h, P2_CHY, iy); |
3354 | SetPositionAndMux( p2h,0, EVENT_COMMIT , NULL,0,0); |
3417 | SetPositionAndMux( p2h,0, EVENT_COMMIT , NULL,0,0); |
3355 | 3418 | ||
- | 3419 | } |
|
3356 |
|
3420 | else if (strstr(type,"Treshold")!=NULL) { |
3357 | sscanf(line,"%*s%s",outputFileSuffix); |
3421 | sscanf(line,"%*s%s",outputFileSuffix); |
3358 | 3422 | ||
3359 | GetCtrlVal (p1h, P1_SERIAL_1, HAPDserialNumber); |
3423 | GetCtrlVal (p1h, P1_SERIAL_1, HAPDserialNumber); |
3360 | sprintf(outputFile,"%s_%s.dat", HAPDserialNumber, outputFileSuffix); |
3424 | sprintf(outputFile,"%s_%s.dat", HAPDserialNumber, outputFileSuffix); |
3361 | SetCtrlVal (p1h, P1_OUTPUTFILE, outputFile); |
3425 | SetCtrlVal (p1h, P1_OUTPUTFILE, outputFile); |
3362 | 3426 | ||
3363 | sprintf(test,"Treshold scan to file %s",outputFile); |
3427 | sprintf(test,"Treshold scan to file %s",outputFile); |
3364 | sa02Printf("%s *\n\n", test); |
3428 | sa02Printf("%s *\n\n", test); |
3365 | 3429 | ||
3366 | daq(NULL); |
3430 | daq(NULL); |
- | 3431 | } |
|
3367 |
|
3432 | else if (strstr(type,"Fitanje")!=NULL) { |
3368 | FitH2DCoarse(p3h, P3_CALIBRATION_2,EVENT_COMMIT,NULL,0,0); |
3433 | FitH2DCoarse(p3h, P3_CALIBRATION_2,EVENT_COMMIT,NULL,0,0); |
3369 | sa02Printf("Coarse fit parameters *\n\n"); |
3434 | sa02Printf("Coarse fit parameters *\n\n"); |
- | 3435 | } |
|
3370 |
|
3436 | else if (strstr(type,"UploadChannelParameters")!=NULL) { |
3371 | UploadChannelParameters(p3h, P3_CPARLOAD,EVENT_COMMIT,NULL,0,0); |
3437 | UploadChannelParameters(p3h, P3_CPARLOAD,EVENT_COMMIT,NULL,0,0); |
3372 | sa02Printf("Loading channel parameters *\n\n"); |
3438 | sa02Printf("Loading channel parameters *\n\n"); |
- | 3439 | } |
|
3373 |
|
3440 | else if (strstr(type,"KalibracijaMizice")!=NULL) { |
3374 | SetHome(p2h, P2_HO,EVENT_COMMIT,NULL,0,0); |
3441 | SetHome(p2h, P2_HO,EVENT_COMMIT,NULL,0,0); |
3375 | SetCtrlVal(p2h,P2_XC,gCENTER_X); |
3442 | SetCtrlVal(p2h,P2_XC,gCENTER_X); |
3376 | SetCtrlVal(p2h,P2_YC,gCENTER_Y); |
3443 | SetCtrlVal(p2h,P2_YC,gCENTER_Y); |
3377 | sa02Printf("Calibration *\n\n"); |
3444 | sa02Printf("Calibration *\n\n"); |
- | 3445 | } |
|
3378 |
|
3446 | else if (strstr(type,"LaserHVOn")!=NULL) { |
3379 | set_dac(1); |
3447 | set_dac(1); |
3380 | sa02Printf("Low intensity laser *\n\n"); |
3448 | sa02Printf("Low intensity laser *\n\n"); |
- | 3449 | } |
|
3381 |
|
3450 | else if (strstr(type,"LaserHVOff")!=NULL) { |
3382 | set_dac(0); |
3451 | set_dac(0); |
3383 | sa02Printf("High intensity laser *\n\n"); |
3452 | sa02Printf("High intensity laser *\n\n"); |
- | 3453 | } |
|
3384 |
|
3454 | else if (strstr(type,"Gain")!=NULL) { |
3385 | sscanf(line,"%*s%d",paramValue); |
3455 | sscanf(line,"%*s%d",paramValue); |
3386 | sprintf(test," %d", atoi(paramValue)); |
3456 | sprintf(test," %d", atoi(paramValue)); |
3387 | sa02Printf("%s *\n\n", test); |
3457 | sa02Printf("%s *\n\n", test); |
3388 | changeGlobalParam(12, atoi(paramValue)); // Global parameter Gain has ID 12 |
3458 | changeGlobalParam(12, atoi(paramValue)); // Global parameter Gain has ID 12 |
- | 3459 | } |
|
3389 |
|
3460 | else if (strstr(type,"ShapingTime")!=NULL) { |
3390 | sscanf(line,"%*s%s",paramValue); |
3461 | sscanf(line,"%*s%s",paramValue); |
3391 | sprintf(test," %d", atoi(paramValue)); |
3462 | sprintf(test," %d", atoi(paramValue)); |
3392 | sa02Printf("%s *\n\n", test); |
3463 | sa02Printf("%s *\n\n", test); |
3393 | changeGlobalParam(13, atoi(paramValue)); // Global parameter ShapingTime has ID 13 |
3464 | changeGlobalParam(13, atoi(paramValue)); // Global parameter ShapingTime has ID 13 |
3394 | } |
3465 | } |
Line 3623... | Line 3694... | ||
3623 | GetTableSelection (p3h, P3_GREG, &trange); |
3694 | GetTableSelection (p3h, P3_GREG, &trange); |
3624 | if ((trange.top!=0)&&(trange.left!=0)) { |
3695 | if ((trange.top!=0)&&(trange.left!=0)) { |
3625 | imin= trange.top - 1; |
3696 | imin= trange.top - 1; |
3626 | imax= imin + trange.height; |
3697 | imax= imin + trange.height; |
3627 | 3698 | ||
- | 3699 | } |
|
3628 |
|
3700 | else { |
3629 | if (!GetActiveTableCell(p3h, P3_GREG, &cell)) { |
3701 | if (!GetActiveTableCell(p3h, P3_GREG, &cell)) { |
3630 | imin = cell.y-1; |
3702 | imin = cell.y-1; |
3631 | imax = imin; |
3703 | imax = imin; |
- | 3704 | } |
|
3632 |
|
3705 | else return 0; |
3633 | } |
3706 | } |
- | 3707 | } |
|
3634 |
|
3708 | else { |
3635 | imin=0; |
3709 | imin=0; |
3636 | imax=4*4; |
3710 | imax=4*4; |
3637 | } |
3711 | } |
3638 | 3712 | ||
3639 | for (i=imin; i<imax; i++) { |
3713 | for (i=imin; i<imax; i++) { |
Line 3697... | Line 3771... | ||
3697 | state = GetTableSelection (p3h, P3_CREG, &trange); |
3771 | state = GetTableSelection (p3h, P3_CREG, &trange); |
3698 | if ((trange.top!=0)&&(trange.left!=0)) { |
3772 | if ((trange.top!=0)&&(trange.left!=0)) { |
3699 | imin= trange.top-1; |
3773 | imin= trange.top-1; |
3700 | imax= imin + trange.height; |
3774 | imax= imin + trange.height; |
3701 | 3775 | ||
- | 3776 | } |
|
3702 |
|
3777 | else { |
3703 | if (!GetActiveTableCell(p3h, P3_CREG, &cell)) { |
3778 | if (!GetActiveTableCell(p3h, P3_CREG, &cell)) { |
3704 | imin = cell.y-1; |
3779 | imin = cell.y-1; |
3705 | imax = imin+1; |
3780 | imax = imin+1; |
- | 3781 | } |
|
3706 |
|
3782 | else return 0; |
3707 | } |
3783 | } |
- | 3784 | } |
|
3708 |
|
3785 | else if ((panel==p1h)&&(control==P1_CHPARLOAD)) { |
3709 | GetCtrlVal(p1h,P1_NSLIX,&imin); |
3786 | GetCtrlVal(p1h,P1_NSLIX,&imin); |
3710 | imax=imin+1; |
3787 | imax=imin+1; |
- | 3788 | } |
|
3711 |
|
3789 | else { |
3712 | imin=0; |
3790 | imin=0; |
3713 | imax=144*4; |
3791 | imax=144*4; |
3714 | } |
3792 | } |
3715 | 3793 | ||
3716 | for (i=imin; i<imax; i++) { |
3794 | for (i=imin; i<imax; i++) { |
Line 3743... | Line 3821... | ||
3743 | if (ctrl_c) { |
3821 | if (ctrl_c) { |
3744 | break; |
3822 | break; |
3745 | } |
3823 | } |
3746 | } |
3824 | } |
3747 | sa02Printf("Channel Parameters Uploaded to the ASICs\n"); |
3825 | sa02Printf("Channel Parameters Uploaded to the ASICs\n"); |
3748 | 3826 | ||
3749 | } |
3827 | } |
3750 | SetCtrlAttribute (panel, control, ATTR_DIMMED, 0); |
3828 | SetCtrlAttribute (panel, control, ATTR_DIMMED, 0); |
3751 | break; |
3829 | break; |
3752 | } |
3830 | } |
3753 | return 0; |
3831 | return 0; |
3754 | } |
3832 | } |
3755 | 3833 | ||
3756 | int CVICALLBACK UploadFPGAParameters (int panel, int control, int event, |
3834 | int CVICALLBACK UploadFPGAParameters (int panel, int control, int event, |
3757 | void *callbackData, int eventData1, int eventData2) { |
3835 | void *callbackData, int eventData1, int eventData2) { |
3758 | 3836 | ||
3759 | int n=0; |
3837 | int n=0; |
3760 | int i=0; |
3838 | int i=0; |
Line 3765... | Line 3843... | ||
3765 | char cmd[NDIM]; |
3843 | char cmd[NDIM]; |
3766 | char sasic[NDIM]; |
3844 | char sasic[NDIM]; |
3767 | uint32_t sa02code; |
3845 | uint32_t sa02code; |
3768 | uint32_t board; |
3846 | uint32_t board; |
3769 | uint32_t response[2]= {0,0}; |
3847 | uint32_t response[2]= {0,0}; |
3770 | 3848 | ||
3771 | switch (event) { |
3849 | switch (event) { |
3772 | case EVENT_COMMIT: { |
3850 | case EVENT_COMMIT: { |
3773 | uint16_t mask=GetConnectedFebMask(); |
3851 | uint16_t mask=GetConnectedFebMask(); |
3774 | SetCtrlAttribute (panel, control, ATTR_DIMMED, 1); |
3852 | SetCtrlAttribute (panel, control, ATTR_DIMMED, 1); |
3775 | 3853 | ||
3776 | GetNumTextBoxLines(p3h, P3_FPGAPAR,&n); |
3854 | GetNumTextBoxLines(p3h, P3_FPGAPAR,&n); |
Line 3782... | Line 3860... | ||
3782 | if (strcmp(cmd,"MUXASIC")==0) { |
3860 | if (strcmp(cmd,"MUXASIC")==0) { |
3783 | asic = sa02MuxMap(asic); |
3861 | asic = sa02MuxMap(asic); |
3784 | } |
3862 | } |
3785 | for (board = 0; board < 4; board ++) if ( mask & (1 << board) ) sa02Cmd(board,sa02code, asic, 0, 0, 2,response); |
3863 | for (board = 0; board < 4; board ++) if ( mask & (1 << board) ) sa02Cmd(board,sa02code, asic, 0, 0, 2,response); |
3786 | sa02Printf("%s\n",buf); |
3864 | sa02Printf("%s\n",buf); |
3787 | } |
3865 | } |
3788 | sa02Printf("FPGA Parameters Uploaded to FEBS\n"); |
3866 | sa02Printf("FPGA Parameters Uploaded to FEBS\n"); |
3789 | SetCtrlAttribute (panel, control, ATTR_DIMMED, 0); |
3867 | SetCtrlAttribute (panel, control, ATTR_DIMMED, 0); |
3790 | break; |
3868 | break; |
3791 | } |
3869 | } |
3792 | } |
3870 | } |
3793 | return 0; |
3871 | return 0; |
3794 | } |
3872 | } |
3795 | 3873 | ||
3796 | int CVICALLBACK SetSelectionToVal (int panel, int control, int event, |
3874 | int CVICALLBACK SetSelectionToVal (int panel, int control, int event, |
3797 | void *callbackData, int eventData1, int eventData2) { |
3875 | void *callbackData, int eventData1, int eventData2) { |
3798 | int state, input_cid=-1,output_cid=-1; |
3876 | int state, input_cid=-1,output_cid=-1; |
3799 | Rect trange; |
3877 | Rect trange; |
3800 | unsigned short value; |
3878 | unsigned short value; |
Line 3813... | Line 3891... | ||
3813 | } |
3891 | } |
3814 | state = GetTableSelection (p3h, output_cid, &trange); |
3892 | state = GetTableSelection (p3h, output_cid, &trange); |
3815 | if ((trange.top!=0)&&(trange.left!=0)) { |
3893 | if ((trange.top!=0)&&(trange.left!=0)) { |
3816 | GetCtrlVal(p3h,input_cid, &value); |
3894 | GetCtrlVal(p3h,input_cid, &value); |
3817 | state = FillTableCellRange (p3h, output_cid, trange, value); |
3895 | state = FillTableCellRange (p3h, output_cid, trange, value); |
3818 | } |
3896 | } |
3819 | break; |
3897 | break; |
3820 | } |
3898 | } |
3821 | return 0; |
3899 | return 0; |
3822 | } |
3900 | } |
3823 | 3901 | ||
Line 3826... | Line 3904... | ||
3826 | int cid[4]= {P3_MUX0,P3_MUX1,P3_MUX2,P3_MUX3}; |
3904 | int cid[4]= {P3_MUX0,P3_MUX1,P3_MUX2,P3_MUX3}; |
3827 | int id=0,i; |
3905 | int id=0,i; |
3828 | uint32_t sa02code; |
3906 | uint32_t sa02code; |
3829 | uint32_t board; |
3907 | uint32_t board; |
3830 | uint32_t response[2]= {0,0}; |
3908 | uint32_t response[2]= {0,0}; |
3831 | 3909 | ||
3832 | switch (event) { |
3910 | switch (event) { |
3833 | case EVENT_COMMIT: |
3911 | case EVENT_COMMIT: |
3834 | 3912 | ||
3835 | switch (control) { |
3913 | switch (control) { |
3836 | case P3_MUX0: |
3914 | case P3_MUX0: |
3837 | id=0; |
3915 | id=0; |
Line 3858... | Line 3936... | ||
3858 | if (id!= i) { |
3936 | if (id!= i) { |
3859 | SetCtrlVal(panel,cid[i],0); |
3937 | SetCtrlVal(panel,cid[i],0); |
3860 | } |
3938 | } |
3861 | } |
3939 | } |
3862 | sa02Printf("MUX %d\n",id); |
3940 | sa02Printf("MUX %d\n",id); |
3863 | break; |
3941 | break; |
3864 | } |
3942 | } |
3865 | return 0; |
3943 | return 0; |
3866 | } |
3944 | } |
3867 | 3945 | ||
3868 | int CVICALLBACK UploadFromPanels (int panel, int control, int event, |
3946 | int CVICALLBACK UploadFromPanels (int panel, int control, int event, |
3869 | void *callbackData, int eventData1, int eventData2) { |
3947 | void *callbackData, int eventData1, int eventData2) { |
3870 | switch (event) { |
3948 | switch (event) { |
3871 | case EVENT_COMMIT: |
3949 | case EVENT_COMMIT: |
3872 | UploadFPGAParameters(panel,control,event,callbackData,eventData1,eventData2); |
3950 | UploadFPGAParameters(panel,control,event,callbackData,eventData1,eventData2); |
3873 | UploadChannelParameters(panel,control,event,callbackData,eventData1,eventData2); |
3951 | UploadChannelParameters(panel,control,event,callbackData,eventData1,eventData2); |
3874 | UploadGlobalParameters(panel,control,event,callbackData,eventData1,eventData2); |
3952 | UploadGlobalParameters(panel,control,event,callbackData,eventData1,eventData2); |
3875 | break; |
3953 | break; |
3876 | } |
3954 | } |
3877 | return 0; |
3955 | return 0; |
3878 | } |
3956 | } |
3879 | 3957 | ||
3880 | double erf(double x, double par[], int npar) { |
3958 | double erf(double x, double par[], int npar) { |
3881 | double y=0; |
3959 | double y=0; |
3882 | double x0= (x-par[0])*par[1]; |
3960 | double x0= (x-par[0])*par[1]; |
3883 | Erf(x0,&y); |
3961 | Erf(x0,&y); |
3884 | return (y); |
3962 | return (y); |
3885 | } |
3963 | } |
3886 | 3964 | ||
3887 | int CVICALLBACK FitH2D (int panel, int control, int event, |
3965 | int CVICALLBACK FitH2D (int panel, int control, int event, |
3888 | void *callbackData, int eventData1, int eventData2) { |
3966 | void *callbackData, int eventData1, int eventData2) { |
3889 | char name[MAX_PATHNAME_LEN]; |
3967 | char name[MAX_PATHNAME_LEN]; |
3890 | 3968 | ||
Line 3892... | Line 3970... | ||
3892 | case EVENT_COMMIT: { |
3970 | case EVENT_COMMIT: { |
3893 | //sprintf(name ,"C:\\root\\bin\\root.exe"); |
3971 | //sprintf(name ,"C:\\root\\bin\\root.exe"); |
3894 | int status; |
3972 | int status; |
3895 | char dfile[MAX_PATHNAME_LEN]; |
3973 | char dfile[MAX_PATHNAME_LEN]; |
3896 | char efile[MAX_PATHNAME_LEN]; |
3974 | char efile[MAX_PATHNAME_LEN]; |
3897 | 3975 | ||
3898 | status = FileSelectPopup ("data", "*.th2d", ".th2d", |
3976 | status = FileSelectPopup ("data", "*.th2d", ".th2d", |
3899 | "Izberi datoteko s histogramom", |
3977 | "Izberi datoteko s histogramom", |
3900 | VAL_LOAD_BUTTON, 0, 0, 1, 0, efile); |
3978 | VAL_LOAD_BUTTON, 0, 0, 1, 0, efile); |
3901 | EscapeString(efile,dfile); |
3979 | EscapeString(efile,dfile); |
3902 | sprintf(name ,"C:/root/bin/root.exe ../macros/sa02fit.cxx(\\\"%s\\\")", dfile); |
3980 | sprintf(name ,"C:/root/bin/root.exe ../macros/sa02fit.cxx(\\\"%s\\\")", dfile); |
3903 | 3981 | ||
3904 | 3982 | ||
3905 | 3983 | ||
3906 | sa02Printf("%s\n",name); |
3984 | sa02Printf("%s\n",name); |
3907 | 3985 | ||
3908 | LaunchExecutable(name); |
3986 | LaunchExecutable(name); |
3909 | 3987 | ||
3910 | 3988 | ||
3911 | } |
3989 | } |
3912 | break; |
3990 | break; |
3913 | } |
3991 | } |
3914 | return 0; |
3992 | return 0; |
3915 | } |
3993 | } |
Line 3918... | Line 3996... | ||
3918 | 3996 | ||
3919 | int ix= (int)x; |
3997 | int ix= (int)x; |
3920 | if (x>0) { |
3998 | if (x>0) { |
3921 | if (x - ix > 0.5 ) { |
3999 | if (x - ix > 0.5 ) { |
3922 | return ix+1; |
4000 | return ix+1; |
- | 4001 | } |
|
3923 |
|
4002 | else { |
3924 | return ix; |
4003 | return ix; |
3925 | } |
4004 | } |
- | 4005 | } |
|
3926 |
|
4006 | else { |
3927 | if (x - ix < -0.5 ) { |
4007 | if (x - ix < -0.5 ) { |
3928 | return ix-1; |
4008 | return ix-1; |
- | 4009 | } |
|
3929 |
|
4010 | else { |
3930 | return ix; |
4011 | return ix; |
3931 | } |
4012 | } |
3932 | } |
4013 | } |
3933 | 4014 | ||
3934 | 4015 | ||
Line 3997... | Line 4078... | ||
3997 | 4078 | ||
3998 | for (i=0; i<fNpoints; i++) { |
4079 | for (i=0; i<fNpoints; i++) { |
3999 | sumwx += fX[i]* fY[i]; |
4080 | sumwx += fX[i]* fY[i]; |
4000 | sumw += fY[i]; |
4081 | sumw += fY[i]; |
4001 | sumwx2 += fX[i]* fX[i]* fY[i]; |
4082 | sumwx2 += fX[i]* fX[i]* fY[i]; |
4002 | 4083 | ||
4003 | } |
4084 | } |
4004 | if (sumw <= 0) { |
4085 | if (sumw <= 0) { |
4005 | return 0; |
4086 | return 0; |
4006 | } |
4087 | } |
4007 | mean = sumwx/sumw; |
4088 | mean = sumwx/sumw; |
4008 | rms2 = fabs(sumwx2/sumw -mean*mean); |
4089 | rms2 = fabs(sumwx2/sumw -mean*mean); |
Line 4088... | Line 4169... | ||
4088 | for (iy=0; iy < npt; iy++ ) { |
4169 | for (iy=0; iy < npt; iy++ ) { |
4089 | datay[iy] = H2DGetBinContent(h2,ix,iy); // /H2DGetMax(h2); |
4170 | datay[iy] = H2DGetBinContent(h2,ix,iy); // /H2DGetMax(h2); |
4090 | } |
4171 | } |
4091 | FitGraph(fitmode, npt, datax , datay, fpar); |
4172 | FitGraph(fitmode, npt, datax , datay, fpar); |
4092 | mean[ix]=fpar[0]; |
4173 | mean[ix]=fpar[0]; |
4093 | rms[ix] |
4174 | rms[ix]=fpar[1]; |
4094 | offset = offsets[ix*2]; |
4175 | offset = offsets[ix*2]; |
4095 | fineadj_unipol = offsets[ix*2+1]; |
4176 | fineadj_unipol = offsets[ix*2+1]; |
4096 | 4177 | ||
4097 | x = sa02getshift(offset, fineadj_unipol); |
4178 | x = sa02getshift(offset, fineadj_unipol); |
4098 | x += (mean0-(mean[ix]+rms0*rms[ix])); |
4179 | x += (mean0-(mean[ix]+rms0*rms[ix])); |
Line 4171... | Line 4252... | ||
4171 | PCLK -> 0 -> CLK_IN (internal clock) |
4252 | PCLK -> 0 -> CLK_IN (internal clock) |
4172 | */ |
4253 | */ |
4173 | 4254 | ||
4174 | if (value==2) { |
4255 | if (value==2) { |
4175 | value=0x7600; |
4256 | value=0x7600; |
- | 4257 | } |
|
4176 |
|
4258 | else { |
4177 | value=0; |
4259 | value=0; |
4178 | } |
4260 | } |
4179 | VME_A32D32_W(address+4,value); // enable outputs |
4261 | VME_A32D32_W(address+4,value); // enable outputs |
4180 | } |
4262 | } |
4181 | sa02Printf("SizeOf(Double)=%d\n",sizeof(double)); |
4263 | sa02Printf("SizeOf(Double)=%d\n",sizeof(double)); |
Line 4304... | Line 4386... | ||
4304 | if (scanpar>10) { |
4386 | if (scanpar>10) { |
4305 | cid=P3_GREG; |
4387 | cid=P3_GREG; |
4306 | spar=scanpar-10; |
4388 | spar=scanpar-10; |
4307 | nch=4*4; |
4389 | nch=4*4; |
4308 | 4390 | ||
- | 4391 | } |
|
4309 |
|
4392 | else { |
4310 | cid=P3_CREG; |
4393 | cid=P3_CREG; |
4311 | spar=scanpar; |
4394 | spar=scanpar; |
4312 | nch=144*4; |
4395 | nch=144*4; |
4313 | 4396 | ||
4314 | } |
4397 | } |
Line 4506... | Line 4589... | ||
4506 | return 0; |
4589 | return 0; |
4507 | } |
4590 | } |
4508 | 4591 | ||
4509 | 4592 | ||
4510 | 4593 | ||
4511 | int ProcessUserEvent(int pID, int rID,int mode){ |
4594 | int ProcessUserEvent(int pID, int rID,int mode) { |
4512 |
|
4595 | ThreadFunctionPtr mythread = NULL; |
4513 |
|
4596 | if (pID ==p1h && rID == P1_DAQ ) mythread=daq; |
4514 |
|
4597 | if (pID ==p1h && rID == P1_READOUT ) mythread=daq_readonly; |
4515 |
|
4598 | if (pID ==p1h && rID == P1_FPGAWRITE ) mythread=MultiFpgaWrite; |
4516 |
|
4599 | if (pID ==p1h && rID == P1_MULTIFPGAWRITE ) mythread=MultiFpgaWrite; |
4517 |
|
4600 | if (pID ==p1h && rID == P1_TESTING ) mythread=Testing; |
4518 |
|
4601 | if (pID ==p2h && rID == P2_DAQ ) mythread=daq_scan; |
4519 |
|
4602 | if (pID ==p6h && rID == MINIRICH_START ) mythread=daq; |
4520 |
|
4603 | if (pID ==p2h && rID == P2_RUNSCRIPT ) { |
4521 |
|
4604 | char scriptname[MAX_PATHNAME_LEN] ; |
4522 | 4605 | ||
4523 |
|
4606 | int status = FileSelectPopup ("./scripts/", "*.txt", "*.txt", |
4524 |
|
4607 | "Select Script file", VAL_LOAD_BUTTON, 0, 0, |
4525 |
|
4608 | 1, 0, scriptname); |
4526 |
|
4609 | if (status) { |
4527 |
|
4610 | SetCtrlVal(p1h, P1_SCRIPTNAME, scriptname ); |
4528 |
|
4611 | mythread=run_script; |
4529 | } |
- | |
4530 | } |
4612 | } |
- | 4613 | } |
|
4531 |
|
4614 | if (pID ==p1h && rID == P1_RUNSCRIPT ) mythread=run_script; |
4532 |
|
4615 | if (pID ==p3h && rID == P3_DAQ ) mythread=daq_scanpar; |
4533 |
|
4616 | if (pID ==p4h && rID == P4_DAQ ) mythread=V729_daq; |
4534 |
|
4617 | if (mythread!=NULL) { |
4535 |
|
4618 | sa02Printf("New Thread panel=%d button=%d\n", pID, rID); |
4536 |
|
4619 | ctrl_c=0; |
4537 |
|
4620 | daq_on = 1; |
4538 |
|
4621 | SetDimming(1); |
4539 |
|
4622 | if (mode) { |
4540 |
|
4623 | CmtScheduleThreadPoolFunctionAdv (poolHandle, mythread, &rID, |
4541 | DEFAULT_THREAD_PRIORITY, |
4624 | DEFAULT_THREAD_PRIORITY, |
4542 | EndOfThread, |
4625 | EndOfThread, |
4543 | EVENT_TP_THREAD_FUNCTION_END, |
4626 | EVENT_TP_THREAD_FUNCTION_END, |
4544 | NULL, RUN_IN_SCHEDULED_THREAD, |
4627 | NULL, RUN_IN_SCHEDULED_THREAD, |
4545 | &tfID); |
4628 | &tfID); |
4546 | } else { |
- | |
4547 | mythread(NULL); |
- | |
4548 | } |
- | |
4549 | } |
- | |
4550 | - | ||
4551 | if ( pID==p1h && rID == P1_SLOWC ) { |
- | |
4552 | uint32_t board; |
- | |
4553 | GetCtrlVal(p1h,P1_BOARDNUMBER, &board); |
- | |
4554 | SlowControl(board, NULL); |
- | |
4555 | } |
- | |
4556 | // if ( pID==p1h && rID == P1_STEPONE ) StepOne(); |
- | |
4557 | if ( pID==p1h && rID == P1_FEBTESTANA ) FebTestAna(); |
- | |
4558 | if ( pID==p1h && rID == P1_TEST ) FebTest(); |
- | |
4559 | if ( pID==p1h && rID == P1_MODULETEST ) ModuleTest(); |
- | |
4560 | - | ||
4561 | if ( pID==p1h && rID == P1_GET_FPGA_SERIAL ) { |
- | |
4562 | int ison=0; |
- | |
4563 | GetCtrlVal(p1h,P1_BOARDTYPE,&sa02BoardType); |
- | |
4564 | for (int board=0; board<4; board++) { |
- | |
4565 | char saddress[0xff]=""; |
- | |
4566 | GetCtrlVal(p1h, hapd_onoff[board], &ison); |
- | |
4567 | sa02GetSerial(board, saddress); |
- | |
4568 | sa02Printf("SERIAL FPGA = %s \n", saddress); |
- | |
4569 | SetCtrlVal(p1h,fpga_serials[board],saddress); |
- | |
4570 | } |
- | |
4571 | }; |
- | |
4572 | - | ||
4573 | if ( ( pID==p1h && rID == P1_STOP ) |
- | |
4574 | || ( pID==p2h && rID == P2_STOP ) |
- | |
4575 | || ( pID==p3h && rID == P3_STOP ) |
- | |
4576 | || ( pID==p6h && rID == MINIRICH_STOP ) |
- | |
4577 | || ( pID==p4h && rID == P4_STOP ) ) { |
- | |
4578 | sa02Printf("Stopping the Thread %d\n", tfID); |
- | |
4579 | ctrl_c=1; |
- | |
4580 | } |
4629 | } |
4581 |
|
4630 | else { |
4582 | if (rID == P5_SET_DAC_HV_ON) set_dac(1); |
- | |
4583 | if (rID == P5_SET_DAC_HV_OFF) set_dac(0); |
- | |
4584 |
|
4631 | mythread(NULL); |
4585 | if (rID == P5_SET_HV_OFF) set_hv(0); |
- | |
4586 | } |
4632 | } |
- | 4633 | } |
|
- | 4634 | ||
- | 4635 | if ( pID==p1h && rID == P1_SLOWC ) { |
|
- | 4636 | uint32_t board; |
|
- | 4637 | GetCtrlVal(p1h,P1_BOARDNUMBER, &board); |
|
- | 4638 | SlowControl(board, NULL); |
|
- | 4639 | } |
|
- | 4640 | // if ( pID==p1h && rID == P1_STEPONE ) StepOne(); |
|
- | 4641 | if ( pID==p1h && rID == P1_FEBTESTANA ) FebTestAna(); |
|
- | 4642 | if ( pID==p1h && rID == P1_TEST ) FebTest(); |
|
- | 4643 | if ( pID==p1h && rID == P1_MODULETEST ) ModuleTest(); |
|
- | 4644 | ||
- | 4645 | if ( pID==p1h && rID == P1_GET_FPGA_SERIAL ) { |
|
- | 4646 | int ison=0; |
|
- | 4647 | GetCtrlVal(p1h,P1_BOARDTYPE,&sa02BoardType); |
|
- | 4648 | for (int board=0; board<4; board++) { |
|
- | 4649 | char saddress[0xff]=""; |
|
- | 4650 | GetCtrlVal(p1h, hapd_onoff[board], &ison); |
|
- | 4651 | sa02GetSerial(board, saddress); |
|
- | 4652 | sa02Printf("SERIAL FPGA = %s \n", saddress); |
|
- | 4653 | SetCtrlVal(p1h,fpga_serials[board],saddress); |
|
- | 4654 | } |
|
- | 4655 | }; |
|
- | 4656 | ||
- | 4657 | if ( ( pID==p1h && rID == P1_STOP ) |
|
- | 4658 | || ( pID==p2h && rID == P2_STOP ) |
|
- | 4659 | || ( pID==p3h && rID == P3_STOP ) |
|
- | 4660 | || ( pID==p6h && rID == MINIRICH_STOP ) |
|
- | 4661 | || ( pID==p4h && rID == P4_STOP ) ) { |
|
- | 4662 | sa02Printf("Stopping the Thread %d\n", tfID); |
|
- | 4663 | ctrl_c=1; |
|
- | 4664 | } |
|
- | 4665 | if (pID ==p5h) { |
|
- | 4666 | if (rID == P5_SET_DAC_HV_ON) set_dac(1); |
|
- | 4667 | if (rID == P5_SET_DAC_HV_OFF) set_dac(0); |
|
- | 4668 | if (rID == P5_SET_HV_ON) set_hv(1); |
|
- | 4669 | if (rID == P5_SET_HV_OFF) set_hv(0); |
|
- | 4670 | } |
|
4587 |
|
4671 | return 0; |
4588 | } |
4672 | } |
4589 | 4673 | ||
4590 | 4674 | ||
4591 | 4675 | ||
4592 | void CVICALLBACK QueueUserEventCallback (CmtTSQHandle queueHandle, unsigned int event, int value, void *callbackData) { |
4676 | void CVICALLBACK QueueUserEventCallback (CmtTSQHandle queueHandle, unsigned int event, int value, void *callbackData) { |
4593 | //int *data= (int *) callbackData; |
4677 | //int *data= (int *) callbackData; |
4594 | int mdata[2]; |
4678 | int mdata[2]; |
Line 4603... | Line 4687... | ||
4603 | LPSTR lpszCmdLine, int nCmdShow) { |
4687 | LPSTR lpszCmdLine, int nCmdShow) { |
4604 | 4688 | ||
4605 | char title[0xFF]; |
4689 | char title[0xFF]; |
4606 | char saddress[0xff]=""; |
4690 | char saddress[0xff]=""; |
4607 | //uint32_t board; |
4691 | //uint32_t board; |
4608 | int i; |
4692 | int i; |
4609 | int status=0; |
4693 | int status=0; |
4610 | 4694 | ||
4611 | if (InitCVIRTE (hInstance, 0, 0) == 0) { |
4695 | if (InitCVIRTE (hInstance, 0, 0) == 0) { |
4612 | return -1; /* out of memory */ |
4696 | return -1; /* out of memory */ |
4613 | } |
4697 | } |
Line 4616... | Line 4700... | ||
4616 | CmtNewThreadPool (MAX_THREADS, &poolHandle); |
4700 | CmtNewThreadPool (MAX_THREADS, &poolHandle); |
4617 | 4701 | ||
4618 | if ( (status = CmtNewTSQ (1, 2*sizeof(int), OPT_TSQ_AUTO_FLUSH_ALL, &pTSQ)) <0) |
4702 | if ( (status = CmtNewTSQ (1, 2*sizeof(int), OPT_TSQ_AUTO_FLUSH_ALL, &pTSQ)) <0) |
4619 | printf("CmtNewTSQ cannot be installed\n"); |
4703 | printf("CmtNewTSQ cannot be installed\n"); |
4620 | if ( (status = CmtInstallTSQCallback (pTSQ, EVENT_TSQ_ITEMS_IN_QUEUE, EVENT_TSQ_QUEUE_SIZE, |
4704 | if ( (status = CmtInstallTSQCallback (pTSQ, EVENT_TSQ_ITEMS_IN_QUEUE, EVENT_TSQ_QUEUE_SIZE, |
4621 | QueueUserEventCallback, pTSQData, CmtGetCurrentThreadID(), NULL)) <0) |
4705 | QueueUserEventCallback, pTSQData, CmtGetCurrentThreadID(), NULL)) <0) |
4622 | printf("CmtInstallTSQCallback cannot be installed\n"); ; |
4706 | printf("CmtInstallTSQCallback cannot be installed\n"); ; |
4623 | 4707 | ||
4624 | SetStdioPort (CVI_STDIO_WINDOW ); |
4708 | SetStdioPort (CVI_STDIO_WINDOW ); |
4625 | 4709 | ||
4626 | readIni("febdaq.ini"); |
4710 | readIni("febdaq.ini"); |
Line 4641... | Line 4725... | ||
4641 | if ((p1h = LoadPanel (0, "sa02_CVI.uir", P1)) < 0) return -1; |
4725 | if ((p1h = LoadPanel (0, "sa02_CVI.uir", P1)) < 0) return -1; |
4642 | if ((p2h = LoadPanel (0, "sa02_CVI.uir", P2)) < 0) return -1; |
4726 | if ((p2h = LoadPanel (0, "sa02_CVI.uir", P2)) < 0) return -1; |
4643 | if ((p3h = LoadPanel (0, "sa02_CVI.uir", P3)) < 0) return -1; |
4727 | if ((p3h = LoadPanel (0, "sa02_CVI.uir", P3)) < 0) return -1; |
4644 | if ((p4h = V729_LoadPanel (0, "CAEN_V729\\CAEN_V729_CVI.uir", P4)) < 0) return -1; |
4728 | if ((p4h = V729_LoadPanel (0, "CAEN_V729\\CAEN_V729_CVI.uir", P4)) < 0) return -1; |
4645 | if ((p5h = LoadPanel (0, "sa02_CVI.uir", P5)) < 0) return -1; |
4729 | if ((p5h = LoadPanel (0, "sa02_CVI.uir", P5)) < 0) return -1; |
4646 | if ((p6h = LoadPanel (0, "ICFA\\minirich.uir", MINIRICH)) < 0) return -1; |
4730 | if ((p6h = LoadPanel (0, "ICFA\\minirich.uir", MINIRICH)) < 0) return -1; |
4647 | if ((pm1 = LoadMenuBar (p1h, "sa02_CVI.uir", MENU)) < 0) return -1; |
4731 | if ((pm1 = LoadMenuBar (p1h, "sa02_CVI.uir", MENU)) < 0) return -1; |
4648 | 4732 | ||
4649 | SetPanelMenuBar(p1h, pm1); |
4733 | SetPanelMenuBar(p1h, pm1); |
4650 | DisplayPanel (p1h); |
4734 | DisplayPanel (p1h); |
4651 | 4735 | ||
4652 | LoadUirHeader("sa02_CVI.h"); |
4736 | LoadUirHeader("sa02_CVI.h"); |
4653 | LoadUirHeader("CAEN_V729\\CAEN_V729_CVI.h"); |
4737 | LoadUirHeader("CAEN_V729\\CAEN_V729_CVI.h"); |
4654 | 4738 | ||
4655 | SetCtrlVal(p2h,P2_XC,gCENTER_X); |
4739 | SetCtrlVal(p2h,P2_XC,gCENTER_X); |
4656 | SetCtrlVal(p2h,P2_YC,gCENTER_Y); |
4740 | SetCtrlVal(p2h,P2_YC,gCENTER_Y); |
4657 | 4741 | ||
4658 | SetCtrlVal(p3h, P3_INPUTFILE,gFEBParam); |
4742 | SetCtrlVal(p3h, P3_INPUTFILE,gFEBParam); |
4659 | SetParametersFromFile(gFEBParam); |
4743 | SetParametersFromFile(gFEBParam); |
4660 | 4744 | ||
4661 | SetCtrlAttribute (p1h, P1_GRAPH2D, ATTR_CALLBACK_DATA, (void *)integer_val); |
4745 | SetCtrlAttribute (p1h, P1_GRAPH2D, ATTR_CALLBACK_DATA, (void *)integer_val); |
4662 | SetCtrlAttribute (p1h, P1_SLIY, ATTR_CALLBACK_DATA, (void *)integer_val); |
4746 | SetCtrlAttribute (p1h, P1_SLIY, ATTR_CALLBACK_DATA, (void *)integer_val); |
4663 | SetCtrlAttribute (p1h, P1_SLIX, ATTR_CALLBACK_DATA, (void *)integer_val); |
4747 | SetCtrlAttribute (p1h, P1_SLIX, ATTR_CALLBACK_DATA, (void *)integer_val); |
4664 | SetCtrlAttribute (p1h, P1_NSLIY, ATTR_CALLBACK_DATA, (void *)integer_val); |
4748 | SetCtrlAttribute (p1h, P1_NSLIY, ATTR_CALLBACK_DATA, (void *)integer_val); |
4665 | SetCtrlAttribute (p1h, P1_NSLIX, ATTR_CALLBACK_DATA, (void *)integer_val); |
4749 | SetCtrlAttribute (p1h, P1_NSLIX, ATTR_CALLBACK_DATA, (void *)integer_val); |
4666 | 4750 | ||
4667 | for (i=0; i<12; i++) { |
4751 | for (i=0; i<12; i++) { |
4668 | SetTraceAttributeEx (p1h, chart_control[0], i+1, ATTR_TRACE_LG_TEXT, (char *) slowcname[i]); |
4752 | SetTraceAttributeEx (p1h, chart_control[0], i+1, ATTR_TRACE_LG_TEXT, (char *) slowcname[i]); |
4669 | } |
4753 | } |
4670 | 4754 | ||
4671 | GetPanelAttribute (p1h, ATTR_TITLE, title ); |
4755 | GetPanelAttribute (p1h, ATTR_TITLE, title ); |
4672 | if (gVME_CONTROLLER == WIENER_VMEMM) sprintf( title, "%s + WIENER_VMEMM", title ); |
4756 | if (gVME_CONTROLLER == WIENER_VMEMM) sprintf( title, "%s + WIENER_VMEMM", title ); |
4673 | if (gVME_CONTROLLER == WIENER_VMUSB) sprintf( title, "%s + WIENER_VMUSB", title ); |
4757 | if (gVME_CONTROLLER == WIENER_VMUSB) sprintf( title, "%s + WIENER_VMUSB", title ); |
4674 | if (gVME_CONTROLLER == CAEN_V1718) sprintf( title, "%s + CAEN_V1718", title ); |
4758 | if (gVME_CONTROLLER == CAEN_V1718) sprintf( title, "%s + CAEN_V1718", title ); |
- | 4759 | if (gVME_CONTROLLER == SIS3153_USB) sprintf( title, "%s + SIS3153_USB", title ); |
|
4675 | if (gCAEN_V1495) sprintf( title, "%s + CAEN_V1495", title ); |
4760 | if (gCAEN_V1495) sprintf( title, "%s + CAEN_V1495", title ); |
4676 | if (gCAEN_V288 ) sprintf( title, "%s + CAEN_V288", title ); |
4761 | if (gCAEN_V288 ) sprintf( title, "%s + CAEN_V288", title ); |
4677 | 4762 | ||
4678 | if (gBELLEPTS) { |
4763 | if (gBELLEPTS) { |
4679 | sprintf( title, "%s + BELLEPTS", title ); |
4764 | sprintf( title, "%s + BELLEPTS", title ); |
Line 4690... | Line 4775... | ||
4690 | SetCtrlVal(p1h,hapd_onoff[i],gFEBMask&(1<<i)); |
4775 | SetCtrlVal(p1h,hapd_onoff[i],gFEBMask&(1<<i)); |
4691 | SetCtrlVal(p1h,P1_SENDSWTRIG,gTriggerType); |
4776 | SetCtrlVal(p1h,P1_SENDSWTRIG,gTriggerType); |
4692 | SetCtrlVal(p1h,P1_TPENB,CHECK_BIT(uInterf,0)); |
4777 | SetCtrlVal(p1h,P1_TPENB,CHECK_BIT(uInterf,0)); |
4693 | 4778 | ||
4694 | sa02SetAddress(strtoul (saddress,NULL,0)); |
4779 | sa02SetAddress(strtoul (saddress,NULL,0)); |
4695 | 4780 | ||
4696 | LedCB(p1h,P1_PTSLED,EVENT_COMMIT, NULL,0,0); |
4781 | LedCB(p1h,P1_PTSLED,EVENT_COMMIT, NULL,0,0); |
4697 | 4782 | ||
4698 | 4783 | ||
4699 | StdIo2FileCB (p1h, P1_STDIOLOG, EVENT_COMMIT, NULL,0,0); |
4784 | StdIo2FileCB (p1h, P1_STDIOLOG, EVENT_COMMIT, NULL,0,0); |
4700 | InitColors(); |
4785 | InitColors(); |
4701 | sa02Printf("Panels=%d %d %d %d\n", p1h, p2h,p3h,p4h); |
4786 | sa02Printf("Panels=%d %d %d %d\n", p1h, p2h,p3h,p4h); |
4702 | GetCtrlVal(p1h,P1_VERBOSE,&sa02Verbose); |
4787 | GetCtrlVal(p1h,P1_VERBOSE,&sa02Verbose); |
4703 | 4788 | ||
4704 | LoadElectronicMap("eid2hapdxy.map"); |
4789 | LoadElectronicMap("eid2hapdxy.map"); |
4705 | icfa_Init(); |
4790 | icfa_Init(); |
4706 | 4791 | ||
4707 | 4792 | ||
4708 | loop_on=1; |
4793 | loop_on=1; |
4709 | do { |
4794 | do { |
4710 | GetUserEvent (1, &pID, &rID); |
4795 | GetUserEvent (1, &pID, &rID); |
4711 | ProcessUserEvent(pID,rID,1); |
4796 | ProcessUserEvent(pID,rID,1); |
- | 4797 | } |
|
4712 |
|
4798 | while (loop_on); |
4713 | 4799 | ||
4714 | CmtDiscardThreadPool (poolHandle); |
4800 | CmtDiscardThreadPool (poolHandle); |
4715 | DiscardPanel (p4h); |
4801 | DiscardPanel (p4h); |
4716 | DiscardPanel (p3h); |
4802 | DiscardPanel (p3h); |
4717 | DiscardPanel (p2h); |
4803 | DiscardPanel (p2h); |
4718 | DiscardPanel (p1h); |
4804 | DiscardPanel (p1h); |
4719 | 4805 | ||
4720 | if (gMIKRO_PORT) MIKRO_Close (); |
4806 | if (gMIKRO_PORT) MIKRO_Close (); |
4721 | 4807 | ||
4722 | 4808 | ||
4723 | VME_STOP(); |
4809 | VME_STOP(); |
4724 | return 0; |
4810 | return 0; |
4725 | } |
4811 | } |
4726 | 4812 | ||
4727 | int CVICALLBACK ResetStdOut (int panel, int control, int event, |
4813 | int CVICALLBACK ResetStdOut (int panel, int control, int event, |
4728 | void *callbackData, int eventData1, int eventData2) { |
4814 | void *callbackData, int eventData1, int eventData2) { |
4729 | switch (event) { |
4815 | switch (event) { |
Line 4734... | Line 4820... | ||
4734 | return 0; |
4820 | return 0; |
4735 | } |
4821 | } |
4736 | 4822 | ||
4737 | int CVICALLBACK TrgHvMon (int panel, int control, int event, |
4823 | int CVICALLBACK TrgHvMon (int panel, int control, int event, |
4738 | void *callbackData, int eventData1, int eventData2) { |
4824 | void *callbackData, int eventData1, int eventData2) { |
4739 | switch (event) { |
4825 | switch (event) { |
4740 | case EVENT_TIMER_TICK: |
4826 | case EVENT_TIMER_TICK: |
4741 | hvmon=1; |
4827 | hvmon=1; |
4742 | break; |
4828 | break; |
4743 | } |
4829 | } |
4744 | return 0; |
4830 | return 0; |
Line 4813... | Line 4899... | ||
4813 | dummyword = 0; |
4899 | dummyword = 0; |
4814 | do { |
4900 | do { |
4815 | if( (c = getc( fp )) == EOF ) { |
4901 | if( (c = getc( fp )) == EOF ) { |
4816 | if(verbose) { |
4902 | if(verbose) { |
4817 | sa02Printf( "EOF detected. Exit.\n"); |
4903 | sa02Printf( "EOF detected. Exit.\n"); |
4818 | 4904 | ||
4819 | 4905 | ||
4820 | } |
4906 | } |
4821 | return -1; |
4907 | return -1; |
4822 | } |
4908 | } |
4823 | (c == 0xff) ? dummyword++ : (dummyword=0); |
4909 | (c == 0xff) ? dummyword++ : (dummyword=0); |
- | 4910 | } |
|
4824 |
|
4911 | while( dummyword < 4 ); |
4825 | 4912 | ||
4826 | if( mode == SLAVESERIAL_MODE ) { |
4913 | if( mode == SLAVESERIAL_MODE ) { |
4827 | if(verbose) sa02Printf("slave serial mode"); |
4914 | if(verbose) sa02Printf("slave serial mode"); |
4828 | Pts_write( addr +ADR_MODE, mode ); |
4915 | Pts_write( addr +ADR_MODE, mode ); |
4829 | Pts_erase( addr, verbose ); |
4916 | Pts_erase( addr, verbose ); |
4830 | for( j=0; j<32; j++ ) Pts_write( addr + ADR_CFG, 0x1 ); |
4917 | for( j=0; j<32; j++ ) Pts_write( addr + ADR_CFG, 0x1 ); |
4831 | while( (c=getc(fp))!=EOF ) { |
4918 | while( (c=getc(fp))!=EOF ) { |
4832 | for( j=0; j<8; j++ ) Pts_write( addr + ADR_CFG, (c>>(7-j))&0x1 ); |
4919 | for( j=0; j<8; j++ ) Pts_write( addr + ADR_CFG, (c>>(7-j))&0x1 ); |
4833 | nchar++; |
4920 | nchar++; |
4834 | if( verbose && nchar%byte_per_dot==0 ) { |
4921 | if( verbose && nchar%byte_per_dot==0 ) { |
4835 | sa02Printf( "#"); |
4922 | sa02Printf( "#"); |
4836 | } |
4923 | } |
4837 | } |
4924 | } |
- | 4925 | } |
|
4838 |
|
4926 | else if( mode == SELECTMAP_MODE ) { |
4839 | if( verbose ) sa02Printf("select map mode\n"); |
4927 | if( verbose ) sa02Printf("select map mode\n"); |
4840 | Pts_write( addr + ADR_MODE, SELECTMAP_MODE ); |
4928 | Pts_write( addr + ADR_MODE, SELECTMAP_MODE ); |
4841 | Pts_erase( addr, verbose ); |
4929 | Pts_erase( addr, verbose ); |
4842 | VME_MWRST(); |
4930 | VME_MWRST(); |
4843 | for( j=0; j<4; j++ ) Pts_Mwrite( addr + ADR_CFG, 0xff ); |
4931 | for( j=0; j<4; j++ ) Pts_Mwrite( addr + ADR_CFG, 0xff ); |
Line 4855... | Line 4943... | ||
4855 | sa02Printf( "#"); |
4943 | sa02Printf( "#"); |
4856 | 4944 | ||
4857 | } |
4945 | } |
4858 | } |
4946 | } |
4859 | VME_MWEXEC(); |
4947 | VME_MWEXEC(); |
- | 4948 | } |
|
4860 |
|
4949 | else { |
4861 | if(verbose) { |
4950 | if(verbose) { |
4862 | sa02Printf( "\nIllegal mode\n"); |
4951 | sa02Printf( "\nIllegal mode\n"); |
4863 | 4952 | ||
4864 | } |
4953 | } |
4865 | return -1; |
4954 | return -1; |
Line 4878... | Line 4967... | ||
4878 | sa02Printf("CSR1(0x%02x)=0x%04x\n",ADR_CSR1,csr1_value&0xffff); |
4967 | sa02Printf("CSR1(0x%02x)=0x%04x\n",ADR_CSR1,csr1_value&0xffff); |
4879 | } |
4968 | } |
4880 | if(csr1_value&CSR1_DONE) { |
4969 | if(csr1_value&CSR1_DONE) { |
4881 | if(verbose) sa02Printf("configure complete.\n"); |
4970 | if(verbose) sa02Printf("configure complete.\n"); |
4882 | return 1; |
4971 | return 1; |
- | 4972 | } |
|
4883 |
|
4973 | else { |
4884 | if(verbose) sa02Printf("configure not complete."); |
4974 | if(verbose) sa02Printf("configure not complete."); |
4885 | return -1; |
4975 | return -1; |
4886 | } |
4976 | } |
4887 | } |
4977 | } |
4888 | 4978 | ||
4889 | 4979 | ||
4890 | int CVICALLBACK PtsDownloadCB (int panel, int control, int event, |
4980 | int CVICALLBACK PtsDownloadCB (int panel, int control, int event, |
4891 | void *callbackData, int eventData1, int eventData2) { |
4981 | void *callbackData, int eventData1, int eventData2) { |
4892 | char filename[254]; |
4982 | char filename[254]; |
4893 | int mode=0; |
4983 | int mode=0; |
4894 | char saddress[0xFF]; |
4984 | char saddress[0xFF]; |
4895 | uint32_t addr; |
4985 | uint32_t addr; |
4896 | 4986 | ||
4897 | 4987 | ||
4898 | switch (event) { |
4988 | switch (event) { |
4899 | case EVENT_COMMIT: |
4989 | case EVENT_COMMIT: |
4900 | GetCtrlVal(p3h,P3_ADDRESS, saddress); |
4990 | GetCtrlVal(p3h,P3_ADDRESS, saddress); |
4901 | addr= strtoul (saddress,NULL,0); |
4991 | addr= strtoul (saddress,NULL,0); |
4902 | GetCtrlVal(p3h,P3_PTSFIRMWARE,filename); |
4992 | GetCtrlVal(p3h,P3_PTSFIRMWARE,filename); |
4903 | GetCtrlVal(p3h,P3_PTSMODE,&mode); |
4993 | GetCtrlVal(p3h,P3_PTSMODE,&mode); |
4904 | if(VME_CONNECTED() >=0 ) { |
4994 | if(VME_CONNECTED() >=0 ) { |
4905 | Pts_configure_bit( addr , filename, mode, 1 ); |
4995 | Pts_configure_bit( addr , filename, mode, 1 ); |
- | 4996 | } |
|
4906 |
|
4997 | else { |
4907 | MessagePopup ("Warning", "Connect VME!!"); |
4998 | MessagePopup ("Warning", "Connect VME!!"); |
4908 | } |
4999 | } |
4909 | break; |
5000 | break; |
4910 | } |
5001 | } |
4911 | return 0; |
5002 | return 0; |