6
6
import java .net .Socket ;
7
7
import javax .swing .JFileChooser ;
8
8
9
+
9
10
public class ThreadServer extends Thread
10
11
{
11
12
private int usbPort ;
@@ -20,8 +21,10 @@ public class ThreadServer extends Thread
20
21
private double kpF ;
21
22
private double kiF ;
22
23
private double kdF ;
23
- private int server_answer = 2958 ;
24
+ private int server_answer = 2958 ;
24
25
private int valid_client_request = 45862 ;
26
+ private int openloopSignal = 54378 ;
27
+ private int closedloopSignal = 45876 ;
25
28
private Window gui ;
26
29
private ServerSocket server ;
27
30
private Socket socket ;
@@ -34,8 +37,6 @@ public class ThreadServer extends Thread
34
37
public ThreadServer (Window _gui )
35
38
{
36
39
this .gui = _gui ;
37
- this .usbPort = 16 ;
38
- this .tsT = 0.1 ;
39
40
40
41
// Create server
41
42
System .out .println ("Starting Loggin thread" );
@@ -150,40 +151,99 @@ public void terminate()
150
151
public void run ()
151
152
{
152
153
// get user parameters
154
+ int signalSendPidI ;
155
+ int signalSendPidII ;
153
156
this .usbPort = Integer .parseInt (this .gui .txt_port .getText ());
154
157
this .tsT = Double .parseDouble (this .gui .txt_sample_time_I .getText ());
155
158
this .setpointT = Double .parseDouble (this .gui .txt_setpoint_I .getText ());
156
- this .kpT = Double .parseDouble (this .gui .txt_kp_T .getText ());
157
159
this .kiT = Double .parseDouble (this .gui .txt_ki_T .getText ());
158
160
this .kdT = Double .parseDouble (this .gui .txt_kd_T .getText ());
159
161
this .tsF = Double .parseDouble (this .gui .txt_sample_time_II .getText ());
160
162
this .setpointF = Double .parseDouble (this .gui .txt_setpoint_II .getText ());
161
- this .kpF = Double .parseDouble (this .gui .txt_kp_F .getText ());
162
163
this .kiF = Double .parseDouble (this .gui .txt_ki_F .getText ());
163
164
this .kdF = Double .parseDouble (this .gui .txt_kd_F .getText ());
164
165
165
- // Send parámeters usbPort Ts, setpoint, & PID parameters
166
+ // enviar información del puerto usb asociado a la tarjeta de adquisición
166
167
try
167
168
{
168
169
out .writeInt (this .usbPort );
169
- out .writeDouble (this .tsT );
170
- out .writeDouble (this .setpointT );
171
- out .writeDouble (this .kpT );
172
- out .writeDouble (this .kiT );
173
- out .writeDouble (this .kdT );
174
- out .writeDouble (this .tsF );
175
- out .writeDouble (this .setpointF );
176
- out .writeDouble (this .kpF );
177
- out .writeDouble (this .kiF );
178
- out .writeDouble (this .kdF );
179
170
}
180
- catch (IOException e )
171
+ catch (IOException e )
172
+ {
173
+ System .out .println ("No se pudo enviar información del puerto USB asociado" );
174
+ e .printStackTrace ();
175
+ return ;
176
+ }
177
+
178
+ if (this .gui .txt_kp_T .getText ().equals ("openloop" ))
179
+ {
180
+ signalSendPidI = this .openloopSignal ;
181
+ }
182
+ else
183
+ {
184
+ signalSendPidI = this .closedloopSignal ;
185
+ this .kpT = Double .parseDouble (this .gui .txt_kp_T .getText ());
186
+ }
187
+
188
+ if (this .gui .txt_kp_F .getText ().equals ("openloop" ))
189
+ {
190
+ signalSendPidII = this .openloopSignal ;
191
+ }
192
+ else
193
+ {
194
+ signalSendPidII = this .closedloopSignal ;
195
+ this .kpF = Double .parseDouble (this .gui .txt_kp_F .getText ());
196
+ }
197
+
198
+ // Envía la señal openloop o closedloop y los respectivos parámetros para el proceso I
199
+ try
200
+ {
201
+ out .writeInt (signalSendPidI );
202
+ if (signalSendPidI == this .openloopSignal )
203
+ {
204
+ out .writeDouble (this .tsT );
205
+ out .writeDouble (this .setpointT );
206
+ }
207
+ else
208
+ {
209
+ out .writeDouble (this .tsT );
210
+ out .writeDouble (this .setpointT );
211
+ out .writeDouble (this .kpT );
212
+ out .writeDouble (this .kiT );
213
+ out .writeDouble (this .kdT );
214
+ }
215
+ }catch (IOException e )
181
216
{
182
217
System .out .println ("Error al enviar parámetros usbPort, Ts" );
183
218
e .printStackTrace ();
184
219
return ;
185
220
}
186
221
222
+ // Envía la señal openloop o closedloop y los respectivos parámetros para el proceso II
223
+ try
224
+ {
225
+ out .writeInt (signalSendPidII );
226
+ if (signalSendPidII == this .openloopSignal )
227
+ {
228
+ out .writeDouble (this .tsF );
229
+ out .writeDouble (this .setpointF );
230
+ }
231
+ else
232
+ {
233
+ out .writeDouble (this .tsF );
234
+ out .writeDouble (this .setpointF );
235
+ out .writeDouble (this .kpF );
236
+ out .writeDouble (this .kiF );
237
+ out .writeDouble (this .kdF );
238
+ }
239
+ }catch (IOException e )
240
+ {
241
+ System .out .println ("Error al enviar parámetros usbPort, Ts" );
242
+ e .printStackTrace ();
243
+ return ;
244
+ }
245
+
246
+
187
247
// crear un par de hilos por cada controlador
188
248
// Control temperatura
189
249
try
0 commit comments