Rev 57 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 57 | Rev 58 | ||
---|---|---|---|
1 | #include <windows.h> |
1 | #include <windows.h> |
2 | #include <userint.h> |
2 | #include <userint.h> |
3 | #include <utility.h> |
3 | #include <utility.h> |
4 | #include <formatio.h> |
4 | #include <formatio.h> |
5 | #include <ansi_c.h> |
5 | #include <ansi_c.h> |
6 | #include "usb.h" |
6 | #include "usb.h" |
7 | #include "xxusbdll.h" |
7 | #include "xxusbdll.h" |
8 | 8 | ||
9 | #include <cvirte.h> /* Needed if linking in external compiler; harmless otherwise */ |
9 | #include <cvirte.h> /* Needed if linking in external compiler; harmless otherwise */ |
10 | #include "uklon_ui.h" |
10 | #include "uklon_ui.h" |
11 | 11 | ||
12 | 12 | ||
13 | #define NDIS 21 |
13 | #define NDIS 21 |
14 | #define NSCA 22 |
14 | #define NSCA 22 |
15 | #define NTGG 23 |
15 | #define NTGG 23 |
16 | 16 | ||
17 | int nc[]={P1_NC0, P1_NC1, P1_NC2, P1_NC3, |
17 | int nc[]={P1_NC0, P1_NC1, P1_NC2, P1_NC3, |
18 | P1_NC4, P1_NC5, P1_NC6, P1_NC7, |
18 | P1_NC4, P1_NC5, P1_NC6, P1_NC7, |
19 | P1_NC8, P1_NC9, P1_NC10,P1_NC11, |
19 | P1_NC8, P1_NC9, P1_NC10,P1_NC11, |
20 | P1_NC12,P1_NC13,P1_NC14,P1_NC15 } ; |
20 | P1_NC12,P1_NC13,P1_NC14,P1_NC15 } ; |
21 | 21 | ||
22 | 22 | ||
23 | #define C_I CAMAC_I |
23 | #define C_I CAMAC_I |
24 | #define C_Z CAMAC_Z |
24 | #define C_Z CAMAC_Z |
25 | #define C_C CAMAC_C |
25 | #define C_C CAMAC_C |
26 | //#define C_write WUSBXX_CAMAC_write |
26 | //#define C_write WUSBXX_CAMAC_write |
27 | //#define C_read WUSBXX_CAMAC_read |
27 | //#define C_read WUSBXX_CAMAC_read |
28 | #define C_write CAMAC_write |
28 | #define C_write CAMAC_write |
29 | #define C_read CAMAC_read |
29 | #define C_read CAMAC_read |
30 | 30 | ||
31 | //******************************************************************** |
31 | //******************************************************************** |
32 | usb_dev_handle *udev; |
32 | usb_dev_handle *udev; |
33 | int Q; |
33 | int Q; |
34 | int X; |
34 | int X; |
35 | static HINSTANCE DLLHandle; |
35 | static HINSTANCE DLLHandle; |
36 | 36 | ||
37 | int WUSBXX_load (char* module_path) |
37 | int WUSBXX_load (char* module_path) |
38 | { |
38 | { |
39 | 39 | ||
40 | 40 | ||
41 | if (module_path == NULL) |
41 | if (module_path == NULL) |
42 | DLLHandle = LoadLibrary("libxxusb.dll"); |
42 | DLLHandle = LoadLibrary("libxxusb.dll"); |
43 | else |
43 | else |
44 | DLLHandle = LoadLibrary(module_path); |
44 | DLLHandle = LoadLibrary(module_path); |
45 | 45 | ||
46 | if (!(xxusb_register_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_register_read"))) return __LINE__; |
46 | if (!(xxusb_register_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_register_read"))) return __LINE__; |
47 | if (!(xxusb_stack_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_read"))) return __LINE__; |
47 | if (!(xxusb_stack_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_read"))) return __LINE__; |
48 | if (!(xxusb_stack_write_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_write"))) return __LINE__; |
48 | if (!(xxusb_stack_write_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_write"))) return __LINE__; |
49 | if (!(xxusb_stack_execute_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_execute"))) return __LINE__; |
49 | if (!(xxusb_stack_execute_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_stack_execute"))) return __LINE__; |
50 | if (!(xxusb_register_write_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_register_write"))) return __LINE__; |
50 | if (!(xxusb_register_write_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_register_write"))) return __LINE__; |
51 | if (!(xxusb_usbfifo_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_usbfifo_read"))) return __LINE__; |
51 | if (!(xxusb_usbfifo_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_usbfifo_read"))) return __LINE__; |
52 | if (!(xxusb_bulk_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_bulk_read"))) return __LINE__; |
52 | if (!(xxusb_bulk_read_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_bulk_read"))) return __LINE__; |
53 | if (!(xxusb_bulk_write_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_bulk_write"))) return __LINE__; |
53 | if (!(xxusb_bulk_write_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_bulk_write"))) return __LINE__; |
54 | if (!(xxusb_reset_toggle_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_reset_toggle"))) return __LINE__; |
54 | if (!(xxusb_reset_toggle_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_reset_toggle"))) return __LINE__; |
55 | 55 | ||
56 | if (!(xxusb_devices_find_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_devices_find"))) return __LINE__; |
56 | if (!(xxusb_devices_find_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_devices_find"))) return __LINE__; |
57 | if (!(xxusb_device_close_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_device_close"))) return __LINE__; |
57 | if (!(xxusb_device_close_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_device_close"))) return __LINE__; |
58 | if (!(xxusb_device_open_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_device_open"))) return __LINE__; |
58 | if (!(xxusb_device_open_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_device_open"))) return __LINE__; |
59 | if (!(xxusb_flash_program_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_flash_program"))) return __LINE__; |
59 | if (!(xxusb_flash_program_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_flash_program"))) return __LINE__; |
60 | if (!(xxusb_flashblock_program_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_flashblock_program"))) return __LINE__; |
60 | if (!(xxusb_flashblock_program_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_flashblock_program"))) return __LINE__; |
61 | if (!(xxusb_serial_open_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_serial_open"))) return __LINE__; |
61 | if (!(xxusb_serial_open_Ptr = (void*) GetProcAddress(DLLHandle,"xxusb_serial_open"))) return __LINE__; |
62 | 62 | ||
63 | if (!(VME_register_write_Ptr = (void*) GetProcAddress(DLLHandle,"VME_register_write"))) return __LINE__; |
63 | if (!(VME_register_write_Ptr = (void*) GetProcAddress(DLLHandle,"VME_register_write"))) return __LINE__; |
64 | if (!(VME_register_read_Ptr = (void*) GetProcAddress(DLLHandle,"VME_register_read"))) return __LINE__; |
64 | if (!(VME_register_read_Ptr = (void*) GetProcAddress(DLLHandle,"VME_register_read"))) return __LINE__; |
65 | if (!(VME_LED_settings_Ptr = (void*) GetProcAddress(DLLHandle,"VME_LED_settings"))) return __LINE__; |
65 | if (!(VME_LED_settings_Ptr = (void*) GetProcAddress(DLLHandle,"VME_LED_settings"))) return __LINE__; |
66 | if (!(VME_DGG_Ptr = (void*) GetProcAddress(DLLHandle,"VME_DGG"))) return __LINE__; |
66 | if (!(VME_DGG_Ptr = (void*) GetProcAddress(DLLHandle,"VME_DGG"))) return __LINE__; |
67 | if (!(VME_Output_settings_Ptr = (void*) GetProcAddress(DLLHandle,"VME_Output_settings"))) return __LINE__; |
67 | if (!(VME_Output_settings_Ptr = (void*) GetProcAddress(DLLHandle,"VME_Output_settings"))) return __LINE__; |
68 | if (!(VME_read_16_Ptr = (void*) GetProcAddress(DLLHandle,"VME_read_16"))) return __LINE__; |
68 | if (!(VME_read_16_Ptr = (void*) GetProcAddress(DLLHandle,"VME_read_16"))) return __LINE__; |
69 | if (!(VME_read_32_Ptr = (void*) GetProcAddress(DLLHandle,"VME_read_32"))) return __LINE__; |
69 | if (!(VME_read_32_Ptr = (void*) GetProcAddress(DLLHandle,"VME_read_32"))) return __LINE__; |
70 | if (!(VME_BLT_read_32_Ptr = (void*) GetProcAddress(DLLHandle,"VME_BLT_read_32"))) return __LINE__; |
70 | if (!(VME_BLT_read_32_Ptr = (void*) GetProcAddress(DLLHandle,"VME_BLT_read_32"))) return __LINE__; |
71 | if (!(VME_write_16_Ptr = (void*) GetProcAddress(DLLHandle,"VME_write_16"))) return __LINE__; |
71 | if (!(VME_write_16_Ptr = (void*) GetProcAddress(DLLHandle,"VME_write_16"))) return __LINE__; |
72 | if (!(VME_write_32_Ptr = (void*) GetProcAddress(DLLHandle,"VME_write_32"))) return __LINE__; |
72 | if (!(VME_write_32_Ptr = (void*) GetProcAddress(DLLHandle,"VME_write_32"))) return __LINE__; |
73 | 73 | ||
74 | if (!(CAMAC_DGG_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_DGG"))) return __LINE__; |
74 | if (!(CAMAC_DGG_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_DGG"))) return __LINE__; |
75 | if (!(CAMAC_register_read_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_register_read"))) return __LINE__; |
75 | if (!(CAMAC_register_read_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_register_read"))) return __LINE__; |
76 | if (!(CAMAC_register_write_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_register_write"))) return __LINE__; |
76 | if (!(CAMAC_register_write_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_register_write"))) return __LINE__; |
77 | if (!(CAMAC_LED_settings_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_LED_settings"))) return __LINE__; |
77 | if (!(CAMAC_LED_settings_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_LED_settings"))) return __LINE__; |
78 | if (!(CAMAC_Output_settings_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_Output_settings"))) return __LINE__; |
78 | if (!(CAMAC_Output_settings_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_Output_settings"))) return __LINE__; |
79 | if (!(CAMAC_read_LAM_mask_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_read_LAM_mask"))) return __LINE__; |
79 | if (!(CAMAC_read_LAM_mask_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_read_LAM_mask"))) return __LINE__; |
80 | if (!(CAMAC_write_LAM_mask_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_write_LAM_mask"))) return __LINE__; |
80 | if (!(CAMAC_write_LAM_mask_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_write_LAM_mask"))) return __LINE__; |
81 | if (!(CAMAC_write_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_write"))) return __LINE__; |
81 | if (!(CAMAC_write_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_write"))) return __LINE__; |
82 | if (!(CAMAC_read_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_read"))) return __LINE__; |
82 | if (!(CAMAC_read_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_read"))) return __LINE__; |
83 | if (!(CAMAC_Z_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_Z"))) return __LINE__; |
83 | if (!(CAMAC_Z_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_Z"))) return __LINE__; |
84 | if (!(CAMAC_C_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_C"))) return __LINE__; |
84 | if (!(CAMAC_C_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_C"))) return __LINE__; |
85 | if (!(CAMAC_I_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_I"))) return __LINE__; |
85 | if (!(CAMAC_I_Ptr = (void*) GetProcAddress(DLLHandle,"CAMAC_I"))) return __LINE__; |
86 | return 0; |
86 | return 0; |
87 | } |
87 | } |
88 | 88 | ||
89 | 89 | ||
90 | void WUSBXX_open (char *serial) |
90 | void WUSBXX_open (char *serial) |
91 | { |
91 | { |
92 | if (serial != NULL) |
92 | if (serial != NULL) |
93 | udev = xxusb_serial_open(serial); |
93 | udev = xxusb_serial_open(serial); |
94 | if (!udev) |
94 | if (!udev) |
95 | MessagePopup ("Error", "Cannot connect to USB. ! Check the connection!"); |
95 | MessagePopup ("Error", "Cannot connect to USB. ! Check the connection!"); |
96 | } |
96 | } |
97 | 97 | ||
98 | void WUSBXX_close (void) |
98 | void WUSBXX_close (void) |
99 | { |
99 | { |
100 | if (udev) xxusb_device_close(udev); |
100 | if (udev) xxusb_device_close(udev); |
101 | } |
101 | } |
102 | 102 | ||
103 | int WUSBXX_CAMAC_write( usb_dev_handle *udev, int N, int A, int F, long Data, int *Q, int *X); |
103 | int WUSBXX_CAMAC_write( usb_dev_handle *udev, int N, int A, int F, long Data, int *Q, int *X); |
104 | int WUSBXX_CAMAC_read( usb_dev_handle *udev,int N, int A, int F, long *Data, int *Q, int *X); |
104 | int WUSBXX_CAMAC_read( usb_dev_handle *udev,int N, int A, int F, long *Data, int *Q, int *X); |
105 | int WUSBXX_CAMAC_Z( usb_dev_handle *udev ); |
105 | int WUSBXX_CAMAC_Z( usb_dev_handle *udev ); |
106 | int WUSBXX_CAMAC_C( usb_dev_handle *udev ); |
106 | int WUSBXX_CAMAC_C( usb_dev_handle *udev ); |
107 | int WUSBXX_CAMAC_I(usb_dev_handle *udev, int inhibit); |
107 | int WUSBXX_CAMAC_I(usb_dev_handle *udev, int inhibit); |
108 | 108 | ||
109 | int WUSBXX_CAMAC_write( usb_dev_handle *udev,int N, int A, int F, long Data, int *Q, int *X) |
109 | int WUSBXX_CAMAC_write( usb_dev_handle *udev,int N, int A, int F, long Data, int *Q, int *X) |
110 | { |
110 | { |
111 | long intbuf[4]; |
111 | long intbuf[4]; |
112 | int ret; |
112 | int ret; |
113 | // CAMAC direct write function |
113 | // CAMAC direct write function |
114 | intbuf[0]=1; |
114 | intbuf[0]=1; |
115 | intbuf[1]=(long)(F+A*32+N*512 + 0x4000); |
115 | intbuf[1]=(long)(F+A*32+N*512 + 0x4000); |
116 | if ((F > 15) && (F < 24)) // orig controla |
116 | if ((F > 15) && (F < 24)) // orig controla |
117 | //if ((F > 15) && (F < 28)) // orig controla |
117 | //if ((F > 15) && (F < 28)) // orig controla |
118 | { |
118 | { |
119 | intbuf[0]=3; |
119 | intbuf[0]=3; |
120 | intbuf[2]=(Data & 0xffff); |
120 | intbuf[2]=(Data & 0xffff); |
121 | intbuf[3]=((Data >>16) & 255); |
121 | intbuf[3]=((Data >>16) & 255); |
122 | ret = xxusb_stack_execute(udev, intbuf); |
122 | ret = xxusb_stack_execute(udev, intbuf); |
123 | *Q = (intbuf[0] & 1); |
123 | *Q = (intbuf[0] & 1); |
124 | *X = ((intbuf[0] >> 1) & 1); |
124 | *X = ((intbuf[0] >> 1) & 1); |
125 | } else { |
125 | } else { |
126 | printf("Error N%d A%d F%d",N,A,F); |
126 | printf("Error N%d A%d F%d",N,A,F); |
127 | } |
127 | } |
128 | return ret; |
128 | return ret; |
129 | } |
129 | } |
130 | 130 | ||
131 | int WUSBXX_CAMAC_read( usb_dev_handle *udev,int N, int A, int F, long *Data, int *Q, int *X) |
131 | int WUSBXX_CAMAC_read( usb_dev_handle *udev,int N, int A, int F, long *Data, int *Q, int *X) |
132 | { |
132 | { |
133 | long intbuf[4]; |
133 | long intbuf[4]; |
134 | int ret; |
134 | int ret; |
135 | // CAMAC direct read function |
135 | // CAMAC direct read function |
136 | intbuf[0]=1; |
136 | intbuf[0]=1; |
137 | intbuf[1]=(long)(F+A*32+N*512 + 0x4000); |
137 | intbuf[1]=(long)(F+A*32+N*512 + 0x4000); |
138 | // intbuf[1]=(long)(F+A*32+N*512); |
138 | // intbuf[1]=(long)(F+A*32+N*512); |
139 | ret = xxusb_stack_execute(udev, intbuf); |
139 | ret = xxusb_stack_execute(udev, intbuf); |
140 | // printf ("ret = %d\n",ret); |
140 | // printf ("ret = %d\n",ret); |
141 | if (F < 16) // orig controla |
141 | if (F < 16) // orig controla |
142 | { |
142 | { |
143 | // *Data = intbuf[0]; //16-bit word |
143 | // *Data = intbuf[0]; //16-bit word |
144 | *Data = intbuf[0] + (intbuf[1] & 0xFF) * 0x10000; //24-bit word |
144 | *Data = intbuf[0] + (intbuf[1] & 0xFF) * 0x10000; //24-bit word |
145 | *Q = ((intbuf[1] >> 8) & 1); |
145 | *Q = ((intbuf[1] >> 8) & 1); |
146 | *X = ((intbuf[1] >> 9) & 1); |
146 | *X = ((intbuf[1] >> 9) & 1); |
147 | } |
147 | } |
148 | // else { |
148 | // else { |
149 | // printf("Error N%d A%d F%d",N,A,F); |
149 | // printf("Error N%d A%d F%d",N,A,F); |
150 | // } |
150 | // } |
151 | return ret; |
151 | return ret; |
152 | } |
152 | } |
153 | 153 | ||
154 | int WUSBXX_CAMAC_Z(usb_dev_handle *udev) |
154 | int WUSBXX_CAMAC_Z(usb_dev_handle *udev) |
155 | { |
155 | { |
156 | long intbuf[4]; |
156 | long intbuf[4]; |
157 | int ret; |
157 | int ret; |
158 | // CAMAC Z = N(28) A(8) F(29) |
158 | // CAMAC Z = N(28) A(8) F(29) |
159 | intbuf[0]=1; |
159 | intbuf[0]=1; |
160 | intbuf[1]=(long)(29+8*32+28*512 + 0x4000); |
160 | intbuf[1]=(long)(29+8*32+28*512 + 0x4000); |
161 | ret = xxusb_stack_execute(udev, intbuf); |
161 | ret = xxusb_stack_execute(udev, intbuf); |
162 | return ret; |
162 | return ret; |
163 | } |
163 | } |
164 | 164 | ||
165 | int WUSBXX_CAMAC_C(usb_dev_handle *udev) |
165 | int WUSBXX_CAMAC_C(usb_dev_handle *udev) |
166 | { |
166 | { |
167 | long intbuf[4]; |
167 | long intbuf[4]; |
168 | int ret; |
168 | int ret; |
169 | // CAMAC C = N(28) A(9) F(29) |
169 | // CAMAC C = N(28) A(9) F(29) |
170 | intbuf[0]=1; |
170 | intbuf[0]=1; |
171 | intbuf[1]=(long)(29+9*32+28*512 + 0x4000); |
171 | intbuf[1]=(long)(29+9*32+28*512 + 0x4000); |
172 | ret = xxusb_stack_execute( udev, intbuf); |
172 | ret = xxusb_stack_execute( udev, intbuf); |
173 | return ret; |
173 | return ret; |
174 | } |
174 | } |
175 | 175 | ||
176 | int WUSBXX_CAMAC_I(usb_dev_handle *udev, int inhibit) |
176 | int WUSBXX_CAMAC_I(usb_dev_handle *udev, int inhibit) |
177 | { |
177 | { |
178 | long intbuf[4]; |
178 | long intbuf[4]; |
179 | int ret; |
179 | int ret; |
180 | // Set Inhibit = N(29) A(9) F(24) |
180 | // Set Inhibit = N(29) A(9) F(24) |
181 | // Clear Inhibit = N(29) A(9) F(26) |
181 | // Clear Inhibit = N(29) A(9) F(26) |
182 | intbuf[0]=1; |
182 | intbuf[0]=1; |
183 | if (inhibit) intbuf[1]=(long)(24+9*32+29*512 + 0x4000); |
183 | if (inhibit) intbuf[1]=(long)(24+9*32+29*512 + 0x4000); |
184 | else intbuf[1]=(long)(26+9*32+29*512 + 0x4000); |
184 | else intbuf[1]=(long)(26+9*32+29*512 + 0x4000); |
185 | ret = xxusb_stack_execute(udev, intbuf); |
185 | ret = xxusb_stack_execute(udev, intbuf); |
186 | return ret; |
186 | return ret; |
187 | } |
187 | } |
188 | 188 | ||
189 | int init_CAMAC () { |
189 | int init_CAMAC () { |
190 | 190 | ||
191 | long dum; |
191 | long dum; |
192 | C_Z(udev); |
192 | C_Z(udev); |
193 | C_C(udev); |
193 | C_C(udev); |
194 | C_I(udev,1); |
194 | C_I(udev,1); |
195 | 195 | ||
196 | C_read ( udev,NTGG, 0 , 9, &dum, &Q,&X); /* init TGG */ |
196 | C_read ( udev,NTGG, 0 , 9, &dum, &Q,&X); /* init TGG */ |
197 | C_write ( udev,NTGG, 0, 16, 1000, &Q,&X); /* Set preset counting value */ |
197 | C_write ( udev,NTGG, 0, 16, 1000, &Q,&X); /* Set preset counting value */ |
198 | C_write ( udev,NTGG, 0 ,17, 0x2, &Q,&X); /* Set Load&Clock Modes */ |
198 | C_write ( udev,NTGG, 0 ,17, 0x2, &Q,&X); /* Set Load&Clock Modes */ |
199 | C_write ( udev,NDIS, 0, 16, 0xffff, &Q,&X); /* enable all ch. */ |
199 | C_write ( udev,NDIS, 0, 16, 0xffff, &Q,&X); /* enable all ch. */ |
200 | C_read ( udev,NDIS, 0, 26, &dum, &Q, &X); |
200 | C_read ( udev,NDIS, 0, 26, &dum, &Q, &X); |
201 | 201 | ||
202 | C_I(udev, 0); |
202 | C_I(udev, 0); |
203 | 203 | ||
204 | return 0 ; |
204 | return 0 ; |
205 | } |
205 | } |
206 | 206 | ||
207 | //******************************************************************** |
207 | //******************************************************************** |
208 | 208 | ||
209 | int plot_graph ( int p1h, int logsc, int data[16] ) { |
209 | int plot_graph ( int p1h, int logsc, int data[16] ) { |
210 | int max, max_I2 ; |
210 | int max, max_I2 ; |
211 | double plot_data[16], plot_max ; |
211 | double plot_data[16], plot_max ; |
212 | int ch ; |
212 | int ch ; |
213 | 213 | ||
214 | max = 100 ; |
214 | max = 100 ; |
215 | for ( ch=0 ; ch<16 ; ch ++ ) { |
215 | for ( ch=0 ; ch<16 ; ch ++ ) { |
216 | if ( data[ch]>max ) max=data[ch] ; |
216 | if ( data[ch]>max ) max=data[ch] ; |
217 | } |
217 | } |
218 | 218 | ||
219 | DeleteGraphPlot (p1h, P1_HISTO, -1, VAL_IMMEDIATE_DRAW); |
219 | DeleteGraphPlot (p1h, P1_HISTO, -1, VAL_IMMEDIATE_DRAW); |
220 | 220 | ||
221 | max = ((max*1.2)/1000)*1000 ; |
221 | max = ((max*1.2)/1000)*1000 ; |
222 | GetCtrlVal (p1h, P1_I2, &max_I2 ) ; |
222 | GetCtrlVal (p1h, P1_I2, &max_I2 ) ; |
223 | if ( max_I2>0 ) max=max_I2 ; |
223 | if ( max_I2>0 ) max=max_I2 ; |
224 | 224 | ||
225 | if ( logsc ) { |
225 | if ( logsc ) { |
226 | 226 | ||
227 | for ( ch=0 ; ch<16 ; ch ++ ) { |
227 | for ( ch=0 ; ch<16 ; ch ++ ) { |
228 | plot_data[ch] = log10((double)data[ch]) ; |
228 | plot_data[ch] = log10((double)data[ch]) ; |
229 | plot_max = log10((double)max) ; |
229 | plot_max = log10((double)max) ; |
230 | } |
230 | } |
231 | 231 | ||
232 | SetAxisScalingMode (p1h, P1_HISTO, VAL_LEFT_YAXIS, VAL_MANUAL, 0.0, plot_max); |
232 | SetAxisScalingMode (p1h, P1_HISTO, VAL_LEFT_YAXIS, VAL_MANUAL, 0.0, plot_max); |
233 | PlotY (p1h, P1_HISTO, plot_data, 16, VAL_DOUBLE, VAL_VERTICAL_BAR, |
233 | PlotY (p1h, P1_HISTO, plot_data, 16, VAL_DOUBLE, VAL_VERTICAL_BAR, |
234 | VAL_NO_POINT, VAL_SOLID, 1, VAL_DK_BLUE); |
234 | VAL_NO_POINT, VAL_SOLID, 1, VAL_DK_BLUE); |
235 | 235 | ||
236 | 236 | ||
237 | } else { |
237 | } else { |
238 | SetAxisScalingMode (p1h, P1_HISTO, VAL_LEFT_YAXIS, VAL_MANUAL, 0.0, max); |
238 | SetAxisScalingMode (p1h, P1_HISTO, VAL_LEFT_YAXIS, VAL_MANUAL, 0.0, max); |
239 | PlotY (p1h, P1_HISTO, data, 16, VAL_INTEGER, VAL_VERTICAL_BAR, |
239 | PlotY (p1h, P1_HISTO, data, 16, VAL_INTEGER, VAL_VERTICAL_BAR, |
240 | VAL_NO_POINT, VAL_SOLID, 1, VAL_DK_BLUE); |
240 | VAL_NO_POINT, VAL_SOLID, 1, VAL_DK_BLUE); |
241 | 241 | ||
242 | for ( ch=0; ch<16; ch++ ) { |
242 | for ( ch=0; ch<16; ch++ ) { |
243 | SetCtrlVal (p1h, nc[ch], data[ch] ) ; |
243 | SetCtrlVal (p1h, nc[ch], data[ch] ) ; |
244 | } |
244 | } |
245 | } |
245 | } |
246 | 246 | ||
247 | 247 | ||
248 | return 0 ; |
248 | return 0 ; |
249 | } |
249 | } |
250 | 250 | ||
251 | 251 | ||
252 | //******************************************************************** |
252 | //******************************************************************** |
253 | //******************************************************************** |
253 | //******************************************************************** |
254 | 254 | ||
255 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
255 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
256 | LPSTR lpszCmdLine, int nCmdShow) |
256 | LPSTR lpszCmdLine, int nCmdShow) |
257 | { |
257 | { |
258 | int rph, rID, p1h, p2h ; |
258 | int rph, rID, p1h, p2h ; |
259 | int data[16], sum, max, max_I2=0 ; |
259 | int data[16], sum, max, max_I2=0 ; |
260 | long val, dum; |
260 | long val, dum; |
261 | double plot_data[16], splot_data[10][32], plot_max ; |
261 | double plot_data[16], splot_data[10][32], plot_max ; |
262 | int thr_set, time_set; |
262 | int thr_set, time_set; |
263 | int ch, i, j,ii; |
263 | int ch, i, j,ii; |
264 | 264 | ||
265 | FILE *fp ; |
265 | FILE *fp ; |
266 | char filename[256] ; |
266 | char filename[256] ; |
267 | int logscale ; |
267 | int logscale ; |
268 | int os[10]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1} ; |
268 | int os[10]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1} ; |
269 | 269 | ||
270 | logscale = 0 ; |
270 | logscale = 0 ; |
271 | 271 | ||
272 | if (InitCVIRTE (hInstance, 0, 0) == 0) /* Needed if linking in external compiler; harmless otherwise */ |
272 | if (InitCVIRTE (hInstance, 0, 0) == 0) /* Needed if linking in external compiler; harmless otherwise */ |
273 | return -1; /* out of memory */ |
273 | return -1; /* out of memory */ |
274 | 274 | ||
275 | for ( i=0; i<16; data[i++]=0 ) ; |
275 | for ( i=0; i<16; data[i++]=0 ) ; |
276 | 276 | ||
277 | 277 | ||
278 | 278 | ||
279 | dum=WUSBXX_load (NULL); |
279 | dum=WUSBXX_load (NULL); |
280 | if (dum) MessagePopup ("Error", "Cannot load dll!"); |
280 | if (dum) MessagePopup ("Error", "Cannot load dll!"); |
281 | WUSBXX_open ("CC0130"); |
281 | WUSBXX_open ("CC0130"); |
282 | 282 | ||
283 | //ii=80000000/i-40; |
283 | //ii=80000000/i-40; |
284 | //if (ii<72) ii=72; |
284 | //if (ii<72) ii=72; |
285 | //CAMAC_DGG(udev,0,7,0,ii,40,0,0); |
285 | //CAMAC_DGG(udev,0,7,0,ii,40,0,0); |
286 | //CAMAC_DGG(udev,1,1,1,12,8,0,0); |
286 | //CAMAC_DGG(udev,1,1,1,12,8,0,0); |
287 | 287 | ||
288 | 288 | ||
289 | init_CAMAC(); |
289 | init_CAMAC(); |
290 | 290 | ||
291 | p1h = LoadPanel (0, "uklon_ui.uir", P1); |
291 | p1h = LoadPanel (0, "uklon_ui.uir", P1); |
292 | // p2h = LoadPanel (0, "uklon_ui.uir", P2); |
292 | // p2h = LoadPanel (0, "uklon_ui.uir", P2); |
293 | DisplayPanel (p1h); |
293 | DisplayPanel (p1h); |
294 | // DisplayPanel (p2h); |
294 | // DisplayPanel (p2h); |
295 | 295 | ||
296 | GetUserEvent (1, &rph, &rID); |
296 | GetUserEvent (1, &rph, &rID); |
297 | 297 | ||
298 | 298 | ||
299 | while ((rID!=P1_QUIT)||(rph!=p1h)) |
299 | while ((rID!=P1_QUIT)||(rph!=p1h)) |
300 | { |
300 | { |
301 | if ( rph == p1h ) { |
301 | if ( rph == p1h ) { |
302 | if ( rID==P1_START ) { |
302 | if ( rID==P1_START ) { |
303 | GetCtrlVal (p1h, P1_THR, &thr_set ) ; /* read desired thr. */ |
303 | GetCtrlVal (p1h, P1_THR, &thr_set ) ; /* read desired thr. */ |
304 | C_write ( udev, NDIS, 0, 17, thr_set, &Q, &X); /* set the threshold */ |
304 | C_write ( udev, NDIS, 0, 17, thr_set, &Q, &X); /* set the threshold */ |
305 | C_write ( udev, NDIS, 1, 17, 0, &Q,&X); /* */ |
305 | C_write ( udev, NDIS, 1, 17, 0, &Q,&X); /* */ |
306 | 306 | ||
307 | C_read ( udev, NSCA,0,9,&dum, &Q,&X); |
307 | C_read ( udev, NSCA,0,9,&dum, &Q,&X); |
308 | 308 | ||
309 | GetCtrlVal (p1h, P1_TIME, &time_set ) ; /* read time (ms) */ |
309 | GetCtrlVal (p1h, P1_TIME, &time_set ) ; /* read time (ms) */ |
310 | 310 | ||
311 | SetCtrlAttribute (p1h, P1_TIMER, ATTR_ENABLED, 0); |
311 | SetCtrlAttribute (p1h, P1_TIMER, ATTR_ENABLED, 0); |
312 | C_write ( udev, NTGG, 0, 16, time_set, &Q,&X); |
312 | C_write ( udev, NTGG, 0, 16, time_set, &Q,&X); |
313 | C_read ( udev, NTGG, 0, 15, &dum, &Q,&X); |
313 | C_read ( udev, NTGG, 0, 15, &dum, &Q,&X); |
314 | 314 | ||
315 | SetCtrlVal (p1h, P1_LEDON,1); |
315 | SetCtrlVal (p1h, P1_LEDON,1); |
316 | SetCtrlAttribute (p1h, P1_TIMER, ATTR_INTERVAL,time_set*0.001 ); |
316 | SetCtrlAttribute (p1h, P1_TIMER, ATTR_INTERVAL,time_set*0.001 ); |
317 | SetCtrlAttribute (p1h, P1_TIMER, ATTR_ENABLED, 1); |
317 | SetCtrlAttribute (p1h, P1_TIMER, ATTR_ENABLED, 1); |
318 | ResetTimer (p1h, P1_TIMER); |
318 | ResetTimer (p1h, P1_TIMER); |
319 | Delay (0.1+(time_set/1000.)); |
319 | Delay (0.1+(time_set/1000.)); |
320 | } |
320 | } |
321 | 321 | ||
322 | if ( rID==P1_COUNT ) { |
322 | if ( rID==P1_COUNT ) { |
323 | sum = 0 ; |
323 | sum = 0 ; |
324 | max = 100 ; |
324 | max = 100 ; |
325 | C_I(udev, 1); |
325 | C_I(udev, 1); |
326 | for ( ch=0 ; ch<16 ; ch ++ ) { |
326 | for ( ch=0 ; ch<16 ; ch ++ ) { |
327 | Delay(0.01); |
327 | Delay(0.01); |
328 | C_read ( udev, NSCA, ch, 0, &val, &Q,&X); |
328 | C_read ( udev, NSCA, ch, 0, &val, &Q,&X); |
329 | C_read ( udev, NSCA, ch, 0, &val, &Q,&X); |
329 | C_read ( udev, NSCA, ch, 0, &val, &Q,&X); |
- | 330 | // CC USB ne precita v redu CAEN C257 scalerja, |
|
- | 331 | // kanali so zamaknjeni za 1, ce je klic samo en |
|
- | 332 | // vrednost kanala 0 se pristeje h kanalom 8..16, zato ga ne uporabljamo. |
|
- | 333 | // vajo iyvedemo le s kanali 1..15. |
|
330 | data[ch]=val; |
334 | data[ch]=val; |
331 | 335 | ||
332 | if (data[ch] > 0) data[ch]--; |
336 | if (data[ch] > 0) data[ch]--; |
333 | // if (data[ch] && 0x80000000) { |
337 | // if (data[ch] && 0x80000000) { |
334 | // data[ch] &= 0x00FFFFFF; |
338 | // data[ch] &= 0x00FFFFFF; |
335 | 339 | ||
336 | //} |
340 | //} |
337 | 341 | ||
338 | sum += data[ch] ; |
342 | sum += data[ch] ; |
339 | } |
343 | } |
340 | C_I(udev, 0); |
344 | C_I(udev, 0); |
341 | SetCtrlVal (p1h, P1_I1, sum ) ; |
345 | SetCtrlVal (p1h, P1_I1, sum ) ; |
342 | plot_graph ( p1h, logscale, data ) ; |
346 | plot_graph ( p1h, logscale, data ) ; |
343 | } |
347 | } |
344 | if ( rID==P1_INIT ) { |
348 | if ( rID==P1_INIT ) { |
345 | init_CAMAC ( ) ; |
349 | init_CAMAC ( ) ; |
346 | } |
350 | } |
347 | 351 | ||
348 | if ( rID==P1_SAVE ) { |
352 | if ( rID==P1_SAVE ) { |
349 | if ( ( fp = fopen ( "scaler.txt", "w+" ) ) == NULL ) printf ( "ERROR" ) ; |
353 | if ( ( fp = fopen ( "scaler.txt", "w+" ) ) == NULL ) printf ( "ERROR" ) ; |
350 | for ( ch=0; ch<16 ; ch++ ) { |
354 | for ( ch=0; ch<16 ; ch++ ) { |
351 | fprintf ( fp, "%d\t%d\n", ch, data[ch] ) ; |
355 | fprintf ( fp, "%d\t%d\n", ch, data[ch] ) ; |
352 | } |
356 | } |
353 | fclose ( fp ) ; |
357 | fclose ( fp ) ; |
354 | } |
358 | } |
355 | 359 | ||
356 | if ( rID==P1_APPEND ) { |
360 | if ( rID==P1_APPEND ) { |
357 | GetCtrlVal (p1h, P1_APFILE, filename); |
361 | GetCtrlVal (p1h, P1_APFILE, filename); |
358 | 362 | ||
359 | if ( ( fp = fopen ( filename, "a" ) ) == NULL ) printf ( "ERROR" ) ; |
363 | if ( ( fp = fopen ( filename, "a" ) ) == NULL ) printf ( "ERROR" ) ; |
360 | for ( ch=0; ch<16 ; ch++ ) { |
364 | for ( ch=0; ch<16 ; ch++ ) { |
361 | fprintf ( fp, "%d\t", data[ch] ) ; |
365 | fprintf ( fp, "%d\t", data[ch] ) ; |
362 | } |
366 | } |
363 | fprintf ( fp, "\n" ) ; |
367 | fprintf ( fp, "\n" ) ; |
364 | fclose ( fp ) ; |
368 | fclose ( fp ) ; |
365 | } |
369 | } |
366 | 370 | ||
367 | if ( rID==P1_REPLOT ) { |
371 | if ( rID==P1_REPLOT ) { |
368 | plot_graph ( p1h, logscale, data ) ; |
372 | plot_graph ( p1h, logscale, data ) ; |
369 | } |
373 | } |
370 | 374 | ||
371 | 375 | ||
372 | if ( rID == P1_PRINT ) { |
376 | if ( rID == P1_PRINT ) { |
373 | SetCtrlVal (p1h, P1_L1,1); |
377 | SetCtrlVal (p1h, P1_L1,1); |
374 | PrintPanel (p1h, "", 1, VAL_VISIBLE_AREA, 1); |
378 | PrintPanel (p1h, "", 1, VAL_VISIBLE_AREA, 1); |
375 | SetCtrlVal (p1h, P1_L1,0); |
379 | SetCtrlVal (p1h, P1_L1,0); |
376 | } |
380 | } |
377 | 381 | ||
378 | 382 | ||
379 | if ( rID == P1_LOG_SCALE ) { |
383 | if ( rID == P1_LOG_SCALE ) { |
380 | GetCtrlVal (p1h, P1_LOG_SCALE, &logscale) ; |
384 | GetCtrlVal (p1h, P1_LOG_SCALE, &logscale) ; |
381 | 385 | ||
382 | plot_graph ( p1h, logscale, data ) ; |
386 | plot_graph ( p1h, logscale, data ) ; |
383 | } |
387 | } |
384 | } |
388 | } |
385 | 389 | ||
386 | if ( rph == p2h ) { |
390 | if ( rph == p2h ) { |
387 | switch ( rID ) { |
391 | switch ( rID ) { |
388 | case P2_OFS1: GetCtrlVal (p2h, P2_OFS1, &os[0] ) ; i=0 ; break ; |
392 | case P2_OFS1: GetCtrlVal (p2h, P2_OFS1, &os[0] ) ; i=0 ; break ; |
389 | case P2_OFS2: GetCtrlVal (p2h, P2_OFS2, &os[1] ) ; i=1 ; break ; |
393 | case P2_OFS2: GetCtrlVal (p2h, P2_OFS2, &os[1] ) ; i=1 ; break ; |
390 | case P2_OFS3: GetCtrlVal (p2h, P2_OFS3, &os[2] ) ; i=2 ; break ; |
394 | case P2_OFS3: GetCtrlVal (p2h, P2_OFS3, &os[2] ) ; i=2 ; break ; |
391 | case P2_OFS4: GetCtrlVal (p2h, P2_OFS4, &os[3] ) ; i=3 ; break ; |
395 | case P2_OFS4: GetCtrlVal (p2h, P2_OFS4, &os[3] ) ; i=3 ; break ; |
392 | case P2_OFS5: GetCtrlVal (p2h, P2_OFS5, &os[4] ) ; i=4 ; break ; |
396 | case P2_OFS5: GetCtrlVal (p2h, P2_OFS5, &os[4] ) ; i=4 ; break ; |
393 | case P2_OFS6: GetCtrlVal (p2h, P2_OFS6, &os[5] ) ; i=5 ; break ; |
397 | case P2_OFS6: GetCtrlVal (p2h, P2_OFS6, &os[5] ) ; i=5 ; break ; |
394 | case P2_OFS7: GetCtrlVal (p2h, P2_OFS7, &os[6] ) ; i=6 ; break ; |
398 | case P2_OFS7: GetCtrlVal (p2h, P2_OFS7, &os[6] ) ; i=6 ; break ; |
395 | case P2_OFS8: GetCtrlVal (p2h, P2_OFS8, &os[7] ) ; i=7 ; break ; |
399 | case P2_OFS8: GetCtrlVal (p2h, P2_OFS8, &os[7] ) ; i=7 ; break ; |
396 | case P2_OFS9: GetCtrlVal (p2h, P2_OFS9, &os[8] ) ; i=8 ; break ; |
400 | case P2_OFS9: GetCtrlVal (p2h, P2_OFS9, &os[8] ) ; i=8 ; break ; |
397 | case P2_OFS10: GetCtrlVal (p2h, P2_OFS10, &os[9] ) ; i=9 ; break ; |
401 | case P2_OFS10: GetCtrlVal (p2h, P2_OFS10, &os[9] ) ; i=9 ; break ; |
398 | } |
402 | } |
399 | 403 | ||
400 | 404 | ||
401 | } |
405 | } |
402 | 406 | ||
403 | GetUserEvent (1, &rph, &rID); |
407 | GetUserEvent (1, &rph, &rID); |
404 | } |
408 | } |
405 | 409 | ||
406 | 410 | ||
407 | WUSBXX_close (); |
411 | WUSBXX_close (); |
408 | //lc8901a_close (hdev); |
412 | //lc8901a_close (hdev); |
409 | return 0; |
413 | return 0; |
410 | } |
414 | } |
411 | 415 | ||
412 | int CVICALLBACK TimerCB (int panel, int control, int event, |
416 | int CVICALLBACK TimerCB (int panel, int control, int event, |
413 | void *callbackData, int eventData1, int eventData2) |
417 | void *callbackData, int eventData1, int eventData2) |
414 | { |
418 | { |
415 | switch (event) |
419 | switch (event) |
416 | { |
420 | { |
417 | case EVENT_TIMER_TICK: |
421 | case EVENT_TIMER_TICK: |
418 | 422 | ||
419 | SetCtrlVal (panel, P1_LEDON,0); |
423 | SetCtrlVal (panel, P1_LEDON,0); |
420 | SetCtrlAttribute (panel, P1_TIMER, ATTR_ENABLED, 0); |
424 | SetCtrlAttribute (panel, P1_TIMER, ATTR_ENABLED, 0); |
421 | break; |
425 | break; |
422 | } |
426 | } |
423 | return 0; |
427 | return 0; |
424 | } |
428 | } |
425 | 429 |