root / trunk / src / java / org / lidar / api / Laser.java
History | View | Annotate | Download (4.95 KB)
1 | 9 | andrej.cim | 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 | 11 | andrej.cim | |
17 | public Laser() {
|
||
18 | 9 | andrej.cim | super("laser"); |
19 | openPort(); |
||
20 | } |
||
21 | |||
22 | /**
|
||
23 | * Vkljuci laser, ki zacne delovati v skladu z nastavljenimi parametri.
|
||
24 | */
|
||
25 | @WebMethod()
|
||
26 | 11 | andrej.cim | public boolean fire(String lockToken) { |
27 | 9 | andrej.cim | return sendCommand(lockToken, "$FIRE 01\r"); |
28 | } |
||
29 | |||
30 | /**
|
||
31 | * Izkljuci laser.
|
||
32 | */
|
||
33 | @WebMethod()
|
||
34 | 11 | andrej.cim | public boolean stop(String lockToken) { |
35 | 9 | andrej.cim | return sendCommand(lockToken, "$STOP 00\r"); |
36 | 11 | andrej.cim | } |
37 | 9 | andrej.cim | |
38 | /**
|
||
39 | * Shrani trenutno konfiguracijo parametrov v interni pomnilnik laserja, ki se bodo nalozili ob naslednjem zagonu napajanja.
|
||
40 | */
|
||
41 | @WebMethod()
|
||
42 | 11 | andrej.cim | public boolean saveConfig(String lockToken) { |
43 | 9 | andrej.cim | return sendCommand(lockToken, "$SAVE 01\r"); |
44 | 11 | andrej.cim | } |
45 | 9 | andrej.cim | |
46 | /**
|
||
47 | * Mnozica vseh nacinov delovanja laserja.
|
||
48 | */
|
||
49 | 11 | andrej.cim | public enum LaserMode { |
50 | 9 | andrej.cim | |
51 | 11 | andrej.cim | Continuous, Burst, ExternalTrigger |
52 | }; |
||
53 | |||
54 | 9 | andrej.cim | /**
|
55 | * Izbere nacin delovanja laserja. Nacini mode so nasteti v mnozici LaserMode.
|
||
56 | * @param mode Nacin delovanja laserja.
|
||
57 | */
|
||
58 | @WebMethod()
|
||
59 | 11 | andrej.cim | public boolean setMode(String lockToken, LaserMode mode) { |
60 | switch (mode) {
|
||
61 | 9 | andrej.cim | 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 | 11 | andrej.cim | } |
71 | 9 | andrej.cim | |
72 | /**
|
||
73 | * Omogoci oz. onemogoci Q-Switch opcijo.
|
||
74 | * @param enabled Omogoci oz. onemogoci..
|
||
75 | */
|
||
76 | @WebMethod()
|
||
77 | 11 | andrej.cim | public boolean setQSwitch(String lockToken, boolean enabled) { |
78 | if (enabled) {
|
||
79 | 9 | andrej.cim | return sendCommand(lockToken, "$QSWITCH 01\r"); |
80 | } else {
|
||
81 | return sendCommand(lockToken, "$QSWITCH 00\r"); |
||
82 | } |
||
83 | 11 | andrej.cim | } |
84 | 9 | andrej.cim | |
85 | /**
|
||
86 | * Zaklene oz. odklene tipkovnico na napajalniku laserja.
|
||
87 | * @param locked Zaklep oz. odklep.
|
||
88 | */
|
||
89 | @WebMethod()
|
||
90 | 11 | andrej.cim | public boolean setKeypad(String lockToken, boolean enabled) { |
91 | if (enabled) {
|
||
92 | 9 | andrej.cim | return sendCommand(lockToken, "$KEYPAD 01\r"); |
93 | } else {
|
||
94 | return sendCommand(lockToken, "$KEYPAD 00\r"); |
||
95 | } |
||
96 | 11 | andrej.cim | } |
97 | 9 | andrej.cim | |
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 | 11 | andrej.cim | public boolean setBurstPulseCount(String lockToken, byte pulses) { |
105 | if (pulses < 0 && pulses > 99) { |
||
106 | 9 | andrej.cim | return false; |
107 | } |
||
108 | |||
109 | String p = "" + pulses; |
||
110 | 11 | andrej.cim | if (p.length() == 1) { |
111 | p = "0" + p;
|
||
112 | } |
||
113 | 9 | andrej.cim | |
114 | return sendCommand(lockToken, "$BURST " + p + "\r"); |
||
115 | 11 | andrej.cim | } |
116 | 9 | andrej.cim | |
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 | 11 | andrej.cim | public boolean setQSwitchFrequency(String lockToken, byte freq) { |
124 | if (freq < 0 && freq > 99) { |
||
125 | 9 | andrej.cim | return false; |
126 | } |
||
127 | |||
128 | String f = "" + freq; |
||
129 | 11 | andrej.cim | if (f.length() == 1) { |
130 | f = "0" + f;
|
||
131 | } |
||
132 | 9 | andrej.cim | |
133 | return sendCommand(lockToken, "$QFREQ " + f + "\r"); |
||
134 | 11 | andrej.cim | } |
135 | 9 | andrej.cim | |
136 | /**
|
||
137 | * Zakasnitev aktivacije v stevilu sunkov delay.
|
||
138 | * Dovoljeno obmocje je od 0 - 99.
|
||
139 | * @param delay Zakasnitev aktivacije.
|
||
140 | */
|
||
141 | 11 | andrej.cim | public boolean setQSwitchDelay(String lockToken, byte delay) { |
142 | if (delay < 0 && delay > 99) { |
||
143 | 9 | andrej.cim | return false; |
144 | } |
||
145 | |||
146 | String d = "" + delay; |
||
147 | 11 | andrej.cim | if (d.length() == 1) { |
148 | d = "0" + d;
|
||
149 | } |
||
150 | 9 | andrej.cim | |
151 | return sendCommand(lockToken, "$QDLY " + d + "\r"); |
||
152 | 11 | andrej.cim | } |
153 | 9 | andrej.cim | |
154 | /**
|
||
155 | * Nastavi energijo laserja, eneryLevel, pri posameznem sunku aktivcaije.
|
||
156 | * @param energyLevel Energija laserja.
|
||
157 | */
|
||
158 | @WebMethod()
|
||
159 | 11 | andrej.cim | public boolean setEnergyLevel(String lockToken, byte energyLevel) { |
160 | if (energyLevel < 1 && energyLevel > 20) { |
||
161 | 9 | andrej.cim | return false; |
162 | } |
||
163 | |||
164 | String e = "" + energyLevel; |
||
165 | 11 | andrej.cim | if (e.length() == 1) { |
166 | e = "0" + e;
|
||
167 | } |
||
168 | |||
169 | 9 | andrej.cim | return sendCommand(lockToken, "$EPFN " + e + "\r"); |
170 | 11 | andrej.cim | } |
171 | 9 | andrej.cim | |
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 | 11 | andrej.cim | public boolean setRepetitionRate(String lockToken, byte rate) { |
179 | if (rate == 1 || rate == 2 || rate == 5 || rate == 10 || rate == 20) { |
||
180 | 9 | andrej.cim | String r = "" + rate; |
181 | 11 | andrej.cim | if (r.length() == 1) { |
182 | r = "0" + r;
|
||
183 | } |
||
184 | 9 | andrej.cim | |
185 | return sendCommand(lockToken, "$LPRF " + r + "\r"); |
||
186 | } |
||
187 | |||
188 | return false; |
||
189 | 11 | andrej.cim | } |
190 | 9 | andrej.cim | } |