DAS  3.1.6 - 18/09/2017
Spat_Device.c
Go to the documentation of this file.
1 #include <windows.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <fcntl.h>
6 #include <io.h>
7 #include <math.h>
8 #include <sys\stat.h>
9 #include <time.h>
10 #include <sys/types.h>
11 #include <sys/timeb.h>
12 #include "mgui.h"
13 #include "DAS_Spatram.h"
14 #include "dcl.h"
15 #include "dxl.h"
16 
18 //cpl CPL; //Control Panel
19 flag FLAG; //flags structure
20 //pbutt PBUTT; //Command Button
21 //stepm STEPM; //Stepper Motors
22 GratingSt GRS; //Grating
23 //hrizmeas HMEAS;
24 ZenithSt ZST; //Zenith
25 AzimuthSt AST; //Azimuth
26 //mige MIGE;
28 
34 /*
35  **********************************************************************
36  * Module : Spat_Device *
37  * Description : Program to handle spectrometer DEVICES *
38  * Motor 0 --> Input Mirror *
39  * Motor 1 --> Grating *
40  * Motor 2 --> Filter Wheel *
41  **********************************************************************
42 */
43 
44 
45 
46 
47 
48 void writelogmotor(int mod, int id_motore, int k, int d, long steps, unsigned char ams_id)
49 {
50  int fc;
51  char str[250];
52  char str1[30];
53  char timebuf[9];
54  char datebuf[9];
55 
56  if (mod==0)
57  {
58  if(id_motore==0)
59  sprintf(str1,"Input Mirror");
60  if(id_motore==1)
61  sprintf(str1,"Grating ");
62  if(id_motore==2)
63  sprintf(str1,"Filter Wheel");
64  if(id_motore==4)
65  sprintf(str1,"Zenith ");
66  if(id_motore==5)
67  sprintf(str1,"Azimuth ");
68 
69  fc = open(DLOG.fsmlog, O_WRONLY | O_APPEND | O_TEXT | O_CREAT, S_IWRITE);
70 
71  if(fc > 0)
72  {
73  _strtime(timebuf);
74  _strdate(datebuf);
75 
76 
77 // sprintf(str, "%s, err = %d, from AMS%u, dir=%d, Steps=%ld, Steps(esa)=%lX, DXL.buftx=%s, DXL.bufrx=%s\n",
78 // str1, k, ams_id, d, steps, steps, DXL.buftx, DXL.bufrx);
79 // write(fc, str, strlen(str));
80 
81  sprintf(str, "%s at %s: %s, from AMS%u, dir=%d, Steps=%ld, Steps(esa)=%lX, DXL.buftx=%s, DXL.bufrx=%s\n",
82  datebuf, timebuf, str1, ams_id, d, steps, steps, DXL.buftx, DXL.bufrx);
83  write(fc, str, strlen(str));
84 
85  }
86 
87  close(fc);
88  }
89  // For the AMS initialization
90  if (mod == 1)
91  {
92 
93  if(id_motore==0)
94  sprintf(str1,"Input Mirror");
95  if(id_motore==1)
96  sprintf(str1,"Grating ");
97  if(id_motore==2)
98  sprintf(str1,"Filter Wheel");
99 
100 
101 
102  fc = open("LOG\\logSM.log", O_WRONLY | O_APPEND | O_TEXT | O_CREAT, S_IWRITE);
103 
104  if(fc > 0)
105  {
106 
107  _strtime(timebuf);
108  _strdate(datebuf);
109 
110  sprintf(str, "%s at %s, AMSs Init with\n ", datebuf, timebuf);
111  write(fc, str, strlen(str));
112 
113 // sprintf(str, "%s :\n Power:%d (%.1lf%%), Step: %d (%s), Slope: %d, Speed: %d (%.3lf) \n",str1, DAS.StepM.cop[id_motore], DAS.StepM.cop_perc[id_motore], DAS.StepM.step[id_motore], DAS.StepM.step_fraz[id_motore], DAS.StepM.slope[id_motore], DAS.StepM.speed[id_motore], DAS.StepM.speed_Hz[id_motore]);
114  write(fc, str, strlen(str));
115 
116  }
117 
118  close(fc);
119  }
120 
121 
122 
123 }
124 
125 
126 
127 
128 
129 float SMfraz(int t)
130 {
131  int c = t;
132  float r;
133 
134  switch(c)
135  {
136  case 0:
137  r = 1;
138  break;
139  case 1:
140  r = 2;
141  break;
142  case 2 :
143  r = 2.5;
144  break;
145  case 3:
146  r = 4;
147  break;
148  case 4 :
149  r = 5;
150  break;
151  case 5:
152  r = 8;
153  break;
154  case 6 :
155  r = 12.5;
156  break;
157  case 7:
158  r = 16;
159  break;
160  case 8 :
161  r = 25;
162  break;
163  case 9:
164  r = 32;
165  break;
166  case 10 :
167  r = 62.5;
168  break;
169  case 11:
170  r = 64;
171  break;
172  case 12 :
173  r = 125;
174  break;
175  case 13:
176  r = 128;
177  break;
178 
179  }
180 
181  return r;
182 
183 
184 }
185 
209 int SM_stepr(int t)
210 {
211 
212 
213 
214 
215  int c = t;
216  int r;
217 
218  switch(c)
219  {
220  case 0:
221  r = 400;
222  break;
223  case 1:
224  r = 800;
225  break;
226  case 2 :
227  r = 1000;
228  break;
229  case 3:
230  r = 1600;
231  break;
232  case 4 :
233  r = 2000;
234  break;
235  case 5:
236  r = 3200;
237  break;
238  case 6 :
239  r = 5000;
240  break;
241  case 7:
242  r = 6400;
243  break;
244  case 8 :
245  r = 10000;
246  break;
247  case 9:
248  r = 12800;
249  break;
250  case 10 :
251  r = 25000;
252  break;
253  case 11:
254  r = 25600;
255  break;
256  case 12 :
257  r = 50000;
258  break;
259  case 13:
260  r = 51200;
261  break;
262 
263  }
264 
265  return r;
266 
267 
268 }
269 
270 /*
271 void D_SimultPositioning(MOBJECT p, int id, long tout)
272 {
273  unsigned long st, et, x;
274  char buf[80];
275 
276  if (DAS.Flag.exemode == DBDEMO)
277  tout = 2000;
278 
279 
280  st = GetTickCount();
281  do
282  {
283  et = GetTickCount();
284  x = labs(et - st);
285  MLoopWhileEvents(0);
286  if((x % 10) == 0 && x > 0)
287  {
288  D_VRangeSim(NULL, (long) x * 100 / tout, 255, 0, 0 );
289  sprintf(buf, "%.1lf sec. left", (double)fabs(((double)(labs(et - st) - tout))/1000.0 ));
290  MObjectSetText(p, buf);
291  }
292  }while(labs(et - st) < tout);
293 
294 }
295 
296 */
297 
298 
299 void WriteLogAMS(int id, int dira, int dirb, unsigned long stepa, unsigned long stepb)
300 {
301 
302  int fc;
303  char str[250];
304  char str1[30];
305  char str2[30];
306  char timebuf[9];
307  char datebuf[9];
308 
309  _strtime(timebuf);
310  _strdate(datebuf);
311 
312  if(id==0)
313  {
314  if(stepa && (stepb==0))
315  {
316  sprintf(str1,"Input Mirror");
317  fc = open(DLOG.fsmlog, O_WRONLY | O_APPEND | O_TEXT | O_CREAT, S_IWRITE);
318  if(fc)
319  {
320  sprintf(str, "%s at %s: %s, from AMS%u, dir=%d, Steps=%ld, Steps(esa)=%lX, DXL.buftx=%s, DXL.bufrx=%s\n", datebuf, timebuf, str1, id, dira, stepa, stepa, DXL.buftx, DXL.bufrx);
321  write(fc, str, strlen(str));
322  }
323  close(fc);
324 
325  }
326  if(stepb && (stepa==0))
327  {
328  sprintf(str1,"Grating ");
329  fc = open(DLOG.fsmlog, O_WRONLY | O_APPEND | O_TEXT | O_CREAT, S_IWRITE);
330  if(fc)
331  {
332  sprintf(str, "%s at %s: %s, from AMS%u, dir=%d, Steps=%ld, Steps(esa)=%lX, DXL.buftx=%s, DXL.bufrx=%s\n", datebuf, timebuf, str1, id, dirb, stepb, stepb, DXL.buftx, DXL.bufrx);
333  write(fc, str, strlen(str));
334  }
335  close(fc);
336 
337  }
338  if(stepa && stepb)
339  {
340  sprintf(str1,"Input Mirror");
341  sprintf(str2,"Grating ");
342  fc = open(DLOG.fsmlog, O_WRONLY | O_APPEND | O_TEXT | O_CREAT, S_IWRITE);
343  if(fc)
344  {
345  sprintf(str, "%s at %s: %s, from AMS%u, dir=%d, Steps=%ld, Steps(esa)=%lX, DXL.buftx=%s, DXL.bufrx=%s\n", datebuf, timebuf, str1, id, dira, stepa, stepa, DXL.buftx, DXL.bufrx);
346  write(fc, str, strlen(str));
347  sprintf(str, "%s at %s: %s, from AMS%u, dir=%d, Steps=%ld, Steps(esa)=%lX, DXL.buftx=%s, DXL.bufrx=%s\n", datebuf, timebuf, str2, id, dirb, stepb, stepb, DXL.buftx, DXL.bufrx);
348  write(fc, str, strlen(str));
349  }
350  close(fc);
351  }
352 
353  }
354 
355  if(id==1)
356  {
357  if(stepa && (stepb==0))
358  {
359  sprintf(str1,"Filter Wheel");
360  fc = open(DLOG.fsmlog, O_WRONLY | O_APPEND | O_TEXT | O_CREAT, S_IWRITE);
361  if(fc)
362  {
363  sprintf(str, "%s at %s: %s, from AMS%u, dir=%d, Steps=%ld, Steps(esa)=%lX, DXL.buftx=%s, DXL.bufrx=%s\n", datebuf, timebuf, str1, id, dira, stepa, stepa, DXL.buftx, DXL.bufrx);
364  write(fc, str, strlen(str));
365  }
366  close(fc);
367 
368  }
369  if(stepb && (stepa==0))
370  {
371  sprintf(str2,"SPARE ");
372  fc = open(DLOG.fsmlog, O_WRONLY | O_APPEND | O_TEXT | O_CREAT, S_IWRITE);
373  if(fc)
374  {
375  sprintf(str, "%s at %s: %s, from AMS%u, dir=%d, Steps=%ld, Steps(esa)=%lX, DXL.buftx=%s, DXL.bufrx=%s\n",
376  datebuf, timebuf, str2, id, dirb, stepb, stepb, DXL.buftx, DXL.bufrx);
377  write(fc, str, strlen(str));
378  }
379  close(fc);
380 
381  }
382  if(stepa && stepb)
383  {
384  sprintf(str1,"Filter Wheel");
385  sprintf(str2,"SPARE ");
386  fc = open(DLOG.fsmlog, O_WRONLY | O_APPEND | O_TEXT | O_CREAT, S_IWRITE);
387  if(fc)
388  {
389  sprintf(str, "%s at %s: %s, from AMS%u, dir=%d, Steps=%ld, Steps(esa)=%lX, DXL.buftx=%s, DXL.bufrx=%s\n", datebuf, timebuf, str1, id, dira, stepa, stepa, DXL.buftx, DXL.bufrx);
390  write(fc, str, strlen(str));
391  sprintf(str, "%s at %s: %s, from AMS%u, dir=%d, Steps=%ld, Steps(esa)=%lX, DXL.buftx=%s, DXL.bufrx=%s\n", datebuf, timebuf, str2, id, dirb, stepb, stepb, DXL.buftx, DXL.bufrx);
392  write(fc, str, strlen(str));
393  }
394  close(fc);
395  }
396  }
397 
398  if(id==2)
399  {
400  if(stepa && (stepb==0))
401  {
402  sprintf(str1,"Zenith ");
403  fc = open(DLOG.fsmlog, O_WRONLY | O_APPEND | O_TEXT | O_CREAT, S_IWRITE);
404  if(fc)
405  {
406  sprintf(str, "%s at %s: %s, from AMS%u, dir=%d, Steps=%ld, Steps(esa)=%lX, DXL.buftx=%s, DXL.bufrx=%s\n",
407  datebuf, timebuf, str1, id, dira, stepa, stepa, DXL.buftx, DXL.bufrx);
408  write(fc, str, strlen(str));
409  }
410  close(fc);
411 
412  }
413  if(stepb && (stepa==0))
414  {
415  sprintf(str2,"Azimuth ");
416  fc = open(DLOG.fsmlog, O_WRONLY | O_APPEND | O_TEXT | O_CREAT, S_IWRITE);
417  if(fc)
418  {
419  sprintf(str, "%s at %s: %s, from AMS%u, dir=%d, Steps=%ld, Steps(esa)=%lX, DXL.buftx=%s, DXL.bufrx=%s\n",
420  datebuf, timebuf, str2, id, dirb, stepb, stepb, DXL.buftx, DXL.bufrx);
421  write(fc, str, strlen(str));
422  }
423  close(fc);
424 
425  }
426  if(stepa && stepb)
427  {
428  sprintf(str1,"Zenith ");
429  sprintf(str2,"Azimuth ");
430  fc = open(DLOG.fsmlog, O_WRONLY | O_APPEND | O_TEXT | O_CREAT, S_IWRITE);
431  if(fc)
432  {
433  sprintf(str, "%s at %s: %s, from AMS%u, dir=%d, Steps=%ld, Steps(esa)=%lX, DXL.buftx=%s, DXL.bufrx=%s\n", datebuf, timebuf, str1, id, dira, stepa, stepa, DXL.buftx, DXL.bufrx);
434  write(fc, str, strlen(str));
435  sprintf(str, "%s at %s: %s, from AMS%u, dir=%d, Steps=%ld, Steps(esa)=%lX, DXL.buftx=%s, DXL.bufrx=%s\n", datebuf, timebuf, str2, id, dirb, stepb, stepb, DXL.buftx, DXL.bufrx);
436  write(fc, str, strlen(str));
437  }
438  close(fc);
439  }
440  }
441 
442 }
443 
444 
445 
446 
447 int SD_PosAADev(double z, double a)
448 {
449 
450  int k, i, s, dir;
451  float GRASTEP, STEPGRA;
452  long minpostime = 2147483647, maxpostime = 0;
453  long st, et, tt, n;
454  double ttout = 0, yy;
455  char buf[80];
456  long dp = 500; // dp are the dead pulse, they have to be added for backlash recovery
457  //float MAZMax = 120.0; //MIGE Azimut MAX
458  //float MAZMin = -60.0; //MIGE Azimut Min
459  float rzenang, razang, az;
460 
461  float MAZMax = 90.0; //MIGE Azimut MAX
462  float MAZMin = -90.0; //MIGE Azimut Min
463 
464 
465  k=DAS.StepM.NAMS-1;
466  for (i=0;i<2;i++)
467  {
468  s = 2 * k + i;
469  DD_VOpen[s] = 0;
470  }
471 
472 
473  //a --> Azimuth
474 
475  //Azimuth positioning
476  razang=MIGEAz((float)a);
477 
478  k = SM_stepr(DAS.StepM.step[AMS3][DAS.StepM.SM_B]); // step/round
479 
480  GRASTEP = (float)360.0 / (float) k; // degree/step
481 
482  STEPGRA = (float) k / (float)360.0; // step/degree
483 
484  yy = (razang - AST.Pos);
485 
486  n = (long) (yy * STEPGRA * DAS.StepM.multiplier[AMS3][1]);
487 
488  AST.Pos = razang;
489  AST.realazpos = a;
490 
491  // Select direction
492  if(n < 0)
493  dir = 1;
494  else
495  dir = 0;
496 
497  n = labs(n);
498  DAS.StepM.Revo[AMS3][DAS.StepM.SM_B] = dir;
499  DAS.StepM.nstep[AMS3][DAS.StepM.SM_B] = n;
500 
501 /**************************************************************************/
502  /*******************************/
503  //z --> Zenith
504  //if(z >= -91 && z <= 45 )
505 // if(z >= -90 && z <= 90 )
506  //Zenith positioning
507  rzenang=MIGEZen((float)z);
508 
509  if(z >= 0 && z <= 180 )
510  {
511 
512  k = SM_stepr(DAS.StepM.step[AMS3][DAS.StepM.SM_A]); // step/round
513 
514  GRASTEP = (float) 360.0 / (float) k; // degree/step
515 
516  STEPGRA = (float) k / (float) 360.0; // step/degree
517 
518 // yy = -(z - ZST.Pos);
519  yy = -(rzenang - ZST.Pos);
520  n = (long)(yy * STEPGRA * (DAS.StepM.multiplier[AMS3][0]));
521 // ZST.Pos = z;
522  ZST.Pos = rzenang;
523  ZST.realzenpos = z;
524  // Select direction
525  if(n < 0)
526  dir = 1;
527  else
528  dir = 0;
529 
530  n = labs(n);
531  DAS.StepM.Revo[AMS3][DAS.StepM.SM_A] = dir;
532  DAS.StepM.nstep[AMS3][DAS.StepM.SM_A] = n;
533  }
534  else
535  {
536  DAS.StepM.Revo[AMS3][DAS.StepM.SM_A] = 0;
537  DAS.StepM.nstep[AMS3][DAS.StepM.SM_A] = 0;
538  sprintf(buf, "Not Allowed Zen.");
539  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[4], buf);
540 
541  }
542 
543 
544 /**************************************************************************/
545  // Tout computation and Max finding
546  k=DAS.StepM.NAMS-1;
547  for (i=0;i<2;i++)
548  {
549  DAS.StepM.postime[k][i] = (long) (DAS.StepM.nstep[k][i]/(float) DAS.StepM.speed_Hz[k][i]);
550  if (DAS.StepM.postime[k][i] >= maxpostime) maxpostime = DAS.StepM.postime[k][i];
551  if (DAS.StepM.postime[k][i] <= minpostime) minpostime = DAS.StepM.postime[k][i];
552  }
553 /*************************************************************************/
554 
555 /**************************************************************************/
556  // Init Progression bar
557  k=DAS.StepM.NAMS-1;
558  for (i=0;i<2;i++)
559  {
560  if (DAS.StepM.nstep[k][i] != 0)
561  {
562  s = 2*k+i;
563  switch (s)
564  {
565  case 0:
566  if(DAS.DOption.amsprogbar)
567  D_VRangeSim(0, "Positioning Mirror",0, 255, 0, 0, 50, 0);
568  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledoff.bmp");
569 
570  break;
571  case 1:
572  if(DAS.DOption.amsprogbar)
573  D_VRangeSim(1, "Positioning Grating",0, 255, 255, 0, 50, 100);
574  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledoff.bmp");
575  break;
576  case 2:
577  if(DAS.DOption.amsprogbar)
578  D_VRangeSim(2, "Positioning Filter Wheel",0, 0, 0, 255, 50, 200);
579  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledoff.bmp");
580  break;
581  case 3:
582  break;
583  case 4:
584  if(DAS.DOption.amsprogbar)
585  if(DAS.DOption.aaopmode == 2)
586  {
587  D_VRangeSim(4,"Positioning Zenith",0, 0, 255, 255, 50, 300);
588 
589  }
590  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledoff.bmp");
591  break;
592  case 5:
593  if(DAS.DOption.amsprogbar)
594  if(DAS.DOption.aaopmode == 2)
595  {
596  D_VRangeSim(5,"Positioning Azimuth",0, 0, 192, 255, 50, 400);
597 
598  }
599  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledoff.bmp");
600  break;
601 
602 
603  }
604  }
605  }
606 
607 /*************************************************************************/
608 
609 /**************************************************************************/
610  // Send step
611  if (DAS.Flag.exemode != DBDEMO)
612  {
613  k=DAS.StepM.NAMS-1;
614  AMS_sendstep(k, DAS.StepM.Revo[k][DAS.StepM.SM_A], DAS.StepM.Revo[k][DAS.StepM.SM_B],
615  DAS.StepM.nstep[k][DAS.StepM.SM_A], DAS.StepM.nstep[k][DAS.StepM.SM_B]);
616 
617  WriteLogAMS(k, DAS.StepM.Revo[k][DAS.StepM.SM_A], DAS.StepM.Revo[k][DAS.StepM.SM_B],
618  DAS.StepM.nstep[k][DAS.StepM.SM_A], DAS.StepM.nstep[k][DAS.StepM.SM_B]);
619 
620  }
621 
622  //Time Out loop
623  st = GetTickCount();
624  do
625  {
626  et = GetTickCount();
627  tt = labs(et - st);
628  MLoopWhileEvents(0);
629  if(tt > 0)
630  {
631  if(DD_VOpen[4])
632  {
633  if(DAS.DOption.amsprogbar)
634  D_VRangeSim(4, NULL,(unsigned long) tt * 100 / DAS.StepM.postime[AMS3][0], 0, 255, 255, 50, 300);
635  if (tt >= DAS.StepM.postime[AMS3][0])
636  {
637  sprintf(buf, "%.1lf", z);
638  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[4], buf);
639  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[2][0], "SYS\\ledGreen.bmp");
640  }
641  else
642  {
643  sprintf(buf, "%.1lf sec. left", (double)fabs(((double)(tt - DAS.StepM.postime[AMS3][0]))/1000.0 ));
644  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[4], buf);
645  }
646  }
647  else
648  {
649  if (tt >= DAS.StepM.postime[AMS3][0])
650  {
651  sprintf(buf, "%.1lf", ZST.realzenpos);
652 
653  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[4], buf);
654  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[2][0], "SYS\\ledGreen.bmp");
655  }
656  else
657  {
658  sprintf(buf, "%.1lf sec. left", (double)fabs(((double)(tt - DAS.StepM.postime[AMS3][0]))/1000.0 ));
659  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[4], buf);
660  }
661 
662  }
663 
664  if(DD_VOpen[5])
665  {
666  if(DAS.DOption.amsprogbar)
667  D_VRangeSim(5, NULL,(unsigned long) tt * 100 / DAS.StepM.postime[AMS3][1], 0, 192, 255, 50, 400);
668  if (labs(et - st) >= DAS.StepM.postime[AMS3][1])
669  {
670  az = (float)S_azim;
671  //sprintf(buf, "%.1lf %.1lf", az, a );
672  sprintf(buf, "%.1lf", AST.realazpos);
673  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[5], buf);
674  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[2][1], "SYS\\ledGreen.bmp");
675  }
676  else
677  {
678  sprintf(buf, "%.1lf sec. left", (double)fabs(((double)(tt - DAS.StepM.postime[AMS3][1]))/1000.0 ));
679  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[5], buf);
680  }
681  }
682  else
683  {
684  if (labs(et - st) >= DAS.StepM.postime[AMS3][1])
685  {
686  az = (float)S_azim;
687  //sprintf(buf, "%.1lf %.1lf", az, a );
688  sprintf(buf, " %.1lf", AST.realazpos );
689  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[5], buf);
690  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[2][1], "SYS\\ledGreen.bmp");
691  }
692  else
693  {
694  sprintf(buf, "%.1lf sec. left", (double)fabs(((double)(tt - DAS.StepM.postime[AMS3][1]))/1000.0 ));
695  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[5], buf);
696  }
697 
698  }
699 
700 
701  }
702  }while((tt < maxpostime));
703 /**************************************************************************/
704 
705 /**************************************************************************/
706 
707  // Check if all the progression bars have been destroyed.
708  // If not the active one is destroyed and the apprpriate label is written
709  k=DAS.StepM.NAMS-1;
710  for (i=0;i<2;i++)
711  {
712  s = 2*k+i;
713  if(DD_VOpen[s])
714  {
715  if(DAS.DOption.amsprogbar)
716  D_VRangeSim(s, NULL, 100, 0, 0, 0, 0, 0);
717  switch (s)
718  {
719  case 4:
720  sprintf(buf, "%.1lf", z);
721  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[4], buf);
722  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledGreen.bmp");
723  break;
724  case 5:
725  sprintf(buf, "%.1lf", (double) a);
726  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[5], buf);
727  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledGreen.bmp");
728  break;
729 
730 
731  }
732  }
733  }
734 
735 
736 
737 return 0;
738 
739 }
740 
741 
742 // perform the simoultaneous positioning of the Spectrometer Devices in the OMU module
743 // m = mirror
744 // w = wavelength (Grating)
745 // f = filter wheel
746 
747 int SD_PosOMUDev(int m, int w, int f)
748 {
749 
750  int k, i, s, er, dir;
751  int backlash = 0;
752 // float GRASTEP, STEPGRA;
753  long minpostime = 2147483647, maxpostime = 0;
754  long st, et, tt, n;
755  double ttout = 0;
756  char buf[80], str[16];
757  long dp = 500; // dp sono i dead pulse, vanno aggiunti all'inversione per il recupero del gioco
758  int StepWithOffset [4][4];
759  float g = 0;
760 
761  for(k=0;k<DAS.StepM.NAMS;k++)
762  { for (i=0;i<2;i++)
763  {
764  s = 2 * k + i;
765  DD_VOpen[s] = 0;
766  }
767  }
768  /*******************************/
769 
770  if((m >= 0) && (m <= 3))
771  {
772  k = SM_stepr(DAS.StepM.step[AMS1][DAS.StepM.SM_A]) * 6 / 4;
773 /* er = (long)(MIS.Pos - m);
774  switch (er)
775  {
776  case 0:
777  n = 0;
778  break;
779  case 1:
780  n = er * k * 3;
781  break;
782  case -3:
783  case -1:
784  case 2:
785  case (-2):
786  n = er * k;
787  break;
788  case 3:
789  n = er * k / 3;
790  break;
791 
792  }
793 
794  */
795  k = SM_stepr(DAS.StepM.step[AMS1][0]) * DAS.StepM.multiplier[AMS1][0] / 4; //4 is the number of positions
796 
797  StepWithOffset [0][0] = 0;
798  StepWithOffset [0][1] = 3*k - DAS.Paramini.Offset[2];
799  StepWithOffset [0][2] = 2*k - DAS.Paramini.Offset[3];
800  StepWithOffset [0][3] = k - DAS.Paramini.Offset[4];
801 
802  StepWithOffset [1][0] = k + DAS.Paramini.Offset[2];
803  StepWithOffset [1][1] = 0;
804  StepWithOffset [1][2] = 3*k - DAS.Paramini.Offset[3] + DAS.Paramini.Offset[2];
805  StepWithOffset [1][3] = 2*k - DAS.Paramini.Offset[4]+ DAS.Paramini.Offset[2];
806 
807  StepWithOffset [2][0] = 2*k + DAS.Paramini.Offset[3];
808  StepWithOffset [2][1] = k - DAS.Paramini.Offset[2]+DAS.Paramini.Offset[3];
809  StepWithOffset [2][2] = 0;
810  StepWithOffset [2][3] = 3*k - DAS.Paramini.Offset[4]+DAS.Paramini.Offset[3];
811 
812  StepWithOffset [3][0] = 3*k + DAS.Paramini.Offset[4];
813  StepWithOffset [3][1] = 2*k - DAS.Paramini.Offset[2]+ DAS.Paramini.Offset[4];
814  StepWithOffset [3][2] = k - DAS.Paramini.Offset[3] + DAS.Paramini.Offset[4];
815  StepWithOffset [3][3] = 0;
816 
817  n = StepWithOffset [m][MIS.Pos];
818 
819 
820 
821  dir = 1;
822  //n = labs(n);
823  DAS.StepM.Revo[AMS1][DAS.StepM.SM_A] = dir;
824  DAS.StepM.nstep[AMS1][DAS.StepM.SM_A] = n;
825  MIS.Pos = m;
826  }
827  else
828  {
829  DAS.StepM.Revo[AMS1][DAS.StepM.SM_A] = 0;
830  DAS.StepM.nstep[AMS1][DAS.StepM.SM_A] = 0;
831 
832  }
833 
834  /******************************/
835  /******************************/
836  //w - Grating position section
837  if(w >= 0 && w <= 17)
838  {
839  g = (float) SM_stepr(DAS.StepM.step[AMS1][1])/3200;
840  n = (long)(((float) (-wav[GRS.Wl] + wav[w]) ) * 4 * g);
841 
842  if(n < 0)
843  dir = 1;
844  else
845  {
846  dir = 0;
847  backlash = 1; //for the backlash recovery
848  }
849  n = labs(n);
850 
851 
852  if(n && dir == 0) //si va verso l'UV
853  n += GRS.dp; // // add fixed step number for backlash recovery
854 
855  DAS.StepM.Revo[AMS1][DAS.StepM.SM_B] = dir;
856  DAS.StepM.nstep[AMS1][DAS.StepM.SM_B] = n;
857  GRS.Wl = w;
858  }
859  else
860  {
861  DAS.StepM.Revo[AMS1][DAS.StepM.SM_B] = 0;
862  DAS.StepM.nstep[AMS1][DAS.StepM.SM_B] = 0;
863 
864  }
865  /*******************************/
866  /*******************************/
867  // f - Filter wheel Section
868 
869  //8 holes....
870  if(DAS.Paramini.EqType == LIS_)
871  {
872  k = SM_stepr(DAS.StepM.step[AMS2][DAS.StepM.SM_A]) / 8;
873  if(f >= 0 && f <= 8)
874  {
875  n= (long)(FWS.Pos - f) * k;
876  if(n < 0)
877  dir = 1;
878  else
879  dir = 0;
880 
881  n = labs(n);
882  DAS.StepM.Revo[AMS2][DAS.StepM.SM_A] = dir;
883  DAS.StepM.nstep[AMS2][DAS.StepM.SM_A] = n;
884  FWS.Pos = f;
885  }
886  else
887  {
888  n = 0;
889  DAS.StepM.Revo[AMS2][DAS.StepM.SM_A] = 0;
890  DAS.StepM.nstep[AMS2][DAS.StepM.SM_A] = 0;
891  }
892 
893 
894  }
895  // ...or 6 holes....
896  if (DAS.Paramini.EqType == SPATRAM ||
897  DAS.Paramini.EqType == GASCODNG1 ||
898  DAS.Paramini.EqType == SPATRAMPLUS ||
899  DAS.Paramini.EqType == TROPOGAS ||
900  DAS.Paramini.EqType == GASCODNG2 ||
901  DAS.Paramini.EqType == GASCODNG3 ||
902  DAS.Paramini.EqType == GASCODNG4 ||
903  DAS.Paramini.EqType == SPATRAM3 ||
904  DAS.Paramini.EqType == SPATRAM2 )
905  {
906  k = SM_stepr(DAS.StepM.step[AMS2][DAS.StepM.SM_A]) / 6;
907  if(f >= 0 && f <= 5)
908  {
909  n= (long)(FWS.Pos - f) * k;
910  if(n < 0)
911  dir = 1;
912  else
913  dir = 0;
914 
915  n = labs(n);
916  DAS.StepM.Revo[AMS2][DAS.StepM.SM_A] = dir;
917  DAS.StepM.nstep[AMS2][DAS.StepM.SM_A] = n;
918  FWS.Pos = f;
919  }
920  else
921  {
922  n = 0;
923  DAS.StepM.Revo[AMS2][DAS.StepM.SM_A] = 0;
924  DAS.StepM.nstep[AMS2][DAS.StepM.SM_A] = 0;
925  }
926  }
927 
928 /**************************************************************************/
929  // Tout computation and Max finding
930  for(k=0;k<2;k++)
931  {
932  for (i=0;i<2;i++)
933  {
934  DAS.StepM.postime[k][i] = (long)( DAS.StepM.nstep[k][i]/(float) DAS.StepM.speed_Hz[k][i]);
935  if (DAS.StepM.postime[k][i] >= maxpostime) maxpostime = DAS.StepM.postime[k][i];
936  if (DAS.StepM.postime[k][i] <= minpostime) minpostime = DAS.StepM.postime[k][i];
937  }
938  }
939 /*************************************************************************/
940 
941  // Init Progression bar
942  for(k=0;k<2;k++)
943  {
944  for (i=0;i<2;i++)
945  {
946  if (DAS.StepM.nstep[k][i] != 0)
947  {
948  s = 2*k+i;
949  switch (s)
950  {
951  case 0:
952  if(DAS.DOption.amsprogbar)
953  D_VRangeSim(0, "Positioning Mirror",0, 255, 0, 0, 50, 0);
954  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledoff.bmp");
955 
956  break;
957  case 1:
958  if(DAS.DOption.amsprogbar)
959  D_VRangeSim(1, "Positioning Grating",0, 255, 255, 0, 50, 100);
960  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledoff.bmp");
961  break;
962  case 2:
963  if(DAS.DOption.amsprogbar)
964  D_VRangeSim(2, "Positioning Filter Wheel",0, 0, 0, 255, 50, 200);
965  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledoff.bmp");
966  break;
967  case 3:
968  break;
969  }
970  }
971  }
972  }
973 
974 /*************************************************************************/
975 
976 /**************************************************************************/
977  // Send step
978  if (DAS.Flag.exemode != DBDEMO)
979  {
980 
981  for(k=0;k<2;k++)
982  {
983  AMS_sendstep(k, DAS.StepM.Revo[k][DAS.StepM.SM_A], DAS.StepM.Revo[k][DAS.StepM.SM_B],
984  DAS.StepM.nstep[k][DAS.StepM.SM_A], DAS.StepM.nstep[k][DAS.StepM.SM_B]);
985 
986  WriteLogAMS(k, DAS.StepM.Revo[k][DAS.StepM.SM_A], DAS.StepM.Revo[k][DAS.StepM.SM_B],
987  DAS.StepM.nstep[k][DAS.StepM.SM_A], DAS.StepM.nstep[k][DAS.StepM.SM_B]);
988 
989  }
990  }
991 /**************************************************************************/
992 
993  //Time Out loop
994  st = GetTickCount();
995  do
996  {
997  et = GetTickCount();
998  tt = labs(et - st);
999  MLoopWhileEvents(0);
1000  if(tt > 0)
1001  {
1002 
1003  if(DD_VOpen[0])
1004  {
1005  if(DAS.DOption.amsprogbar)
1006  D_VRangeSim(0 ,NULL,(unsigned long) tt * 100 / DAS.StepM.postime[AMS1][0], 255, 0, 0, 50, 0);
1007  sprintf(buf, "%.1f sec. left", (double)fabs(((double)(tt - DAS.StepM.postime[AMS1][0]))/1000.0 ));
1008  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[0], buf);
1009  if (tt >= DAS.StepM.postime[AMS1][0])
1010  {
1011  if (DAS.Paramini.EqType == TROPOGAS || DAS.Paramini.EqType == SPATRAM3 || DAS.Paramini.EqType == GASCODNG4)
1012  sprintf(str, "%s",Mir_CodeTropo[m]);
1013  else
1014  sprintf(str, "%s",Mir_Code[m]);
1015 
1016  sprintf(buf, "%s", str);
1017  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[0], buf);
1018  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[0][0], "SYS\\ledGreen.bmp");
1019 
1020  }
1021  }
1022  else
1023  {
1024  sprintf(buf, "%.1f sec. left", (double)fabs(((double)(tt - DAS.StepM.postime[AMS1][0]))/1000.0 ));
1025  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[0], buf);
1026  if (tt >= DAS.StepM.postime[AMS1][0])
1027  {
1028  if (m != -1)
1029  {
1030  if (DAS.Paramini.EqType == TROPOGAS || DAS.Paramini.EqType == SPATRAM3 || DAS.Paramini.EqType == GASCODNG4)
1031  sprintf(str, "%s",Mir_CodeTropo[m]);
1032  else
1033  sprintf(str, "%s",Mir_Code[m]);
1034 
1035  }
1036  else
1037  {
1038  if (DAS.Paramini.EqType == TROPOGAS || DAS.Paramini.EqType == SPATRAM3 || DAS.Paramini.EqType == GASCODNG4)
1039  sprintf(str, "%s",Mir_CodeTropo[MIS.Pos]);
1040  else
1041  sprintf(str, "%s",Mir_Code[MIS.Pos]);
1042 
1043  //sprintf(buf, "%s", str);
1044  //MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[0], buf);
1045  //MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[0][0], "SYS\\ledGreen.bmp");
1046 
1047  }
1048  sprintf(buf, "%s", str);
1049  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[0], buf);
1050  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[0][0], "SYS\\ledGreen.bmp");
1051 
1052 
1053  }
1054 
1055  }
1056  if(DD_VOpen[1])
1057  {
1058  if(DAS.DOption.amsprogbar)
1059  D_VRangeSim(1, NULL,(unsigned long) tt * 100 / DAS.StepM.postime[AMS1][1], 255, 255, 0, 50, 100);
1060  sprintf(buf, "%.1lf sec. left", (double)fabs(((double)(tt - DAS.StepM.postime[AMS1][1]))/1000.0 ));
1061  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[1], buf);
1062  if (tt >= DAS.StepM.postime[AMS1][1])
1063  {
1064  sprintf(buf, "%4d", wl[w]);
1065  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[1], buf);
1066  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[0][1], "SYS\\ledGreen.bmp");
1067  }
1068  }
1069  else
1070  {
1071  sprintf(buf, "%.1lf sec. left", (double)fabs(((double)(tt - DAS.StepM.postime[AMS1][1]))/1000.0 ));
1072  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[1], buf);
1073  if (tt >= DAS.StepM.postime[AMS1][1])
1074  {
1075  if(w != -1)
1076  sprintf(buf, "%4d", wl[w]);
1077  else
1078  sprintf(buf, "%4d", wl[GRS.Wl]);
1079  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[1], buf);
1080  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[0][1], "SYS\\ledGreen.bmp");
1081  }
1082  }
1083  if(DD_VOpen[2])
1084  {
1085  if(DAS.DOption.amsprogbar)
1086  D_VRangeSim(2, NULL,(unsigned long) tt * 100 / DAS.StepM.postime[AMS2][0], 0, 0, 255, 50, 200);
1087  sprintf(buf, "%.1lf sec. left", (double)fabs(((double) (tt - DAS.StepM.postime[AMS2][0]) )/1000.0 ));
1088  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[2], buf);
1089  if (tt >= DAS.StepM.postime[AMS2][0])
1090  {
1091  if ( DAS.Paramini.EqType == LIS_)
1092  sprintf(buf, "%s", Fil_Code8H[f]);
1093  else
1094  {
1095  if(DAS.Paramini.EqType == TROPOGAS)
1096  sprintf(buf, "%s",Fil_CodeTropo[f]);
1097  else if (DAS.Paramini.EqType == GASCODNG2 || DAS.Paramini.EqType == GASCODNG3 || DAS.Paramini.EqType == GASCODNG4)
1098  sprintf(buf, "%s",Fil_CodeNG[f]);
1099  else if (DAS.Paramini.EqType == GASCODNG1)
1100  sprintf(buf, "%s",Fil_CodeNG1[f]);
1101 
1102  else
1103  sprintf(buf, "%s",Fil_Code[f]);
1104  }
1105  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[2], buf);
1106  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[1][0], "SYS\\ledGreen.bmp");
1107  }
1108  }
1109  else
1110  {
1111  sprintf(buf, "%.1lf sec. left", (double)fabs(((double) (tt - DAS.StepM.postime[AMS2][0]) )/1000.0 ));
1112  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[2], buf);
1113  if (tt >= DAS.StepM.postime[AMS2][0])
1114  {
1115  if(f != -1)
1116  {
1117  if ( DAS.Paramini.EqType == LIS_)
1118  sprintf(buf, "%s", Fil_Code8H[f]);
1119  else
1120  {
1121  if(DAS.Paramini.EqType == TROPOGAS)
1122  sprintf(buf, "%s",Fil_CodeTropo[f]);
1123  else if ( DAS.Paramini.EqType == GASCODNG2 || DAS.Paramini.EqType == GASCODNG3 || DAS.Paramini.EqType == GASCODNG4)
1124  sprintf(buf, "%s",Fil_CodeNG[f]);
1125  else if (DAS.Paramini.EqType == GASCODNG1)
1126  sprintf(buf, "%s",Fil_CodeNG1[f]);
1127 
1128  else
1129  sprintf(buf, "%s",Fil_Code[f]);
1130  }
1131  }
1132  else
1133  {
1134  if ( DAS.Paramini.EqType == LIS_)
1135  sprintf(buf, "%s", Fil_Code8H[FWS.Pos]);
1136  else
1137  {
1138  if(DAS.Paramini.EqType == TROPOGAS)
1139  sprintf(buf, "%s",Fil_CodeTropo[FWS.Pos]);
1140  else if (DAS.Paramini.EqType == GASCODNG1 || DAS.Paramini.EqType == GASCODNG2 || DAS.Paramini.EqType == GASCODNG3 || DAS.Paramini.EqType == GASCODNG4)
1141  sprintf(buf, "%s",Fil_CodeNG[FWS.Pos]);
1142  else
1143  sprintf(buf, "%s",Fil_Code[FWS.Pos]);
1144  }
1145  }
1146 
1147  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[2], buf);
1148  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[1][0], "SYS\\ledGreen.bmp");
1149  }
1150  }
1151 
1152 
1153 
1154  }
1155  }while((tt < maxpostime));
1156 /**************************************************************************/
1157 /**************************************************************************/
1158 
1159  // Check if all the progression bars have been destroyed.
1160  // If not the active one is destroyed and the apprpriate label is written
1161  for(k=0;k<2;k++)
1162  {
1163  for (i=0;i<2;i++)
1164  {
1165  s = 2*k+i;
1166  if(DD_VOpen[s])
1167  {
1168  if(DAS.DOption.amsprogbar)
1169  D_VRangeSim(s, NULL, 100, 0, 0, 0, 0, 0);
1170  switch (s)
1171  {
1172  case 0:
1173  if (m != -1)
1174  {
1175  if (DAS.Paramini.EqType == TROPOGAS || DAS.Paramini.EqType == SPATRAM3 || DAS.Paramini.EqType == GASCODNG4)
1176  sprintf(str, "%s",Mir_CodeTropo[m]);
1177  else
1178  sprintf(str, "%s",Mir_Code[m]);
1179  sprintf(buf, "%s", str);
1180  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[0], buf);
1181  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledGreen.bmp");
1182  }
1183  break;
1184  case 1:
1185  sprintf(buf, "%4d", wl[w]);
1186  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[1], buf);
1187  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledGreen.bmp");
1188  break;
1189  case 2:
1190  if ( DAS.Paramini.EqType == LIS_)
1191  sprintf(buf, "%s", Fil_Code8H[f]);
1192  else
1193  {
1194  if(DAS.Paramini.EqType == TROPOGAS)
1195  sprintf(buf, "%s",Fil_CodeTropo[f]);
1196  else if (DAS.Paramini.EqType == GASCODNG2 || DAS.Paramini.EqType == GASCODNG3 || DAS.Paramini.EqType == GASCODNG4)
1197  sprintf(buf, "%s",Fil_CodeNG[f]);
1198  else if (DAS.Paramini.EqType == GASCODNG1)
1199  sprintf(buf, "%s",Fil_CodeNG1[f]);
1200  else
1201  sprintf(buf, "%s",Fil_Code[f]);
1202  }
1203  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[2], buf);
1204  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledGreen.bmp");
1205  break;
1206  case 3:
1207 
1208  break;
1209 
1210  }
1211  }
1212  }
1213 
1214  }
1215 /**************************************************************************/
1216  //Recupero del gioco per grating
1217 
1218  if(DAS.StepM.nstep[AMS1][DAS.StepM.SM_B] && (DAS.StepM.Revo[AMS1][DAS.StepM.SM_B] == 0) )
1219  {
1220  er=DB_StepMotor(AMS1, 1, GRS.dp, 1);
1221  if (er)
1222  {
1223  sprintf(buf, "%4d", wl[w]);
1224  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[1], buf);
1225  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[AMS1][1], "SYS\\ledGreen.bmp");
1226  }
1227  }
1228 
1229 /**************************************************************************/
1230  return 0;
1231 
1232 
1233 
1234 }
1235 
1236 
1237 // perform the simoultaneous positioning of the Spectrometer Devices
1238 // m = mirror
1239 // w = wavelength (Grating)
1240 // f = filter wheel
1241 // z = zenith
1242 // a = azimuth
1243 int SD_Position(int m, int w, int f, double z, double a)
1244 {
1245 
1246  int k, i, s, er, dir;
1247  float GRASTEP, STEPGRA;
1248  long minpostime = 2147483647, maxpostime = 0;
1249  long st, et, tt, n;
1250  double ttout = 0, yy;
1251  char buf[80], str[16];
1252  long dp = 500; // dp sono i dead pulse, vanno aggiunti all'inversione per il recupero del gioco
1253  float razang, rzenang;
1254  int StepWithOffset [4][4];
1255  float g;
1256 
1257 
1258  for(k=0;k<DAS.StepM.NAMS;k++)
1259  { for (i=0;i<2;i++)
1260  {
1261  s = 2 * k + i;
1262  DD_VOpen[s] = 0;
1263  }
1264  }
1265  /*******************************/
1266 
1267  if((m >= 0) && (m <= 3))
1268  {
1269  k = SM_stepr(DAS.StepM.step[AMS1][DAS.StepM.SM_A]) * 6 / 4;
1270 
1271 
1272 /* er = (long)(MIS.Pos - m);
1273  switch (er)
1274  {
1275  case 0:
1276  n = 0;
1277  break;
1278  case 1:
1279  n = er * k * 3;
1280  break;
1281  case -3:
1282  case -1:
1283  case 2:
1284  case (-2):
1285  n = er * k;
1286  break;
1287  case 3:
1288  n = er * k / 3;
1289  break;
1290 
1291  }
1292 */
1293  StepWithOffset [0][0] = 0;
1294  StepWithOffset [0][1] = 3*k - DAS.Paramini.Offset[2];
1295  StepWithOffset [0][2] = 2*k - DAS.Paramini.Offset[3];
1296  StepWithOffset [0][3] = k - DAS.Paramini.Offset[4];
1297 
1298  StepWithOffset [1][0] = k + DAS.Paramini.Offset[2];
1299  StepWithOffset [1][1] = 0;
1300  StepWithOffset [1][2] = 3*k - DAS.Paramini.Offset[3] + DAS.Paramini.Offset[2];
1301  StepWithOffset [1][3] = 2*k - DAS.Paramini.Offset[4]+ DAS.Paramini.Offset[2];
1302 
1303  StepWithOffset [2][0] = 2*k + DAS.Paramini.Offset[3];
1304  StepWithOffset [2][1] = k - DAS.Paramini.Offset[2]+DAS.Paramini.Offset[3];
1305  StepWithOffset [2][2] = 0;
1306  StepWithOffset [2][3] = 3*k - DAS.Paramini.Offset[4]+DAS.Paramini.Offset[3];
1307 
1308  StepWithOffset [3][0] = 3*k + DAS.Paramini.Offset[4];
1309  StepWithOffset [3][1] = 2*k - DAS.Paramini.Offset[2]+ DAS.Paramini.Offset[4];
1310  StepWithOffset [3][2] = k - DAS.Paramini.Offset[3] + DAS.Paramini.Offset[4];
1311  StepWithOffset [3][3] = 0;
1312 
1313 
1314  dir = 1;
1315  n = StepWithOffset [m][MIS.Pos];
1316  n = labs(n);
1317  DAS.StepM.Revo[AMS1][DAS.StepM.SM_A] = dir;
1318  DAS.StepM.nstep[AMS1][DAS.StepM.SM_A] = n;
1319  MIS.Pos = m;
1320  }
1321  else
1322  {
1323  DAS.StepM.Revo[AMS1][DAS.StepM.SM_A] = 0;
1324  DAS.StepM.nstep[AMS1][DAS.StepM.SM_A] = 0;
1325 
1326  }
1327 
1328  /******************************/
1329 
1330  /*******************************/
1331  //w
1332  if(w >= 0 && w <= 17)
1333  {
1334  g = (float) SM_stepr(DAS.StepM.step[AMS1][1])/3200;
1335  n = (long)(((float) (-wav[GRS.Wl] + wav[w]) ) * 4 * g);
1336 
1337  if(n < 0)
1338  dir = 1;
1339  else
1340  dir = 0;
1341 
1342  n = labs(n);
1343 
1344 
1345  if(n && dir == 0) //si va verso l'UV
1346  n += GRS.dp; // // add fixed step number for backlash recovery
1347 
1348  DAS.StepM.Revo[AMS1][DAS.StepM.SM_B] = dir;
1349  DAS.StepM.nstep[AMS1][DAS.StepM.SM_B] = n;
1350  GRS.Wl = w;
1351  }
1352  else
1353  {
1354  DAS.StepM.Revo[AMS1][DAS.StepM.SM_B] = 0;
1355  DAS.StepM.nstep[AMS1][DAS.StepM.SM_B] = 0;
1356 
1357  }
1358  /*******************************/
1359 
1360  /*******************************/
1361  //f
1362 
1363  //8 holes....
1364  if(DAS.Paramini.EqType == LIS_)
1365  {
1366  k = SM_stepr(DAS.StepM.step[AMS2][DAS.StepM.SM_A]) / 8;
1367  if(f >= 0 && f <= 8)
1368  {
1369  n= (long)(FWS.Pos - f) * k;
1370  if(n < 0)
1371  dir = 1;
1372  else
1373  dir = 0;
1374 
1375  n = labs(n);
1376  DAS.StepM.Revo[AMS2][DAS.StepM.SM_A] = dir;
1377  DAS.StepM.nstep[AMS2][DAS.StepM.SM_A] = n;
1378  FWS.Pos = f;
1379  }
1380  else
1381  {
1382  n = 0;
1383  DAS.StepM.Revo[AMS2][DAS.StepM.SM_A] = 0;
1384  DAS.StepM.nstep[AMS2][DAS.StepM.SM_A] = 0;
1385  }
1386 
1387 
1388  }
1389  // ...or 6 holes....
1390  if (DAS.Paramini.EqType == SPATRAM ||
1391  DAS.Paramini.EqType == GASCODNG1 ||
1392  DAS.Paramini.EqType == SPATRAMPLUS ||
1393  DAS.Paramini.EqType == TROPOGAS ||
1394  DAS.Paramini.EqType == GASCODNG2 ||
1395  DAS.Paramini.EqType == GASCODNG3 ||
1396  DAS.Paramini.EqType == GASCODNG4 ||
1397  DAS.Paramini.EqType == SPATRAM3 ||
1398  DAS.Paramini.EqType == SPATRAM2)
1399  {
1400  k = SM_stepr(DAS.StepM.step[AMS2][DAS.StepM.SM_A]) / 6;
1401  if(f >= 0 && f <= 5)
1402  {
1403  n= (long)(FWS.Pos - f) * k;
1404  if(n < 0)
1405  dir = 1;
1406  else
1407  dir = 0;
1408 
1409  n = labs(n);
1410  DAS.StepM.Revo[AMS2][DAS.StepM.SM_A] = dir;
1411  DAS.StepM.nstep[AMS2][DAS.StepM.SM_A] = n;
1412  FWS.Pos = f;
1413  }
1414  else
1415  {
1416  n = 0;
1417  DAS.StepM.Revo[AMS2][DAS.StepM.SM_A] = 0;
1418  DAS.StepM.nstep[AMS2][DAS.StepM.SM_A] = 0;
1419  }
1420  }
1421 
1422  /*******************************/
1423  //a --> Azimuth
1424 
1425  //Azimuth positioning
1426  razang=MIGEAz((float)a);
1427 
1428  k = SM_stepr(DAS.StepM.step[AMS3][DAS.StepM.SM_B]); // step/round
1429 
1430  GRASTEP = (float)360.0 / (float) k; // degree/step
1431 
1432  STEPGRA = (float) k / (float)360.0; // step/degree
1433 
1434  yy = (razang - AST.Pos);
1435 
1436  n = (long) (yy * STEPGRA * DAS.StepM.multiplier[AMS3][1]);
1437 
1438  AST.Pos = razang;
1439  AST.realazpos = a;
1440 
1441  // Select direction
1442  if(n < 0)
1443  dir = 1;
1444  else
1445  dir = 0;
1446 
1447  n = labs(n);
1448  DAS.StepM.Revo[AMS3][DAS.StepM.SM_B] = dir;
1449  DAS.StepM.nstep[AMS3][DAS.StepM.SM_B] = n;
1450 
1451 /**************************************************************************/
1452  /*******************************/
1453  //z --> Zenith
1454  //if(z >= -91 && z <= 45 )
1455 // if(z >= -90 && z <= 90 )
1456  //Zenith positioning
1457  rzenang=MIGEZen((float)z);
1458 
1459  if(z >= 0 && z <= 180 )
1460  {
1461 
1462 
1463 
1464 
1465 
1466  k = SM_stepr(DAS.StepM.step[AMS3][DAS.StepM.SM_A]); // step/round
1467 
1468  GRASTEP = (float) 360.0 / (float) k; // degree/step
1469 
1470  STEPGRA = (float) k / (float) 360.0; // step/degree
1471 
1472 // yy = -(z - ZST.Pos);
1473  yy = -(rzenang - ZST.Pos);
1474  n = (long)(yy * STEPGRA * (DAS.StepM.multiplier[AMS3][0]));
1475 // ZST.Pos = z;
1476  ZST.Pos = rzenang;
1477  ZST.realzenpos = z;
1478  // Select direction
1479  if(n < 0)
1480  dir = 1;
1481  else
1482  dir = 0;
1483 
1484  n = labs(n);
1485  DAS.StepM.Revo[AMS3][DAS.StepM.SM_A] = dir;
1486  DAS.StepM.nstep[AMS3][DAS.StepM.SM_A] = n;
1487  }
1488  else
1489  {
1490  DAS.StepM.Revo[AMS3][DAS.StepM.SM_A] = 0;
1491  DAS.StepM.nstep[AMS3][DAS.StepM.SM_A] = 0;
1492  sprintf(buf, "Not Allowed Zen.");
1493  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[4], buf);
1494 
1495  }
1496  /*******************************/
1497 
1498 
1499 
1500 
1501 
1502  // Tout computation and Max finding
1503  for(k=0;k<DAS.StepM.NAMS;k++)
1504  {
1505  for (i=0;i<2;i++)
1506  {
1507  DAS.StepM.postime[k][i] = (long)( DAS.StepM.nstep[k][i]/(float) DAS.StepM.speed_Hz[k][i]);
1508  if (DAS.StepM.postime[k][i] >= maxpostime) maxpostime = DAS.StepM.postime[k][i];
1509  if (DAS.StepM.postime[k][i] <= minpostime) minpostime = DAS.StepM.postime[k][i];
1510  }
1511  }
1512 /*************************************************************************/
1513 
1514 /**************************************************************************/
1515  // Init Progression bar
1516  for(k=0;k<DAS.StepM.NAMS;k++)
1517  {
1518  for (i=0;i<2;i++)
1519  {
1520  if (DAS.StepM.nstep[k][i] != 0)
1521  {
1522  s = 2*k+i;
1523  switch (s)
1524  {
1525  case 0:
1526  if(DAS.DOption.amsprogbar)
1527  D_VRangeSim(0, "Positioning Mirror",0, 255, 0, 0, 50, 0);
1528  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledoff.bmp");
1529 
1530  break;
1531  case 1:
1532  if(DAS.DOption.amsprogbar)
1533  D_VRangeSim(1, "Positioning Grating",0, 255, 255, 0, 50, 100);
1534  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledoff.bmp");
1535  break;
1536  case 2:
1537  if(DAS.DOption.amsprogbar)
1538  D_VRangeSim(2, "Positioning Filter Wheel",0, 0, 0, 255, 50, 200);
1539  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledoff.bmp");
1540  break;
1541  case 3:
1542  break;
1543  case 4:
1544  if(DAS.DOption.amsprogbar)
1545  if(DAS.DOption.aaopmode == 2)
1546  {
1547  D_VRangeSim(4,"Positioning Zenith",0, 0, 255, 255, 50, 300);
1548 
1549  }
1550  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledoff.bmp");
1551  break;
1552  case 5:
1553  if(DAS.DOption.amsprogbar)
1554  if(DAS.DOption.aaopmode == 2)
1555  {
1556  D_VRangeSim(5,"Positioning Azimuth",0, 0, 192, 255, 50, 400);
1557 
1558  }
1559  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledoff.bmp");
1560  break;
1561 
1562 
1563  }
1564  }
1565  }
1566  }
1567 /*************************************************************************/
1568 
1569 /**************************************************************************/
1570  // Send step
1571 
1572  for(k=0;k<DAS.StepM.NAMS;k++)
1573  {
1574  if (DAS.Flag.exemode != DBDEMO)
1575  {
1576  AMS_sendstep(k, DAS.StepM.Revo[k][DAS.StepM.SM_A], DAS.StepM.Revo[k][DAS.StepM.SM_B],
1577  DAS.StepM.nstep[k][DAS.StepM.SM_A], DAS.StepM.nstep[k][DAS.StepM.SM_B]);
1578  }
1579  WriteLogAMS(k, DAS.StepM.Revo[k][DAS.StepM.SM_A], DAS.StepM.Revo[k][DAS.StepM.SM_B],
1580  DAS.StepM.nstep[k][DAS.StepM.SM_A], DAS.StepM.nstep[k][DAS.StepM.SM_B]);
1581 
1582  }
1583 
1584 
1585  //Time Out loop
1586  st = GetTickCount();
1587  do
1588  {
1589  et = GetTickCount();
1590  tt = labs(et - st);
1591  MLoopWhileEvents(0);
1592  if(tt > 0)
1593  {
1594 
1595  if(DD_VOpen[0])
1596  {
1597  if(DAS.DOption.amsprogbar)
1598  D_VRangeSim(0 ,NULL,(unsigned long) tt * 100 / DAS.StepM.postime[AMS1][0], 255, 0, 0, 50, 0);
1599  sprintf(buf, "%.1f sec. left", (double)fabs(((double)(tt - DAS.StepM.postime[AMS1][0]))/1000.0 ));
1600  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[0], buf);
1601  if (tt >= DAS.StepM.postime[AMS1][0])
1602  {
1603  if (DAS.Paramini.EqType == TROPOGAS || DAS.Paramini.EqType == SPATRAM3 || DAS.Paramini.EqType == GASCODNG4)
1604  sprintf(str, "%s",Mir_CodeTropo[m]);
1605  else
1606  sprintf(str, "%s",Mir_Code[m]);
1607 
1608  sprintf(buf, "%s", str);
1609  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[0], buf);
1610  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[0][0], "SYS\\ledGreen.bmp");
1611 
1612  }
1613  }
1614  else
1615  {
1616  sprintf(buf, "%.1f sec. left", (double)fabs(((double)(tt - DAS.StepM.postime[AMS1][0]))/1000.0 ));
1617  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[0], buf);
1618  if (tt >= DAS.StepM.postime[AMS1][0])
1619  {
1620  if (m != -1)
1621  {
1622  if (DAS.Paramini.EqType == TROPOGAS || DAS.Paramini.EqType == SPATRAM3 || DAS.Paramini.EqType == GASCODNG4)
1623  sprintf(str, "%s",Mir_CodeTropo[m]);
1624  else
1625  sprintf(str, "%s",Mir_Code[m]);
1626 
1627  }
1628  else
1629  {
1630  if (DAS.Paramini.EqType == TROPOGAS || DAS.Paramini.EqType == SPATRAM3 || DAS.Paramini.EqType == GASCODNG4)
1631  sprintf(str, "%s",Mir_CodeTropo[MIS.Pos]);
1632  else
1633  sprintf(str, "%s",Mir_Code[MIS.Pos]);
1634 
1635  //sprintf(buf, "%s", str);
1636  //MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[0], buf);
1637  //MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[0][0], "SYS\\ledGreen.bmp");
1638 
1639  }
1640  sprintf(buf, "%s", str);
1641  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[0], buf);
1642  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[0][0], "SYS\\ledGreen.bmp");
1643 
1644 
1645  }
1646 
1647  }
1648  if(DD_VOpen[1])
1649  {
1650  if(DAS.DOption.amsprogbar)
1651  D_VRangeSim(1, NULL,(unsigned long) tt * 100 / DAS.StepM.postime[AMS1][1], 255, 255, 0, 50, 100);
1652  sprintf(buf, "%.1lf sec. left", (double)fabs(((double)(tt - DAS.StepM.postime[AMS1][1]))/1000.0 ));
1653  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[1], buf);
1654  if (tt >= DAS.StepM.postime[AMS1][1])
1655  {
1656  sprintf(buf, "%4d", wl[w]);
1657  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[1], buf);
1658  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[0][1], "SYS\\ledGreen.bmp");
1659  }
1660  }
1661  else
1662  {
1663  sprintf(buf, "%.1lf sec. left", (double)fabs(((double)(tt - DAS.StepM.postime[AMS1][1]))/1000.0 ));
1664  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[1], buf);
1665  if (tt >= DAS.StepM.postime[AMS1][1])
1666  {
1667  if(w != -1)
1668  sprintf(buf, "%4d", wl[w]);
1669  else
1670  sprintf(buf, "%4d", wl[GRS.Wl]);
1671  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[1], buf);
1672  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[0][1], "SYS\\ledGreen.bmp");
1673  }
1674  }
1675  if(DD_VOpen[2])
1676  {
1677  if(DAS.DOption.amsprogbar)
1678  D_VRangeSim(2, NULL,(unsigned long) tt * 100 / DAS.StepM.postime[AMS2][0], 0, 0, 255, 50, 200);
1679  sprintf(buf, "%.1lf sec. left", (double)fabs(((double) (tt - DAS.StepM.postime[AMS2][0]) )/1000.0 ));
1680  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[2], buf);
1681  if (tt >= DAS.StepM.postime[AMS2][0])
1682  {
1683  if ( DAS.Paramini.EqType == LIS_)
1684  sprintf(buf, "%s", Fil_Code8H[f]);
1685  else
1686  {
1687  if(DAS.Paramini.EqType == TROPOGAS)
1688  sprintf(buf, "%s",Fil_CodeTropo[f]);
1689  else if (DAS.Paramini.EqType == GASCODNG2 || DAS.Paramini.EqType == GASCODNG3 || DAS.Paramini.EqType == GASCODNG4)
1690  sprintf(buf, "%s",Fil_CodeNG[f]);
1691  else if (DAS.Paramini.EqType == GASCODNG1)
1692  sprintf(buf, "%s",Fil_CodeNG1[f]);
1693  else
1694  sprintf(buf, "%s",Fil_Code[f]);
1695  }
1696  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[2], buf);
1697  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[1][0], "SYS\\ledGreen.bmp");
1698  }
1699  }
1700  else
1701  {
1702  sprintf(buf, "%.1lf sec. left", (double)fabs(((double) (tt - DAS.StepM.postime[AMS2][0]) )/1000.0 ));
1703  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[2], buf);
1704  if (tt >= DAS.StepM.postime[AMS2][0])
1705  {
1706  if(f != -1)
1707  {
1708  if ( DAS.Paramini.EqType == LIS_)
1709  sprintf(buf, "%s", Fil_Code8H[f]);
1710  else
1711  {
1712  if(DAS.Paramini.EqType == TROPOGAS)
1713  sprintf(buf, "%s",Fil_CodeTropo[f]);
1714  else if (DAS.Paramini.EqType == GASCODNG2 || DAS.Paramini.EqType == GASCODNG3 || DAS.Paramini.EqType == GASCODNG4)
1715  sprintf(buf, "%s",Fil_CodeNG[f]);
1716  else if (DAS.Paramini.EqType == GASCODNG1)
1717  sprintf(buf, "%s",Fil_CodeNG1[f]);
1718  else
1719  sprintf(buf, "%s",Fil_Code[f]);
1720  }
1721  }
1722  else
1723  {
1724  if ( DAS.Paramini.EqType == LIS_)
1725  sprintf(buf, "%s", Fil_Code8H[FWS.Pos]);
1726  else
1727  {
1728  if(DAS.Paramini.EqType == TROPOGAS)
1729  sprintf(buf, "%s",Fil_CodeTropo[FWS.Pos]);
1730  else if (DAS.Paramini.EqType == GASCODNG1 || DAS.Paramini.EqType == GASCODNG2 || DAS.Paramini.EqType == GASCODNG3 || DAS.Paramini.EqType == GASCODNG4)
1731  sprintf(buf, "%s",Fil_CodeNG[FWS.Pos]);
1732  else
1733  sprintf(buf, "%s",Fil_Code[FWS.Pos]);
1734  }
1735  }
1736 
1737  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[2], buf);
1738  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[1][0], "SYS\\ledGreen.bmp");
1739  }
1740  }
1741 
1742  if(DD_VOpen[4])
1743  {
1744  if(DAS.DOption.amsprogbar)
1745  D_VRangeSim(4, NULL,(unsigned long) tt * 100 / DAS.StepM.postime[AMS3][0], 0, 255, 255, 50, 300);
1746  if (tt >= DAS.StepM.postime[AMS3][0])
1747  {
1748  sprintf(buf, "%.1lf", z);
1749  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[4], buf);
1750  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[2][0], "SYS\\ledGreen.bmp");
1751  }
1752  else
1753  {
1754  sprintf(buf, "%.1lf sec. left", (double)fabs(((double)(tt - DAS.StepM.postime[AMS3][0]))/1000.0 ));
1755  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[4], buf);
1756  }
1757  }
1758  else
1759  {
1760  if (tt >= DAS.StepM.postime[AMS3][0])
1761  {
1762  sprintf(buf, "%.1lf", z);
1763  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[4], buf);
1764  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[2][0], "SYS\\ledGreen.bmp");
1765  }
1766  else
1767  {
1768  sprintf(buf, "%.1lf sec. left", (double)fabs(((double)(tt - DAS.StepM.postime[AMS3][0]))/1000.0 ));
1769  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[4], buf);
1770  }
1771 
1772  }
1773 
1774  if(DD_VOpen[5])
1775  {
1776  if(DAS.DOption.amsprogbar)
1777  D_VRangeSim(5, NULL,(unsigned long) tt * 100 / DAS.StepM.postime[AMS3][1], 0, 192, 255, 50, 400);
1778  if (labs(et - st) >= DAS.StepM.postime[AMS3][1])
1779  {
1780  sprintf(buf, "%.1lf", a);
1781  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[5], buf);
1782  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[2][1], "SYS\\ledGreen.bmp");
1783  }
1784  else
1785  {
1786  sprintf(buf, "%.1lf sec. left", (double)fabs(((double)(tt - DAS.StepM.postime[AMS3][1]))/1000.0 ));
1787  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[5], buf);
1788  }
1789  }
1790  else
1791  {
1792  if (labs(et - st) >= DAS.StepM.postime[AMS3][1])
1793  {
1794  sprintf(buf, "%.1lf", a);
1795  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[5], buf);
1796  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[2][1], "SYS\\ledGreen.bmp");
1797  }
1798  else
1799  {
1800  sprintf(buf, "%.1lf sec. left", (double)fabs(((double)(tt - DAS.StepM.postime[AMS3][1]))/1000.0 ));
1801  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[5], buf);
1802  }
1803 
1804  }
1805 
1806 
1807  }
1808  }while((tt < maxpostime));
1809 /**************************************************************************/
1810 /**************************************************************************/
1811 
1812  // Check if all the progression bars have been destroyed.
1813  // If not the active one is destroyed and the apprpriate label is written
1814  for(k=0;k<DAS.StepM.NAMS;k++)
1815  {
1816  for (i=0;i<2;i++)
1817  {
1818  s = 2*k+i;
1819  if(DD_VOpen[s])
1820  {
1821  if(DAS.DOption.amsprogbar)
1822  D_VRangeSim(s, NULL, 100, 0, 0, 0, 0, 0);
1823  switch (s)
1824  {
1825  case 0:
1826  if (m != -1)
1827  {
1828  if (DAS.Paramini.EqType == TROPOGAS || DAS.Paramini.EqType == SPATRAM3 || DAS.Paramini.EqType == GASCODNG4)
1829  sprintf(str, "%s",Mir_CodeTropo[m]);
1830  else
1831  sprintf(str, "%s",Mir_Code[m]);
1832  sprintf(buf, "%s", str);
1833  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[0], buf);
1834  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledGreen.bmp");
1835  }
1836  break;
1837  case 1:
1838  sprintf(buf, "%4d", wl[w]);
1839  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[1], buf);
1840  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledGreen.bmp");
1841  break;
1842  case 2:
1843  if ( DAS.Paramini.EqType == LIS_)
1844  sprintf(buf, "%s", Fil_Code8H[f]);
1845  else
1846  {
1847  if(DAS.Paramini.EqType == TROPOGAS)
1848  sprintf(buf, "%s",Fil_CodeTropo[f]);
1849  else if (DAS.Paramini.EqType == GASCODNG2 || DAS.Paramini.EqType == GASCODNG3 || DAS.Paramini.EqType == GASCODNG4)
1850  sprintf(buf, "%s",Fil_CodeNG[f]);
1851  else if (DAS.Paramini.EqType == GASCODNG1)
1852  sprintf(buf, "%s",Fil_CodeNG1[f]);
1853  else
1854  sprintf(buf, "%s",Fil_Code[f]);
1855  }
1856  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[2], buf);
1857  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledGreen.bmp");
1858  break;
1859  case 3:
1860 
1861  break;
1862  case 4:
1863  sprintf(buf, "%.1lf", z);
1864  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[4], buf);
1865  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledGreen.bmp");
1866  break;
1867  case 5:
1868  sprintf(buf, "%.1lf", (double) a);
1869  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[5], buf);
1870  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[k][i], "SYS\\ledGreen.bmp");
1871  break;
1872 
1873 
1874  }
1875  }
1876  }
1877 
1878  }
1879 /**************************************************************************/
1880  //Recupero del gioco per grating
1881 
1882  if(DAS.StepM.nstep[AMS1][DAS.StepM.SM_B] && (DAS.StepM.Revo[AMS1][DAS.StepM.SM_B] == 0) )
1883  {
1884  er=DB_StepMotor(AMS1, 1, GRS.dp, 1);
1885  if (er)
1886  {
1887  sprintf(buf, "%4d", wl[w]);
1888  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[1], buf);
1889  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[AMS1][1], "SYS\\ledGreen.bmp");
1890  }
1891  }
1892 
1893 /**************************************************************************/
1894  return 0;
1895 
1896 
1897 }
1898 int SD_Mirror(int where)
1899 {
1900 
1901  char buf[80];
1902  long n[3];
1903  long nx;
1904  int d, dir[3]; // 0 = CW, 1 = CCW
1905  int k = 1500, er = 0;
1906 
1907  int StepWithOffset [4][4];
1908 
1909  //mtr1(or 2) = 0 --> motor off
1910  //mtr1(or 2) = 1 --> motor on
1911  /* 22 */
1912 // AMS_MotorOn_Off(AMS1, 1, 0);
1913 
1914 // k = SM_stepr(DAS.StepM.step[AMS1][0]) * 6 / 4;
1915 
1916  k = SM_stepr(DAS.StepM.step[AMS1][0]) * DAS.StepM.multiplier[AMS1][0] / 4; //4 is the number of positions
1917 
1918  StepWithOffset [0][0] = 0;
1919  StepWithOffset [0][1] = 3*k - DAS.Paramini.Offset[2];
1920  StepWithOffset [0][2] = 2*k - DAS.Paramini.Offset[3];
1921  StepWithOffset [0][3] = k - DAS.Paramini.Offset[4];
1922 
1923  StepWithOffset [1][0] = k + DAS.Paramini.Offset[2];
1924  StepWithOffset [1][1] = 0;
1925  StepWithOffset [1][2] = 3*k - DAS.Paramini.Offset[3] + DAS.Paramini.Offset[2];
1926  StepWithOffset [1][3] = 2*k - DAS.Paramini.Offset[4]+ DAS.Paramini.Offset[2];
1927 
1928  StepWithOffset [2][0] = 2*k + DAS.Paramini.Offset[3];
1929  StepWithOffset [2][1] = k - DAS.Paramini.Offset[2]+DAS.Paramini.Offset[3];
1930  StepWithOffset [2][2] = 0;
1931  StepWithOffset [2][3] = 3*k - DAS.Paramini.Offset[4]+DAS.Paramini.Offset[3];
1932 
1933  StepWithOffset [3][0] = 3*k + DAS.Paramini.Offset[4];
1934  StepWithOffset [3][1] = 2*k - DAS.Paramini.Offset[2]+ DAS.Paramini.Offset[4];
1935  StepWithOffset [3][2] = k - DAS.Paramini.Offset[3] + DAS.Paramini.Offset[4];
1936  StepWithOffset [3][3] = 0;
1937 
1938 
1939 
1940 
1941 
1942  if(where < 0 || where > 3) return 0;
1943 
1944  //Disattiva i pulsanti sulla keyboard
1945  DB_KB_ButtonActive(0);
1948 
1949  nx = StepWithOffset [where][MIS.Pos];
1950  d = 1;
1951 
1952 
1953 // Procedure by danbo (20/10/2005)
1954 /*
1955  er = (long)(MIS.Pos - where);
1956 
1957  switch (er)
1958  {
1959  case 0:
1960  n[2] = 0;
1961  break;
1962  case 1:
1963  n[2] = er * k * 3;
1964 
1965  break;
1966  case -3:
1967  case -1:
1968  case 2:
1969  case (-2):
1970  n[2] = er * k;
1971  break;
1972  case 3:
1973  n[2] = er * k / 3;
1974 
1975  break;
1976 
1977  }
1978 
1979 
1980  dir[2] = 1;
1981  n[2] = labs(n[2]);
1982 */
1983  /*
1984  if (er < 0)
1985  n[2] += DAS.Paramini.Offset[where + 1];
1986  if (er > 0)
1987  n[2] -= DAS.Paramini.Offset[MIS.Pos + 1];
1988 */
1989 /*
1990  if(DAS.Paramini.Offset[MIS.Pos + 1] != 0 || DAS.Paramini.Offset[where + 1] != 0)
1991  {
1992 
1993  n[2] += (DAS.Paramini.Offset[MIS.Pos + 1] + DAS.Paramini.Offset[where + 1]);
1994 
1995  }
1996 */
1997 /*
1998  switch (where)
1999  {
2000  case 0:
2001  switch (MIS.Pos)
2002  case 0:
2003  n[2] = 0;
2004  break;
2005  case 1;
2006 */
2007 
2008  // n[2] += DAS.Paramini.Offset[MIS.Pos + 1];
2009 
2010 
2011 // sprintf(buf," MISPos:%d, where:%d, numstep=%ld, dir=%d", MIS.Pos, where, n[2], dir[2]);
2012 // MMessageDialog("DAS Inf", buf, "ok", NULL);
2013 
2014 
2015 //Previous version
2016 /*
2017  n[0] = (long) (4 - where + MIS.Pos) * k;
2018  dir[0] = 1;
2019 
2020  n[1] = (long) (4 - MIS.Pos + where) * k;
2021  dir[1] = 0;
2022 */
2023 // n[2] = (long)(MIS.Pos - where) * k;
2024 
2025 
2026  // In order to move the mirror always in the same direction
2027 // dir[2] = 1;
2028  // the direction is chosen depending on the previous position
2029 /* if(n[2] < 0) dir[2] = 1;
2030  else dir[2] = 0;
2031 */
2032 
2033 // n[2] = labs(n[2]);
2034 
2035  // Cerca il valore minimo
2036 /* for(c = 0; c < 2; c++)
2037  if(n[c] < n[c + 1]) { d = dir[c]; nx = n[c]; }
2038  else { d = dir[c + 1]; nx = n[c + 1]; }
2039 
2040  if (nx==0) return 1;
2041 
2042 
2043  nx = n[2];
2044  d = dir[2];
2045 */
2046  // Eseguo NStep
2047 
2048  Status("New Input Mirror Position");
2049 
2050  if(nx)
2051  {
2052  er = DB_StepMotor(AMS1, 0, nx, d);
2053 
2054  if (er)
2055  {
2056  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[AMS1][0], "SYS\\ledGreen.bmp");
2057  }
2058 
2059 
2060  }
2061 
2062 
2063 
2064  MIS.Pos = where;
2065  /*--------------------------------------------------------------------*/
2066  // Send OffSet for Mirror position
2067 
2068 /* if(DAS.Paramini.Offset[MIS.Pos + 1] != 0)
2069  {
2070  if(DAS.Paramini.Offset[MIS.Pos + 1] > 0) d = 0;
2071  else d = 1;
2072 
2073  er = AMS_DoPos(AMS1, d, 0, labs(DAS.Paramini.Offset[MIS.Pos + 1]), 0);
2074  if(er) { Message("n Step not sent! 2", er); }
2075  }
2076 */
2077  /*--------------------------------------------------------------------*/
2078  if (DAS.Paramini.EqType == TROPOGAS || DAS.Paramini.EqType == SPATRAM3 || DAS.Paramini.EqType == GASCODNG4)
2079  sprintf(buf, "%s",Mir_CodeTropo[where]);
2080  else
2081  sprintf(buf, "%s",Mir_Code[where]);
2082 
2083  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[0], buf);
2084  if(FLAG.manhormeas)
2085  MObjectSetText(DAS.Gui.HorizMeas.lbl[0], buf);
2086 
2087 
2088 
2089 // Status("Ready");
2090  if(!FLAG.fileprg || !FLAG.exec )
2091  //Attiva i pulsanti sulla keyboard se non si sta eseguendo una tabella di misure
2092  //oppure se il programma e' stato sospeso (si e' premuto il tasto "pause")
2093  DB_KB_ButtonActive(1);
2094 
2095 // AMS_MotorOn_Off(AMS1, 0, 0);
2096 
2097  if(er) return 1;
2098 
2099  return 0;
2100 
2101 }
2102 //long GratPos = 0;
2103 //int GratDir = 0;
2104 //int GratWl = 0;
2105 
2106 
2107 
2108 int SD_Grating(int ang)
2109 {
2110  int er = 0;
2111  char buf[80];
2112  long n, dp = 1500; // dp sono i dead pulse, vanno aggiunti all'inversione per il recupero del gioco
2113  int dir;
2114  float k = 0;
2115  long period = 5000;
2116  int prepos;
2117  long prestep;
2118  //se ang non e' compreso nei limiti esce dalla function
2119  if(ang < 0 || ang > 18) return 0;
2120 
2121  //Status("Set NEW Grating Position");
2122 
2123  //Disable the keyboard buttons
2124  DB_KB_ButtonActive(0);
2127 
2128 
2129  /******************************************
2130  //in SD_Position
2131  k = SM_stepr(DAS.StepM.step[AMS1][1])/3200;
2132  n = (long)(((float) (-wav[GRS.Wl] + wav[w]) ) * 4 * k);
2133 
2134  if(n < 0)
2135  dir = 1;
2136  else
2137  dir = 0;
2138 
2139  n = labs(n);
2140 
2141 
2142  /***********************************************/
2143 
2144  //Multiplier factor depending on the values of microsteps
2145  k = (float)SM_stepr(DAS.StepM.step[AMS1][1])/3200;
2146 
2147  //Actual steps sent to the grating motor
2148  n = (long)(((float) (-wav[GRS.Wl] + wav[ang]) ) * DAS.StepM.multiplier[AMS1][1] * k);
2149 
2150  prepos = wl[GRS.Wl];
2151  prestep = wav[GRS.Wl];
2152  GRS.Wl = ang;
2153 
2154  sprintf(buf, " %4d --> %4d", prepos, wl[ang]);
2155  Status(buf);
2156 
2157  //Select the direction (n < 0 --> Dir = 1 = UV; n > 0 --> Dir = 0 = Vis.)
2158  if(n < 0)
2159  dir = 1;
2160  else
2161  dir = 0;
2162 
2163  n = labs(n);
2164  DAS.StepM.nstep[AMS1][1]= n;
2165 
2166  if(n && dir == 0) //towards UV
2167  n += GRS.dp; // add fixed step number for backlash recovery (recupero del gioco)
2168 
2169 
2170  GRS.Pos = n;
2171 
2172  if (n==0)
2173  {
2174  //Attiva i pulsanti sulla keyboard
2175  DB_KB_ButtonActive(1);
2176  return 1;
2177  }
2178 
2179  // Eseguo n passi
2180  if(n)
2181  {
2182  er = DB_StepMotor(AMS1, 1, n, dir);
2183  if (er)
2184  {
2185  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[AMS1][1], "SYS\\ledGreen.bmp");
2186  }
2187  }
2188 
2189  //Se ci si e' mossi verso l'UV si fa il recupero del gioco
2190 /* if(DAS.Paramini.EqType == LIS_)
2191  {
2192  if(dir == 1)
2193  {
2194  er=DB_StepMotor(AMS1, 1, GRS.dp, 1);
2195  if (er)
2196  {
2197  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM2, "SYS\\ledGreen.bmp");
2198  }
2199  }
2200 
2201  }
2202  else if (DAS.Paramini.EqType == SPATRAM || DAS.Paramini.EqType == GASCODNG || DAS.Paramini.EqType == SPATRAMPLUS || DAS.Paramini.EqType == TROPOGAS )
2203  {
2204 */
2205  if(n && dir == 0)
2206  {
2207  er=DB_StepMotor(AMS1, 1, GRS.dp, 1);
2208  if (er)
2209  {
2210  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[AMS1][1], "SYS\\ledGreen.bmp");
2211  }
2212  }
2213 // }
2214 
2215 
2216  sprintf(buf, "%4d", wl[ang]);
2217  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[1], buf);
2218 
2219  sprintf(buf, "Steps : %ld", (-prestep + wav[ang]) );
2220  Status(buf);
2221 
2222  if(FLAG.manhormeas)
2223  MObjectSetText(DAS.Gui.HorizMeas.lbl[1], buf);
2224  if(!FLAG.fileprg || !FLAG.exec )
2225  //Attiva i pulsanti sulla keyboard se non si sta eseguendo una tabella di misure
2226  //oppure se il programma e' stato sospeso (si e' premuto il tasto "pause")
2227  DB_KB_ButtonActive(1);
2228 
2229 
2230 
2231  if(er) return 1;
2232 
2233 
2234  return 0;
2235 
2236 }
2237 
2238 
2239 //int FWS.Pos = 0;
2240 //int FWS.Dir = 0;
2241 /*
2242  * filter = 0 - 7 (0 = HOME)
2243  */
2244 int SD_FilterW(int filter)
2245 {
2246 
2247  char buf[80];
2248  long n[3];
2249  long nx;
2250  int d, dir[3]; // 0 = CW, 1 = CCW
2251  int k , er;
2252 // char Filter[4];
2253 
2254  //Disattiva i pulsanti sulla keyboard
2255  DB_KB_ButtonActive(0);
2258 
2259  /************************************************************/
2260  //Sceglie quale ruota e' installata (a 8 fori....
2261  if(DAS.Paramini.EqType == LIS_)
2262  {
2263  k = SM_stepr(DAS.StepM.step[AMS2][0]) / 8;
2264 
2265  if(filter < 0 || filter > 7) return 0;
2266  }
2267  // ...oppure a 6 fori....
2268  else if (DAS.Paramini.EqType == SPATRAM ||
2269  DAS.Paramini.EqType == GASCODNG1 ||
2270  DAS.Paramini.EqType == SPATRAMPLUS ||
2271  DAS.Paramini.EqType == TROPOGAS ||
2272  DAS.Paramini.EqType == GASCODNG2 ||
2273  DAS.Paramini.EqType == GASCODNG3 ||
2274  DAS.Paramini.EqType == GASCODNG4 ||
2275  DAS.Paramini.EqType == SPATRAM3 ||
2276  DAS.Paramini.EqType == SPATRAM2)
2277  {
2278  k = SM_stepr(DAS.StepM.step[AMS2][0]) / 6;
2279  if(filter < 0 || filter > 5) return 0;
2280  }
2281  else // ...oppure non lo sa)
2282  {
2283  sprintf(buf, "For this Equipment the Filter Wheel type is UNKNOWN\nPlease Contact DANBO!!!!");
2284  er = MMessageDialog("DAS information", buf, "Ok", NULL);
2285  if (!er)
2286  {
2287  return 0;
2288  }
2289 
2290  }
2291  /**************************************************************/
2292 
2293  n[2] = (long)(FWS.Pos - filter) * k;
2294 
2295  if(n[2] < 0) dir[2] = 1;
2296  else dir[2] = 0;
2297  n[2] = labs(n[2]);
2298 
2299  nx = n[2];
2300  d = dir[2];
2301 
2302  // Eseguo NStep
2303 
2304  Status("New Filter Wheel Position");
2305 
2306 
2307  if(nx)
2308  {
2309  er=DB_StepMotor(AMS2, 2, nx, d);
2310  if (er)
2311  {
2312  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[AMS2][0], "SYS\\ledGreen.bmp");
2313  }
2314  }
2315 
2316 
2317  FWS.Pos = filter;
2318  if ( DAS.Paramini.EqType == LIS_)
2319  sprintf(buf, "%s", Fil_Code8H[filter]);
2320  else
2321  {
2322  if(DAS.Paramini.EqType == TROPOGAS)
2323  sprintf(buf, "%s",Fil_CodeTropo[filter]);
2324  else if (DAS.Paramini.EqType == GASCODNG2 || DAS.Paramini.EqType == GASCODNG3 || DAS.Paramini.EqType == GASCODNG4)
2325  sprintf(buf, "%s",Fil_CodeNG[filter]);
2326  else if (DAS.Paramini.EqType == GASCODNG1)
2327  sprintf(buf, "%s",Fil_CodeNG1[filter]);
2328  else
2329  sprintf(buf, "%s",Fil_Code[filter]);
2330  }
2331 
2332  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[2], buf);
2333  if(FLAG.manhormeas)
2334  MObjectSetText(DAS.Gui.HorizMeas.lbl[2], buf);
2335  Status("Ready");
2336 
2337  if(!FLAG.fileprg || !FLAG.exec )
2338  //Attiva i pulsanti sulla keyboard se non si sta eseguendo una tabella di misure
2339  //oppure se il programma e' stato sospeso (si e' premuto il tasto "pause")
2340  DB_KB_ButtonActive(1);
2341 
2342 
2343  if(er) return 1;
2344 
2345  return 0;
2346 
2347 
2348 }
2349 
2350 
2351 /*
2352  * filter = 0 - 7 (0 = HOME)
2353  */
2354 int SD_NDFilterW(int filter)
2355 {
2356 
2357  char buf[80];
2358  long n[3];
2359  long nx;
2360  int d, dir[3]; // 0 = CW, 1 = CCW
2361  int k , er;
2362 // char Filter[4];
2363 
2364  //Disattiva i pulsanti sulla keyboard
2365  DB_KB_ButtonActive(0);
2368 
2369  /************************************************************/
2370  if (DAS.Paramini.EqType == SPATRAM ||
2371  DAS.Paramini.EqType == GASCODNG1 ||
2372  DAS.Paramini.EqType == SPATRAMPLUS ||
2373  DAS.Paramini.EqType == TROPOGAS ||
2374  DAS.Paramini.EqType == GASCODNG2 ||
2375  DAS.Paramini.EqType == GASCODNG3 ||
2376  DAS.Paramini.EqType == GASCODNG4 ||
2377  DAS.Paramini.EqType == SPATRAM3 ||
2378  DAS.Paramini.EqType == SPATRAM2)
2379  {
2380  k = SM_stepr(DAS.StepM.step[AMS2][1]) / 6;
2381  if(filter < 0 || filter > 5) return 0;
2382  }
2383  else // ...oppure non lo sa)
2384  {
2385  sprintf(buf, "For this Equipment the Filter Wheel type is UNKNOWN\nPlease Contact DANBO!!!!");
2386  er = MMessageDialog("DAS information", buf, "Ok", NULL);
2387  if (!er)
2388  {
2389  return 0;
2390  }
2391 
2392  }
2393  /**************************************************************/
2394 
2395  n[2] = (long)(NDFWS.Pos - filter) * k;
2396 
2397  if(n[2] < 0) dir[2] = 1;
2398  else dir[2] = 0;
2399  n[2] = labs(n[2]);
2400 
2401  nx = n[2];
2402  d = dir[2];
2403 
2404  // Eseguo NStep
2405 
2406  Status("New ND Filter Wheel Position");
2407 
2408 
2409  if(nx)
2410  {
2411  er=DB_StepMotor(AMS2, 3, nx, d);
2412  if (er)
2413  {
2414  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[AMS2][1], "SYS\\ledGreen.bmp");
2415  }
2416  }
2417 
2418 
2419  NDFWS.Pos = filter;
2420  if ( DAS.Paramini.EqType == LIS_)
2421  sprintf(buf, "%s", Fil_Code8H[filter]);
2422  else
2423  {
2424  if(DAS.Paramini.EqType == TROPOGAS)
2425  sprintf(buf, "%s",Fil_CodeTropo[filter]);
2426  else if (DAS.Paramini.EqType == GASCODNG1 || DAS.Paramini.EqType == GASCODNG2 || DAS.Paramini.EqType == GASCODNG3 || DAS.Paramini.EqType == GASCODNG4)
2427  sprintf(buf, "%s",Fil_CodeNG[filter]);
2428  else
2429  sprintf(buf, "%s",NDFil_Code[filter]);
2430  }
2431 
2432  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[3], buf);
2433  if(FLAG.manhormeas)
2434  MObjectSetText(DAS.Gui.HorizMeas.lbl[3], buf);
2435  Status("Ready");
2436 
2437  if(!FLAG.fileprg || !FLAG.exec )
2438  //Attiva i pulsanti sulla keyboard se non si sta eseguendo una tabella di misure
2439  //oppure se il programma e' stato sospeso (si e' premuto il tasto "pause")
2440  DB_KB_ButtonActive(1);
2441 
2442 
2443  if(er) return 1;
2444 
2445  return 0;
2446 
2447 
2448 }
2449 /*
2450 Corrispondenza BIT --> Devices per le Porte Optoisolate
2451 (Nel Manuale AMS -> OOP di AMS1
2452 
2453 Per LIS, SPATRAM,
2454 LSB OOP(0) --> Peltier
2455  OOP(1) --> FAN
2456  OOP(2) --> HG
2457  OOP(3) --> QJ
2458  OOP(4) --> SPARE
2459  OOP(5) --> SPARE
2460  OOP(6) --> SPARE
2461 MSB OOP(7) --> SPARE
2462 
2463 Per GASCODNG1
2464 LSB OOP(0) --> Peltier
2465  OOP(1) --> FAN
2466  OOP(2) --> HG
2467  OOP(3) --> QJ
2468  OOP(4) --> Torque MOTOR
2469  OOP(5) --> SPARE
2470  OOP(6) --> ExtLamp
2471 MSB OOP(7) --> ExtShutt
2472 
2473 Per TROPOGAS
2474 LSB OOP(0) --> Peltier
2475  OOP(1) --> FAN
2476  OOP(2) --> HG
2477  OOP(3) --> QJ
2478  OOP(4) --> Peltier Power Supply
2479  OOP(5) --> Hires Power Supply
2480  OOP(6) --> SPARE
2481 MSB OOP(7) --> SPARE
2482 
2483 */
2484 /*
2485  if(mod) // Cold
2486  OOP_AMS1 |= 0x01; //bit 0, 00000001, dec = 1
2487  else // Heat
2488  OOP_AMS1 &= 0xFE; // 11111110, dec = 254
2489 ---------------------------------------------
2490  if(mod)
2491  OOP_AMS1 |= 0x02; //bit 1, 00000010, dec = 2
2492  else
2493  OOP_AMS1 &= 0xFD; // 11111101, dec = 253
2494 ---------------------------------------------
2495  if(mod)
2496  OOP_AMS1 |= 0x04; //bit 2, 00000100, dec = 4
2497  else
2498  OOP_AMS1 &= 0xFB; // 11111011, dec = 251
2499 ---------------------------------------------
2500  if(mod)
2501  OOP_AMS1 |= 0x08; //bit 3, 00001000, dec = 8
2502  else
2503  OOP_AMS1 &= 0xF7; // 11110111, dec = 247
2504 ---------------------------------------------
2505  if(mod)
2506  OOP_AMS1 |= 0x10; //bit 4, 00010000, dec = 16
2507  else
2508  OOP_AMS1 &= 0xEF; // 11101111, dec = 239
2509 ---------------------------------------------
2510  if(mod)
2511  OOP_AMS1 |= 0x20; //bit 5, 00100000, dec = 32
2512  else
2513  OOP_AMS1 &= 0xDF; // 11011111, dec = 223
2514 ---------------------------------------------
2515  if(mod)
2516  OOP_AMS1 |= 0x40; //bit 6, 01000000, dec = 64
2517  else
2518  OOP_AMS1 &= 0xBF; // 10111111, dec = 191
2519 ---------------------------------------------
2520  if(mod)
2521  OOP_AMS1 |= 0x80; //bit 7, 10000000, dec = 128
2522  else
2523  OOP_AMS1 &= 0x7F; // 01111111, dec = 127
2524 ---------------------------------------------
2525 
2526 */
2527 
2528 
2529 
2530 // mod = 1 --> Hires Power Supply ON
2531 // mod = 0 --> Hires Power Supply OFF
2532 void HiresPS(int mod)
2533 {
2534  if(mod)
2535  DAS.StepM.OOP[AMS1] |= 0x20; //bit 5, 00100000, dec = 32
2536  else
2537  DAS.StepM.OOP[AMS1] &= 0xDF; // 11011111, dec = 223
2538 
2539 
2540  // 1's complement
2541  DAS.StepM.OOP[AMS1] = ~DAS.StepM.OOP[AMS1];
2542  //write on the optoinsulated port
2543  AMS_wopto(AMS1, DAS.StepM.OOP[AMS1]);
2544  // again 1's complement for restoring the positive logic
2545  DAS.StepM.OOP[AMS1] = ~DAS.StepM.OOP[AMS1];
2546 
2547 
2548 
2549 }
2550 
2551 void PeltierPS(int mod)
2552 {
2553 
2554  if(mod)
2555  DAS.StepM.OOP[AMS1] |= 0x10; //bit 4, 00010000, dec = 16
2556  else
2557  DAS.StepM.OOP[AMS1] &= 0xEF; // 11101111, dec = 239
2558 
2559 
2560  // 1's complement
2561  DAS.StepM.OOP[AMS1] = ~DAS.StepM.OOP[AMS1];
2562  //write on the optoinsulated port
2563  AMS_wopto(AMS1, DAS.StepM.OOP[AMS1]);
2564  // again 1's complement for restoring the positive logic
2565  DAS.StepM.OOP[AMS1] = ~DAS.StepM.OOP[AMS1];
2566 
2567 
2568 }
2569 
2570 void AMS_PWM_Zero(int mod)
2571 {
2572 
2573  int er;
2574 
2575  er = ChkDigIO(DAS.StepM.OOP[AMS2], 0);
2576 
2577  if(mod)
2578  DAS.StepM.OOP[AMS2] |= 0x01; //bit 0 , 00000001
2579  else
2580  DAS.StepM.OOP[AMS2] &= 0xFE;
2581 
2582 
2583  // 1's complement
2584  DAS.StepM.OOP[AMS2] = ~DAS.StepM.OOP[AMS2];
2585  //write on the optoinsulated port
2586  //AMS_wopto(AMS2, DAS.StepM.OOP[AMS2]);
2587  AMS_wopto(AMS2, 1);
2588  delay(500);
2589  // again 1's complement for restoring the positive logic
2590  DAS.StepM.OOP[AMS2] = ~DAS.StepM.OOP[AMS2];
2591 
2592 
2593 
2594 
2595 }
2596 
2597 void Peltier(int mod)
2598 {
2599 
2600  if(mod) // Cold
2601  DAS.StepM.OOP[AMS1] |= 0x01; //bit 0 , 00000001
2602  else // Heat
2603  DAS.StepM.OOP[AMS1] &= 0xFE;
2604 
2605 
2606  // 1's complement
2607  DAS.StepM.OOP[AMS1] = ~DAS.StepM.OOP[AMS1];
2608  //write on the optoinsulated port
2609  AMS_wopto(AMS1, DAS.StepM.OOP[AMS1]);
2610  delay(750);
2611  // again 1's complement for restoring the positive logic
2612  DAS.StepM.OOP[AMS1] = ~DAS.StepM.OOP[AMS1];
2613 
2614 
2615 
2616 
2617 }
2618 
2619 void FANECU(int mod)
2620 {
2621 
2622  unsigned long t = 500;
2623 // char buf[256];
2624  int er = 0;
2625 
2626 
2627  if(mod)
2628  {
2629  DAS.StepM.OOP[AMS3] |= 0x02; //bit 1, 00000010
2630  MObjectSetText(DAS.Gui.PushButt.KeyB[6], "F ECU On");
2631  }
2632  else
2633  {
2634  DAS.StepM.OOP[AMS3] &= 0xFD; //11111101
2635  MObjectSetText(DAS.Gui.PushButt.KeyB[6], "F ECU Off");
2636  }
2637 
2638  // 1's complement
2639  DAS.StepM.OOP[AMS3] = ~DAS.StepM.OOP[AMS3];
2640  //write on the optoinsulated port
2641  AMS_wopto(AMS3, DAS.StepM.OOP[AMS3]);
2642  delay(100);
2643  // again 1's complement for restoring the positive logic
2644  DAS.StepM.OOP[AMS3] = ~DAS.StepM.OOP[AMS3];
2645 
2646 
2647 }
2648 
2649 
2650 
2651 
2652 void FANPeltier(int mod)
2653 {
2654 
2655  if(mod)
2656  DAS.StepM.OOP[AMS1] |= 0x02; //bit 1, 00000010
2657  else
2658  DAS.StepM.OOP[AMS1] &= 0xFD; //11111101
2659 
2660 
2661  // 1's complement
2662  DAS.StepM.OOP[AMS1] = ~DAS.StepM.OOP[AMS1];
2663  //write on the optoinsulated port
2664  //delay(500);
2665  AMS_wopto(AMS1, DAS.StepM.OOP[AMS1]);
2666  delay(750);
2667  // again 1's complement for restoring the positive logic
2668  DAS.StepM.OOP[AMS1] = ~DAS.StepM.OOP[AMS1];
2669 
2670 
2671 }
2672 
2673 void HgLamp(int mod)
2674 {
2675 
2676  if(mod)
2677  {
2678 
2679  // Bitwise inclusive OR
2680  //The bitwise-inclusive-OR operator compares each bit of its first operand to
2681  //the corresponding bit of its second operand. If either bit is 1,
2682  //the corresponding result bit is set to 1. Otherwise, the corresponding
2683  //result bit is set to 0.
2684  //i.e if(DAS.StepM.OOP[AMS1] = 00000000) -->
2685  //DAS.StepM.OOP[AMS1] | 0x04 = 00000000 | 00000100 = 00000100
2686  DAS.StepM.OOP[AMS1] |= 0x04; //bit 2, 00000100
2687  HGFlg = 1;
2688  MObjectSetText(DAS.Gui.ContrPanel.pblamps[0], "Hg On");
2689  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedHG, "SYS\\ledonHG.bmp");
2690 
2691  }
2692  else
2693  {
2694  //The bitwise-AND operator compares each bit of its first operand to
2695  //the corresponding bit of its second operand. If both bits are 1,
2696  //the corresponding result bit is set to 1. Otherwise, the corresponding
2697  //result bit is set to 0.
2698  //i.e if(DAS.StepM.OOP[AMS1] = 00000100) -->
2699  //DAS.StepM.OOP[AMS1] | 0xFB = 00000100 | 11111011 = 00000000
2700  DAS.StepM.OOP[AMS1] &= 0xFB; //11111011
2701 
2702  HGFlg = 0;
2703  MObjectSetText(DAS.Gui.ContrPanel.pblamps[0], "Hg Off");
2704  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedHG, "SYS\\ledoff.bmp");
2705  }
2706 
2707  // 1's complement
2708  // 1) if mod and DAS.StepM.OOP[AMS1] = 00000100 then 11111011
2709  // 2) if !mod and DAS.StepM.OOP[AMS1] = 00000000 then 11111111
2710  DAS.StepM.OOP[AMS1] = ~DAS.StepM.OOP[AMS1];
2711 
2712  //write on the optoinsulated port
2713  // 1) bit 2 set to 0 (we are in negative logic so 0 = ON, 1 = OFF)
2714  // 1) bit 2 set to 1 (we are in negative logic so 0 = ON, 1 = OFF)
2715  AMS_wopto(AMS1, DAS.StepM.OOP[AMS1]);
2716 
2717  // again 1's complement for restoring the positive logic
2718  // 1) if mod and DAS.StepM.OOP[AMS1] = 11111011 then 00000100 (bit 2 on)
2719  // 2) if !mod and DAS.StepM.OOP[AMS1] = 11111111 then 00000000 (bit 2 off)
2720  DAS.StepM.OOP[AMS1] = ~DAS.StepM.OOP[AMS1];
2721 
2722 }
2723 
2724 void QjLamp(int mod)
2725 {
2726 
2727  if(mod)
2728  {
2729  DAS.StepM.OOP[AMS1] |= 0x08; //bit 3, 00001000
2730  QJFlg = 1;
2731  MObjectSetText(DAS.Gui.ContrPanel.pblamps[1], "Qj On");
2732  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedQJ, "SYS\\ledonQJ.bmp");
2733 
2734  }
2735  else
2736  {
2737  DAS.StepM.OOP[AMS1] &= 0xF7; //11110111
2738  QJFlg = 0;
2739  MObjectSetText(DAS.Gui.ContrPanel.pblamps[1], "Qj Off");
2740  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedQJ, "SYS\\ledoff.bmp");
2741  }
2742 
2743  // 1's complement
2744  DAS.StepM.OOP[AMS1] = ~DAS.StepM.OOP[AMS1];
2745  //write on the optoinsulated port
2746  AMS_wopto(AMS1, DAS.StepM.OOP[AMS1]);
2747  // again 1's complement for restoring the positive logic
2748  DAS.StepM.OOP[AMS1] = ~DAS.StepM.OOP[AMS1];
2749 
2750 
2751 }
2752 
2753 
2754 
2755 
2756 //convert SUN AZIMUTH and ZENITH angles, to be used with MIGE
2757 //mode = 0 --> fix azimuth and return azimuth for MIGE positioning
2758 //mode = 1 --> fix zenith and return zenith for MIGE positioning
2759 float MIGEActualZenAz(int mode)
2760 {
2761 
2762 // float MAZMax = 120.0; //MIGE Azimut MAX
2763 // float MAZMin = -60.0; //MIGE Azimut Min
2764  float MAZMax = 120.0; //MIGE Azimut MAX
2765  float MAZMin = 0.0; //MIGE Azimut Min
2766 
2767  float SAA, SEA, elev, az;
2768  char str[80];
2769 
2770  if (mode == 0) //fix azimuth angle
2771  {
2772  //Need condition for the latitude?
2773  // Inside Tropics
2774 
2775  //sun Azimuth angle
2776  sprintf(str, "%.01lf", S_azim);
2777  SAA = (float)atof(str);
2778 
2779  az = MIGEAz(SAA);
2780  return az;
2781  }
2782 
2783  if (mode == 1) //fix zenith angle
2784  {
2785  //sun Azimuth angle
2786  sprintf(str, "%.01lf", S_azim);
2787  SAA = (float)atof(str);
2788 
2789 
2790  //sun Zenit angle
2791  sprintf(str, "%.01lf", (90 - S_zenetr));
2792  SEA = (float)atof(str);
2793 
2794  elev = MIGEZen(SEA);
2795 /*
2796  if (SAA >= 0 && SAA <= MAZMax)
2797  {
2798  elev = elev;
2799  }
2800  if (SAA > MAZMax && SAA <= (MAZMax + 180))
2801  {
2802  elev = -elev;
2803  }
2804  if (SAA > (MAZMax + 180) && SAA < 360)
2805  {
2806  elev = elev;
2807  }
2808 */
2809  return elev;
2810  }
2811 
2812 return 0;
2813 
2814 }
2815 
2816 int SD_Zenith_H(float ang)
2817 {
2818 
2819  int er = 0;
2820  char buf[80];
2821  long n, dp = 500; // dp sono i dead pulse, vanno aggiunti all'inversione per il recupero del gioco
2822  int dir;
2823  float k = 0;
2824 // float x;
2825  double GRASTEP, STEPGRA;
2826  float prepos;
2827  double yy;
2828 // float rzenang;
2829 // if(DAS.MIGE.type)
2830 // {
2831  // +90 --> DX looking to the North
2832  // -90 --> SX looking to the North
2833  if(ang < -91 || ang > 91 ) return 0;
2834 // }
2835 // else
2836 // {
2837  //if ang is not in the limits the DAS exit from the function
2838 // if(ang < -91 || ang > 45 ) return 0;
2839 // }
2840  //Status("Set NEW zenith Position");
2841 
2842  //Disattiva i pulsanti sulla keyboard
2843  DB_KB_ButtonActive(0);
2846 
2847 
2848  k = (float)SM_stepr(DAS.StepM.step[AMS3][0]); // step/round
2849 
2850  GRASTEP = 360/k; // º/step
2851 
2852  STEPGRA = k/360; // step/º
2853 
2854 
2855  yy = -(ang - ZST.Pos); // -(55-90) = 35 //1
2856  //-(56-55) = -1 //2
2857  //-(96-56) = -40 //3
2858  //-(90-96) = 6 //4
2859 
2860 
2861  n = (long)(yy * STEPGRA * (DAS.StepM.multiplier[AMS3][0])); //4 e' la riduzione
2862 
2863 
2864  prepos = (float)ZST.Pos;
2865  ZST.Pos = ang;
2866 
2867  sprintf(buf, " %.1lf --> %.1lf", prepos, ang);
2868  Status(buf);
2869 
2870  // Select direction
2871  if(n < 0)
2872  dir = 1;
2873  else
2874  dir = 0;
2875 
2876  n = labs(n);
2877 
2878 
2879  if (n==0)
2880  {
2881  //Attiva i pulsanti sulla keyboard
2882  DB_KB_ButtonActive(1);
2883  return 1;
2884  }
2885 
2886  // Eseguo n passi
2887  if(n)
2888  {
2889  er = DB_StepMotor(AMS3, 4, n, dir);
2890  if (er)
2891  {
2892  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[AMS3][0], "SYS\\ledGreen.bmp");
2893  }
2894  }
2895 
2896  sprintf(buf, "%.2lf", ang);
2897  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[4], buf);
2898  if(!FLAG.fileprg || !FLAG.exec )
2899  //Attiva i pulsanti sulla keyboard se non si sta eseguendo una tabella di misure
2900  //oppure se il programma e' stato sospeso (si e' premuto il tasto "pause")
2901  DB_KB_ButtonActive(1);
2902 
2903 
2904 
2905  if(er) return 1;
2906 
2907 
2908  return 0;
2909 
2910 
2911 
2912 
2913 
2914 }
2915 
2916 int SD_Zenith(float ang)
2917 {
2918  int er = 0;
2919  char buf[80];
2920  long n, dp = 500; // dp sono i dead pulse, vanno aggiunti all'inversione per il recupero del gioco
2921  int dir;
2922  int k = 0;
2923 // float x;
2924  double GRASTEP, STEPGRA;
2925 // float prepos;
2926  double yy;
2927  float rzenang;
2928 // if(DAS.MIGE.type)
2929 // {
2930  // +90 --> DX looking to the North
2931  // -90 --> SX looking to the North
2932 // if(ang < 0 || ang > 180 ) return 0;
2933 // }
2934 // else
2935 // {
2936  //if ang is not in the limits the DAS exit from the function
2937 // if(ang < -91 || ang > 45 ) return 0;
2938 // }
2939  //Status("Set NEW zenith Position");
2940 
2941  //Disattiva i pulsanti sulla keyboard
2942  DB_KB_ButtonActive(0);
2945 
2946 /*
2947  k = (float)SM_stepr(DAS.StepM.step[AMS3][0]); // step/round
2948 
2949  GRASTEP = 360/k; // º/step
2950 
2951  STEPGRA = k/360; // step/º
2952 
2953 
2954  yy = -(ang - ZST.Pos); // -(55-90) = 35 //1
2955  //-(56-55) = -1 //2
2956  //-(96-56) = -40 //3
2957  //-(90-96) = 6 //4
2958 
2959 
2960  n = (long)(yy * STEPGRA * (DAS.StepM.multiplier[AMS3][0])); //4 e' la riduzione
2961 
2962 
2963  prepos = ZST.Pos;
2964  ZST.Pos = ang;
2965 
2966  sprintf(buf, " %.1lf --> %.1lf", prepos, ang);
2967  Status(buf);
2968 
2969  // Select direction
2970  if(n < 0)
2971  dir = 1;
2972  else
2973  dir = 0;
2974 
2975  n = labs(n);
2976 
2977 // if(n && dir == 0) //si va verso l'UV
2978 // n += dp; // // add fixed step number for backlash recovery
2979 
2980 
2981 */
2982 
2983 
2984  //Zenith positioning
2985  rzenang=MIGEZen((float)ang);
2986 
2987  if(ang >= 0 && ang <= 180 )
2988  {
2989 
2990 
2991 
2992  k = SM_stepr(DAS.StepM.step[AMS3][DAS.StepM.SM_A]); // step/round
2993 
2994  GRASTEP = (float) 360.0 / (float) k; // degree/step
2995 
2996  STEPGRA = (float) k / (float) 360.0; // step/degree
2997 
2998 // yy = -(z - ZST.Pos);
2999  yy = -(rzenang - ZST.Pos);
3000  n = (long)(yy * STEPGRA * (DAS.StepM.multiplier[AMS3][0]));
3001 // ZST.Pos = z;
3002  ZST.Pos = rzenang;
3003  ZST.realzenpos = ang;
3004  // Select direction
3005  if(n < 0)
3006  dir = 1;
3007  else
3008  dir = 0;
3009 
3010  n = labs(n);
3011  DAS.StepM.Revo[AMS3][DAS.StepM.SM_A] = dir;
3012  DAS.StepM.nstep[AMS3][DAS.StepM.SM_A] = n;
3013  }
3014  else
3015  {
3016  DAS.StepM.Revo[AMS3][DAS.StepM.SM_A] = 0;
3017  DAS.StepM.nstep[AMS3][DAS.StepM.SM_A] = 0;
3018  sprintf(buf, "Not Allowed Zen.");
3019  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[4], buf);
3020 
3021  }
3022 
3023  if (n==0)
3024  {
3025  //Attiva i pulsanti sulla keyboard
3026  DB_KB_ButtonActive(1);
3027  return 1;
3028  }
3029 
3030  // Eseguo n passi
3031  if(n)
3032  {
3033  er = DB_StepMotor(AMS3, 4, DAS.StepM.nstep[AMS3][DAS.StepM.SM_A], DAS.StepM.Revo[AMS3][DAS.StepM.SM_A]);
3034  if (er)
3035  {
3036  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[AMS3][0], "SYS\\ledGreen.bmp");
3037  }
3038  }
3039 
3040 /* if(dir == 0)
3041  {
3042  er=DB_StepMotor(AMS3, DAS.StepM.SM5, dp, 1);
3043  if (er)
3044  {
3045  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM5, "SYS\\ledGreen.bmp");
3046  }
3047  }
3048 */
3049 
3050  sprintf(buf, "%.2lf", ang);
3051  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[4], buf);
3052  if(!FLAG.fileprg || !FLAG.exec )
3053  //Attiva i pulsanti sulla keyboard se non si sta eseguendo una tabella di misure
3054  //oppure se il programma e' stato sospeso (si e' premuto il tasto "pause")
3055  DB_KB_ButtonActive(1);
3056 
3057 
3058 
3059  if(er) return 1;
3060 
3061 
3062  return 0;
3063 
3064 }
3065 
3066 void SD_FNTorqueM(int mod)
3067 {
3068 
3069  if(mod)
3070  {
3071 
3072  // Bitwise inclusive OR
3073  //The bitwise-inclusive-OR operator compares each bit of its first operand to
3074  //the corresponding bit of its second operand. If either bit is 1,
3075  //the corresponding result bit is set to 1. Otherwise, the corresponding
3076  //result bit is set to 0.
3077  //i.e if(DAS.StepM.OOP[AMS1] = 00000000) -->
3078  //DAS.StepM.OOP[AMS1] | 0x10 = 00000000 | 00010000 = 00010000
3079  DAS.StepM.OOP[AMS1] |= 0x10; //bit 4, 00010000
3080  TMFlg = 1;
3081  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[3], " ON");
3082  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[1][1], "SYS\\ledGreen.bmp");
3083 
3084  }
3085  else
3086  {
3087  //The bitwise-AND operator compares each bit of its first operand to
3088  //the corresponding bit of its second operand. If both bits are 1,
3089  //the corresponding result bit is set to 1. Otherwise, the corresponding
3090  //result bit is set to 0.
3091  //i.e if(DAS.StepM.OOP[AMS1] = 00010000) -->
3092  //DAS.StepM.OOP[AMS1] | 0xEF = 00010000 | 11101111 = 00000000
3093  DAS.StepM.OOP[AMS1] &= 0xEF; //11111011
3094 
3095  TMFlg = 0;
3096  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[3], " OFF");
3097  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[1][1], "SYS\\ledoff.bmp");
3098  }
3099 
3100  DAS.StepM.OOP[AMS1] = ~DAS.StepM.OOP[AMS1];
3101 
3102  AMS_wopto(AMS1, DAS.StepM.OOP[AMS1]);
3103 
3104  DAS.StepM.OOP[AMS1] = ~DAS.StepM.OOP[AMS1];
3105 
3106 }
3107 
3108 //ang = mechanical MIGE Angle
3109 //raz = real Azimuth Angle
3110 int SD_Azimuth(float ang, float raz)
3111 {
3112  int er = 0;
3113  char buf[80];
3114  long n, dp = 500; // dp sono i dead pulse, vanno aggiunti all'inversione per il recupero del gioco
3115  int dir;
3116  int k = 0;
3117  float yy;
3118  double GRASTEP, STEPGRA;
3119  float razang;
3120 
3121 
3122  razang=MIGEAz((float)ang);
3123 
3124  k = SM_stepr(DAS.StepM.step[AMS3][DAS.StepM.SM_B]); // step/round
3125 
3126  GRASTEP = (float)360.0 / (float) k; // degree/step
3127 
3128  STEPGRA = (float) k / (float)360.0; // step/degree
3129 
3130  yy = (razang - (float)AST.Pos);
3131 
3132  n = (long) (yy * STEPGRA * DAS.StepM.multiplier[AMS3][1]);
3133 
3134  AST.Pos = razang;
3135  AST.realazpos = ang;
3136 
3137  // Select direction
3138  if(n < 0)
3139  dir = 1;
3140  else
3141  dir = 0;
3142 
3143  n = labs(n);
3144  DAS.StepM.Revo[AMS3][DAS.StepM.SM_B] = dir;
3145  DAS.StepM.nstep[AMS3][DAS.StepM.SM_B] = n;
3146 
3147 
3148 
3149 
3150  //Disattiva i pulsanti sulla keyboard
3151  DB_KB_ButtonActive(0);
3154 
3155 /*
3156  k = (float) SM_stepr(DAS.StepM.step[AMS3][1]); // step/round
3157 
3158  GRASTEP = (float)360.0 / (float) k; // degree/step
3159 
3160  STEPGRA = (float) k / (float)360.0; // step/degree
3161 
3162 
3163 
3164  x = (ang - AST.Pos); // (-35-0) = -35 //1
3165  //(55-(-35)) = -90 //2
3166  //(56-55) = 1 //3
3167  //(90-96) = 6 //4
3168 
3169 
3170  n = (long) (x * STEPGRA * DAS.StepM.multiplier[AMS3][1]); //4 e' la riduzione
3171 
3172  prepos = AST.Pos;
3173  AST.Pos = ang;
3174  AST.realazpos = raz;
3175 
3176  sprintf(buf, " %.1lf --> %.1lf", prepos, ang);
3177  Status(buf);
3178 
3179  // Select direction
3180  if(n < 0)
3181  dir = 1;
3182  else
3183  dir = 0;
3184 
3185  n = labs(n);
3186 
3187 
3188 
3189 
3190  if (n==0)
3191  {
3192  //Attiva i pulsanti sulla keyboard
3193  DB_KB_ButtonActive(1);
3194  return 1;
3195  }
3196 */
3197  // Eseguo n passi
3198  if(n)
3199  {
3200  er = DB_StepMotor(AMS3, 5, DAS.StepM.nstep[AMS3][DAS.StepM.SM_B], DAS.StepM.Revo[AMS3][DAS.StepM.SM_B]);
3201  if (er)
3202  {
3203  MPixmapSetImageFile(DAS.Gui.ContrPanel.LedSM[AMS3][1], "SYS\\ledGreen.bmp");
3204  }
3205  }
3206 
3207 
3208  //sprintf(buf, "%.1lf%s %.1lf%s", ang, " °", raz, " °");
3209  sprintf(buf, "%.1lf", AST.realazpos );
3210  MObjectSetText(DAS.Gui.ContrPanel.Albl_LS[5], buf);
3211  if(!FLAG.fileprg || !FLAG.exec )
3212  //Attiva i pulsanti sulla keyboard se non si sta eseguendo una tabella di misure
3213  //oppure se il programma e' stato sospeso (si e' premuto il tasto "pause")
3214  DB_KB_ButtonActive(1);
3215 
3216 
3217 
3218  if(er) return 1;
3219 
3220 
3221  return 0;
3222 
3223 }
3224 
das DAS
DAS structure.
Definition: Spat_Device.c:27
stepm StepM
Stepper motors parameters structure.
#define SPATRAM
SPectrometer for Atmospheric TRAcers Measurements - CGE-UE Portugal.
Status of the Zenith .
NDFilterWheelSt NDFWS
ND Filter Wheel.
Definition: DAS_Spat.c:58
gui Gui
Graphic User Interface Structure.
void DB_KB_ButtonActive(int mod)
Enable/Disable Push buttons on the Control Panel.
Definition: CreateForms.c:3810
MOBJECT LedSM[AMSMAX][2]
Leds for stepper motors status.
void QjLamp(int mod)
QJ Lamp ON/OFF .
Definition: Spat_Device.c:2724
int Pos
Filter Wheel current Position.
MOBJECT Albl_LS[8]
Active Control Panel Labels for LIS status.
double S_zenetr
Definition: SOLPOS.C:92
void D_VRangeSim(int id, char *str, int val, int r, int g, int b, int x, int y)
init progress bar during simultaneous positioning
Definition: Utils.c:258
char fsmlog[_MAX_PATH]
daily LOG file for stepper motor moovements
void MLoopWhileEvents(int discard)
void HiresPS(int mod)
Hires Power Supply ON/OFF .
Definition: Spat_Device.c:2532
optionini DOption
Options for DAS execution.
#define AMS2
AMS2 address.
const char * Mir_Code[]
const char array for the realisation of the Mirrors buttons in the Mirror shell
Definition: DAS_Spat.c:231
char buftx[1024]
Tx buffer.
Definition: DXL.H:21
MOBJECT KeyB[28]
Keyboard Buttons.
int NAMS
Number of AMSs Devices.
MOBJECT LedQJ
Control Panel Led for QJ Lamp.
double realazpos
dlog DLOG
Definition: DAS_Spat.c:52
int SD_PosOMUDev(int m, int w, int f)
perform the simoultaneous positioning of the Spectrometer Devices in the OMU Unit m = mirror w = wave...
Definition: Spat_Device.c:747
double S_azim
O: Solar azimuth angle: N=0, E=90, S=180, W=270.
Definition: SOLPOS.C:45
int SM_A
Motor A (su Y11) respectively: ID=0->InputMirror,ID=1->FilterWheel,ID=2->Zenith.
DXL structure. Structure for the serial communication with the AMS adapter.
Definition: DXL.H:16
void FANECU(int mod)
FAN ON/OFF .
Definition: Spat_Device.c:2619
void MPixmapSetImageFile(MOBJECT pixmap, const char *fname)
das structure (contain all the previous structures) .
int SD_Zenith(float ang)
Positioning Zenith. The Zenith reaches the position specified by ang.
Definition: Spat_Device.c:2916
void HgLamp(int mod)
HG Lamp ON/OFF .
Definition: Spat_Device.c:2673
unsigned long nstep[AMSMAX][2]
Number of steps to be executed.
int Pos
Mirror Current Position.
int QJFlg
Definition: DAS_Spatram.h:2969
flag Flag
Structure for different flags.
#define DBDEMO
execution in demo mode
DXL_par DXL
Definition: Spat_Device.c:17
MOBJECT pblamps[2]
Control Panel Push buttons for HG and QJ Lamps.
int Offset[16]
Offset of the hardware devices (Input Mirror (5), Grating, Filter Wheel...)
void SD_FNTorqueM(int mod)
Positioning NDFilter. .
Definition: Spat_Device.c:3066
void PeltierPS(int mod)
Peltier Power Supply ON/OFF .
Definition: Spat_Device.c:2551
char * Fil_Code8H[]
const char array for the realisation of the Filters buttons in the Filter shell
Definition: DAS_Spat.c:204
float multiplier[AMSMAX][2]
multiplier, > 0 multiplier, < 0 demultiplier
int SM_stepr(int t)
AMS &#39;steps/round&#39; value return the AMS &#39;steps/round&#39; value (microstepping) depending on the setted st...
Definition: Spat_Device.c:209
void MObjectSetText(MOBJECT obj, const char *text)
int TMFlg
Definition: DAS_Spatram.h:2972
int ChkDigIO(unsigned char word, int bitn)
check for digital I/O Status
int Pos
Filter Wheel current Position.
AzimuthSt AST
Definition: Spat_Device.c:25
int SD_Grating(int ang)
Positioning Grating. The Grating move to the position specified by ang (Wavelength) ...
Definition: Spat_Device.c:2108
void Peltier(int mod)
Peltier ON/OFF .
Definition: Spat_Device.c:2597
int SD_Azimuth(float ang, float raz)
Positioning Azimuth. The Zenith reaches the position specified by ang.
Definition: Spat_Device.c:3110
#define LIS_
Lampedusa Island Spectrometer - ENEA.
int SD_Mirror(int where)
Positioning Input Mirror. The Input Mirror reaches the position specified by where.
Definition: Spat_Device.c:1898
Control Flags.
int exec
= 0 -> PRG Execution Paused; = 1 -> PRG Execution Resumed
int Wl
Grating Wavelength.
#define TROPOGAS
TROPOspheric Gas Analyzer Spectrometer.
horizmeas HorizMeas
Structure for Horizontal Measurements.
char * Fil_CodeNG[]
const char array for the realisation of the Filters buttons in the Filter shell for GASCODNG2 and NG3...
Definition: DAS_Spat.c:216
char bufrx[1024]
Rx buffer.
Definition: DXL.H:20
long dp
Grating backslash recovery steps.
long postime[AMSMAX][2]
time necessary for positioning
#define GASCODNG2
GASCODNG 2 (with ATX power supply & HiresIV)
unsigned char OOP[AMSMAX]
2 byte Word for AMS Opto insulated Output Port Status
#define SPATRAM2
SPATRAM2 (with ATX power supply & HiresV)
#define SPATRAMPLUS
As SPATRAM plus AltAzimuth platform.
int SD_Position(int m, int w, int f, double z, double a)
perform the simoultaneous positioning of the Spectrometer Devices m = mirror w = wavelength (Grating)...
Definition: Spat_Device.c:1243
void Status(char *tit)
Writes information&#39;s on the Status label .
Definition: Load.c:1556
float MIGEActualZenAz(int mode)
convert SUN AZIMUTH and ZENITH angles, to be used with MIGE mode = 0 –> fix azimuth and return azimu...
Definition: Spat_Device.c:2759
void delay(unsigned long d)
Pauses for a specified number of milliseconds. .
Definition: Dxl.c:1113
void WriteLogAMS(int id, int dira, int dirb, unsigned long stepa, unsigned long stepb)
Definition: Spat_Device.c:299
#define GASCODNG3
GASCODNG 3 (with ATX power supply & HiresIV)
pushbutt PushButt
Push buttons.
int Revo[AMSMAX][2]
Revolution Direction CW CCW.
#define GASCODNG1
GASCODNG 1 (with ATX power supply & HiresIV)
Function prototypes.
#define GASCODNG4
GASCODNG 4.
int SD_PosAADev(double z, double a)
perform the simoultaneous positioning of the AltAzimuth platform z = Zenith Axis a = Grating Position...
Definition: Spat_Device.c:447
ZenithSt ZST
Definition: Spat_Device.c:24
char * Fil_CodeNG1[]
const char array for the realisation of the Filters buttons in the Filter shell for GASCODNG1 instrum...
Definition: DAS_Spat.c:213
int amsprogbar
display/hide prograssion bar, 0 = Hide, 1 = display
int MMessageDialog(const char *t, const char *msg, const char *btn1, const char *btn2,...)
#define SPATRAM3
SPATRAM3.
MirrorSt MIS
Mirror.
Definition: DAS_Spat.c:61
flag FLAG
flags structure
Definition: Spat_Device.c:19
int SD_FilterW(int filter)
Positioning Filter wheel. The filter wheel move on the filter number specified by filter...
Definition: Spat_Device.c:2244
Function prototypes.
int AMS_wopto(int id, unsigned int w)
write the value on the optoinsulated port write the value on the optoinsulated port.
Definition: Dxl.c:911
int SM_B
Motor B (su Y12) respectively: ID=0->Grating,ID=1->Not Connected,ID=2->Azimuth.
char * Fil_Code[]
const char array for the realisation of the Filters buttons in the Filter shell
Definition: DAS_Spat.c:207
int wl[]
WaveLength definition - for SD_Grating.
Definition: DAS_Spat.c:182
int fileprg
Flag indicating the execution of a PRG file: = 0 –> No PRG File; = 1 –> PRG file in execution...
controlpanel ContrPanel
Control Panel Structure.
GratingSt GRS
Grating.
Definition: Spat_Device.c:22
int SD_NDFilterW(int filter)
Positioning Filter wheel. The filter wheel move on the filter number specified by filter...
Definition: Spat_Device.c:2354
#define AMS1
AMS1 address.
int DD_VOpen[16]
Definition: Utils.c:151
static double st
Definition: SOLPOS.C:142
int manhormeas
1 = horizontal measurements in manual mode
int step[AMSMAX][2]
Stepper Motors Step.
double speed_Hz[AMSMAX][2]
Stepper Motors Speed [Hz].
int aaopmode
operation mode for the Alt Az Platform, 0 = solar Traxker; 1 = Anti-Solar Tracker; 2 = Free Positioni...
int SD_Zenith_H(float ang)
Definition: Spat_Device.c:2816
void FANPeltier(int mod)
FAN ON/OFF .
Definition: Spat_Device.c:2652
void writelogmotor(int mod, int id_motore, int k, int d, long steps, unsigned char ams_id)
Write Motor Operations on Log File. Write on the SM.LOG file the commands send to the motors...
Definition: Spat_Device.c:48
char * Fil_CodeTropo[]
const char array for the realisation of the Filters buttons in the Filter shell for TROPOGAS instrume...
Definition: DAS_Spat.c:210
static double elev
Definition: SOLPOS.C:130
double realzenpos
void AMS_PWM_Zero(int mod)
Definition: Spat_Device.c:2570
char * NDFil_Code[]
const char array for the realisation of the Filters buttons in the ND Filter shell ...
Definition: DAS_Spat.c:219
long Pos
Grating Position.
int EqType
Spectrometer Type.
int HGFlg
Definition: DAS_Spatram.h:2968
double Pos
Azimuth Current Position.
long wav[]
Step Number definition - for SD_Grating.
Definition: DAS_Spat.c:195
int AMS_sendstep(int id, int dira, int dirb, unsigned long stepa, unsigned long stepb)
Send steps Procedure for sending steps to the Stepper Motor.
Definition: Dxl.c:513
void MObjectSetSensitive(MOBJECT obj)
float MIGEZen(float p)
Definition: CreateForms.c:3419
float SMfraz(int t)
denominator value of the stepping ratio
Definition: Spat_Device.c:129
double Pos
Zenith Current Position.
Status of the Azimuth .
MOBJECT LedHG
Control Panel Led for HG Lamp.
MOBJECT lbl[15]
generic labels for hor meas shell
float MIGEAz(float p)
Definition: CreateForms.c:3475
Status of the Grating .
int exemode
Set the Execution MODE (Execution modes)
FilterWheelSt FWS
Filter Wheel.
Definition: DAS_Spat.c:57
#define AMS3
AMS3 address.
int DB_StepMotor(int id, int motor, long step, int dir)
Send steps to the selected stepper motor. .
Definition: Dxl.c:816
const char * Mir_CodeTropo[]
const char array for the realisation of the Mirrors buttons in the Mirror shell for TROPOGAS ...
Definition: DAS_Spat.c:234
paramini Paramini
structure for the parameters defined in param.ini configuration file
______________________________________________________________________________________
Generated on Mon Sep 18 2017 11:44:09 for DAS - Rel. 3.1.6 - 18/09/2017.