root / trunk / src / java / org / lidar / api / Laser.java
History | View | Annotate | Download (4.95 KB)
1 |
package org.lidar.api; |
---|---|
2 |
|
3 |
import javax.comm.SerialPort; |
4 |
import javax.jws.WebMethod; |
5 |
import javax.jws.WebService; |
6 |
import org.apache.commons.configuration.XMLConfiguration; |
7 |
import org.lidar.Config; |
8 |
import org.lidar.Serial; |
9 |
|
10 |
/**
|
11 |
* Laser API
|
12 |
* @author Andrej Cimpersek
|
13 |
*/
|
14 |
@WebService()
|
15 |
public class Laser extends Serial { |
16 |
|
17 |
public Laser() {
|
18 |
super("laser"); |
19 |
openPort(); |
20 |
} |
21 |
|
22 |
/**
|
23 |
* Vkljuci laser, ki zacne delovati v skladu z nastavljenimi parametri.
|
24 |
*/
|
25 |
@WebMethod()
|
26 |
public boolean fire(String lockToken) { |
27 |
return sendCommand(lockToken, "$FIRE 01\r"); |
28 |
} |
29 |
|
30 |
/**
|
31 |
* Izkljuci laser.
|
32 |
*/
|
33 |
@WebMethod()
|
34 |
public boolean stop(String lockToken) { |
35 |
return sendCommand(lockToken, "$STOP 00\r"); |
36 |
} |
37 |
|
38 |
/**
|
39 |
* Shrani trenutno konfiguracijo parametrov v interni pomnilnik laserja, ki se bodo nalozili ob naslednjem zagonu napajanja.
|
40 |
*/
|
41 |
@WebMethod()
|
42 |
public boolean saveConfig(String lockToken) { |
43 |
return sendCommand(lockToken, "$SAVE 01\r"); |
44 |
} |
45 |
|
46 |
/**
|
47 |
* Mnozica vseh nacinov delovanja laserja.
|
48 |
*/
|
49 |
public enum LaserMode { |
50 |
|
51 |
Continuous, Burst, ExternalTrigger |
52 |
}; |
53 |
|
54 |
/**
|
55 |
* Izbere nacin delovanja laserja. Nacini mode so nasteti v mnozici LaserMode.
|
56 |
* @param mode Nacin delovanja laserja.
|
57 |
*/
|
58 |
@WebMethod()
|
59 |
public boolean setMode(String lockToken, LaserMode mode) { |
60 |
switch (mode) {
|
61 |
case Continuous:
|
62 |
return sendCommand(lockToken, "$MODE 01\r"); |
63 |
case Burst:
|
64 |
return sendCommand(lockToken, "$MODE 02\r"); |
65 |
case ExternalTrigger:
|
66 |
return sendCommand(lockToken, "$MODE 03\r"); |
67 |
} |
68 |
|
69 |
return false; |
70 |
} |
71 |
|
72 |
/**
|
73 |
* Omogoci oz. onemogoci Q-Switch opcijo.
|
74 |
* @param enabled Omogoci oz. onemogoci..
|
75 |
*/
|
76 |
@WebMethod()
|
77 |
public boolean setQSwitch(String lockToken, boolean enabled) { |
78 |
if (enabled) {
|
79 |
return sendCommand(lockToken, "$QSWITCH 01\r"); |
80 |
} else {
|
81 |
return sendCommand(lockToken, "$QSWITCH 00\r"); |
82 |
} |
83 |
} |
84 |
|
85 |
/**
|
86 |
* Zaklene oz. odklene tipkovnico na napajalniku laserja.
|
87 |
* @param locked Zaklep oz. odklep.
|
88 |
*/
|
89 |
@WebMethod()
|
90 |
public boolean setKeypad(String lockToken, boolean enabled) { |
91 |
if (enabled) {
|
92 |
return sendCommand(lockToken, "$KEYPAD 01\r"); |
93 |
} else {
|
94 |
return sendCommand(lockToken, "$KEYPAD 00\r"); |
95 |
} |
96 |
} |
97 |
|
98 |
/**
|
99 |
* Nastavi stevilo sunkov laserja, pulses, ki se bodo zaporedoma izbvrsili, ce je izbran nacin delovanje LaserMode.Continuous.
|
100 |
* Dovoljeno obmocje 0 - 99.
|
101 |
* @param pulses Stevilo sunkov laserja.
|
102 |
*/
|
103 |
@WebMethod()
|
104 |
public boolean setBurstPulseCount(String lockToken, byte pulses) { |
105 |
if (pulses < 0 && pulses > 99) { |
106 |
return false; |
107 |
} |
108 |
|
109 |
String p = "" + pulses; |
110 |
if (p.length() == 1) { |
111 |
p = "0" + p;
|
112 |
} |
113 |
|
114 |
return sendCommand(lockToken, "$BURST " + p + "\r"); |
115 |
} |
116 |
|
117 |
/**
|
118 |
* Zazene Q-Switch na vsakih freq sunkov.
|
119 |
* Dovoljeno obmocje je od 1 - 99.
|
120 |
* @param freq Frekvenca sunkov.
|
121 |
*/
|
122 |
@WebMethod()
|
123 |
public boolean setQSwitchFrequency(String lockToken, byte freq) { |
124 |
if (freq < 0 && freq > 99) { |
125 |
return false; |
126 |
} |
127 |
|
128 |
String f = "" + freq; |
129 |
if (f.length() == 1) { |
130 |
f = "0" + f;
|
131 |
} |
132 |
|
133 |
return sendCommand(lockToken, "$QFREQ " + f + "\r"); |
134 |
} |
135 |
|
136 |
/**
|
137 |
* Zakasnitev aktivacije v stevilu sunkov delay.
|
138 |
* Dovoljeno obmocje je od 0 - 99.
|
139 |
* @param delay Zakasnitev aktivacije.
|
140 |
*/
|
141 |
public boolean setQSwitchDelay(String lockToken, byte delay) { |
142 |
if (delay < 0 && delay > 99) { |
143 |
return false; |
144 |
} |
145 |
|
146 |
String d = "" + delay; |
147 |
if (d.length() == 1) { |
148 |
d = "0" + d;
|
149 |
} |
150 |
|
151 |
return sendCommand(lockToken, "$QDLY " + d + "\r"); |
152 |
} |
153 |
|
154 |
/**
|
155 |
* Nastavi energijo laserja, eneryLevel, pri posameznem sunku aktivcaije.
|
156 |
* @param energyLevel Energija laserja.
|
157 |
*/
|
158 |
@WebMethod()
|
159 |
public boolean setEnergyLevel(String lockToken, byte energyLevel) { |
160 |
if (energyLevel < 1 && energyLevel > 20) { |
161 |
return false; |
162 |
} |
163 |
|
164 |
String e = "" + energyLevel; |
165 |
if (e.length() == 1) { |
166 |
e = "0" + e;
|
167 |
} |
168 |
|
169 |
return sendCommand(lockToken, "$EPFN " + e + "\r"); |
170 |
} |
171 |
|
172 |
/**
|
173 |
* Nastavi frekvenco, s katero naj se prozi lase po aktivaciji. Frekvenca je izrazena v sunkih na sekundo, rate.
|
174 |
* Dovoljene vrednosti so 1, 2, 5, 10 in 20.
|
175 |
* @param rate Frekvenca s katero se prozi laser.
|
176 |
*/
|
177 |
@WebMethod()
|
178 |
public boolean setRepetitionRate(String lockToken, byte rate) { |
179 |
if (rate == 1 || rate == 2 || rate == 5 || rate == 10 || rate == 20) { |
180 |
String r = "" + rate; |
181 |
if (r.length() == 1) { |
182 |
r = "0" + r;
|
183 |
} |
184 |
|
185 |
return sendCommand(lockToken, "$LPRF " + r + "\r"); |
186 |
} |
187 |
|
188 |
return false; |
189 |
} |
190 |
} |