Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
184 | f9daq | 1 | #include <formatio.h> |
2 | #include <utility.h> |
||
3 | #include <ansi_c.h> |
||
4 | #include <rs232.h> |
||
5 | #include "SP2155.h" |
||
6 | |||
7 | #define COMWAIT 1.0 |
||
8 | #define COMDELAY 0.05 |
||
9 | |||
10 | static int SP2155_Port; |
||
11 | static int nin, nout, ires; |
||
12 | static char SP2155_Send[100], SP2155_Receive[100]; |
||
13 | |||
14 | void _VI_FUNC SP2155_Open (int port) |
||
15 | { |
||
16 | SP2155_Port=port; |
||
17 | |||
18 | OpenComConfig (SP2155_Port, "", 38400, 0, 8, 1, 512, 512); |
||
19 | SetXMode (SP2155_Port, 0); |
||
20 | SetCTSMode (SP2155_Port, LWRS_HWHANDSHAKE_OFF); |
||
21 | SetComTime (SP2155_Port, COMWAIT); |
||
22 | |||
23 | return; |
||
24 | } |
||
25 | |||
26 | int _VI_FUNC SP2155_Cmd (char *cmd, double wait) |
||
27 | { |
||
28 | Delay(COMDELAY); |
||
29 | FlushInQ (SP2155_Port); |
||
30 | nout = sprintf (SP2155_Send, "%s\r", cmd); |
||
31 | ComWrt (SP2155_Port, SP2155_Send, nout); |
||
32 | if (wait!=0.) SetComTime (SP2155_Port, wait); |
||
33 | nin = ComRdTerm (SP2155_Port, SP2155_Receive, 90, 0xa); |
||
34 | if (wait!=0.) SetComTime (SP2155_Port, COMWAIT); |
||
35 | if (CompareStrings (SP2155_Receive, nin-3, "ok\r", 0, 0)) return -1; |
||
36 | nin=nin-5; |
||
37 | SP2155_Receive[nin]=0; |
||
38 | return (nin); |
||
39 | } |
||
40 | |||
41 | void _VI_FUNC SP2155_Echo (int mode) |
||
42 | { |
||
43 | if (mode) { |
||
44 | SP2155_Cmd ("ECHO",0); |
||
45 | }else{ |
||
46 | SP2155_Cmd ("NO-ECHO",0); |
||
47 | } |
||
48 | return; |
||
49 | } |
||
50 | |||
51 | int _VI_FUNC SP2155_GetWavelength (void) |
||
52 | { |
||
53 | //** returns wavelength in angstrems |
||
54 | |||
55 | int ia; |
||
56 | float wl; |
||
57 | |||
58 | SP2155_Cmd ("?NM",0); |
||
59 | sscanf(SP2155_Receive," %f ",&wl); |
||
60 | ia = floor (10*wl+0.5); |
||
61 | return (ia); |
||
62 | } |
||
63 | |||
64 | void _VI_FUNC SP2155_SetWavelength (int wavel) |
||
65 | { |
||
66 | //** sets wavelength in angstrems |
||
67 | |||
68 | float wl; |
||
69 | char cmd[100]; |
||
70 | |||
71 | wl=(float)wavel/10.; |
||
72 | sprintf(cmd,"%0.1f GOTO",wl); |
||
73 | SP2155_Cmd (cmd,10); |
||
74 | } |
||
75 | |||
76 | int _VI_FUNC SP2155_GetGrating (void) |
||
77 | { |
||
78 | int ig; |
||
79 | |||
80 | SP2155_Cmd ("?GRATING",0); |
||
81 | sscanf(SP2155_Receive," %d ",&ig); |
||
82 | return (ig); |
||
83 | } |
||
84 | |||
85 | void _VI_FUNC SP2155_SetGrating (int grating) |
||
86 | { |
||
87 | char cmd[100]; |
||
88 | |||
89 | if ((grating!=1)&&(grating!=2)) return; |
||
90 | sprintf(cmd,"%0d GRATING",grating); |
||
91 | SP2155_Cmd (cmd,30); |
||
92 | } |
||
93 | |||
94 | int _VI_FUNC SP2155_GetTurret (void) |
||
95 | { |
||
96 | return (1); |
||
97 | } |
||
98 | |||
99 | void _VI_FUNC SP2155_SetTurret (int turret) |
||
100 | { |
||
101 | |||
102 | } |
||
103 | |||
104 | void _VI_FUNC SP2155_SetSpeed (int aperm) |
||
105 | { |
||
106 | |||
107 | } |
||
108 | |||
109 | void _VI_FUNC SP2155_Scan (int wavel) |
||
110 | { |
||
111 | |||
112 | } |
||
113 | |||
114 | void _VI_FUNC SP2155_Close (void) |
||
115 | { |
||
116 | CloseCom (SP2155_Port); |
||
117 | } |
||
118 | |||
119 | #ifdef SP2155_MAIN |
||
120 | |||
121 | #include <cvirte.h> |
||
122 | |||
123 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
||
124 | LPSTR lpszCmdLine, int nCmdShow) |
||
125 | { |
||
126 | int ig,iangstrem; |
||
127 | |||
128 | if (InitCVIRTE (hInstance, 0, 0) == 0) return -1; /* out of memory */ |
||
129 | |||
130 | SP2155_Open (7); |
||
131 | SP2155_Echo (0); |
||
132 | SP2155_SetGrating (1); |
||
133 | ig=SP2155_GetGrating (); |
||
134 | printf("grating=%d\n",ig); |
||
135 | // SP2155_Cmd ("?TURRET",0); |
||
136 | |||
137 | SP2155_Close (); |
||
138 | |||
139 | return 0; |
||
140 | } |
||
141 | |||
142 | #endif |