1 | #include "cxfel.h" |
---|
2 | |
---|
3 | |
---|
4 | #include "heure.h" |
---|
5 | |
---|
6 | #using <mscorlib.dll> |
---|
7 | #using <System.dll> |
---|
8 | #using <System.Windows.Forms.dll> |
---|
9 | #using <System.Drawing.dll>//pour les controles bouton |
---|
10 | |
---|
11 | using namespace System; |
---|
12 | using namespace System::ComponentModel;//contient des classes pour les composants et les contrôles |
---|
13 | using namespace System::Windows::Forms;//contient des classes dédiées à la génération des formulaires |
---|
14 | using namespace System::Drawing;//contient les classes Point et Size du bouton |
---|
15 | |
---|
16 | using namespace System::IO;//contient les classes pour les I/O |
---|
17 | |
---|
18 | using namespace System::Threading; |
---|
19 | |
---|
20 | //using MySql.Data; |
---|
21 | //using MySql::Data::MySqlClient; |
---|
22 | #using <System.Data.dll> |
---|
23 | #using <MySql.Data.dll> |
---|
24 | using namespace System::Data; |
---|
25 | using namespace MySql::Data::MySqlClient; |
---|
26 | |
---|
27 | #undef MessageBox |
---|
28 | |
---|
29 | modbus_t *ctx;//modbus |
---|
30 | |
---|
31 | |
---|
32 | public __gc class ThreadReadModbus |
---|
33 | { |
---|
34 | public: |
---|
35 | // The ThreadProc method is called when the thread starts. |
---|
36 | static void ThreadProc() |
---|
37 | { |
---|
38 | uint8_t tab_rp_bits[MODBUS_SIZE_READ_COILS]; |
---|
39 | Console::WriteLine(S"ThreadProc: read coils..."); |
---|
40 | int rc = modbus_read_bits(ctx, MODBUS_BASEADR_COILS, MODBUS_SIZE_READ_COILS, tab_rp_bits);////JCM : adresse coils=MODBUS_BASEADR_COILS |
---|
41 | if (rc != MODBUS_SIZE_READ_COILS) |
---|
42 | Console::WriteLine(S"ThreadProc: read coils failed..."); |
---|
43 | Thread::Sleep(500); |
---|
44 | |
---|
45 | uint16_t tab_rp_registers_low[MODBUS_SIZE_READ_HOLDINGS_LOW]; |
---|
46 | Console::WriteLine(S"ThreadProc: read holdings..."); |
---|
47 | rc = modbus_read_registers(ctx, MODBUS_BASEADR_LOW_HOLDINGS,//JCM : adresse holding=MODBUS_BASEADR_LOW_HOLDINGS |
---|
48 | MODBUS_SIZE_READ_HOLDINGS_LOW, tab_rp_registers_low); |
---|
49 | if (rc != MODBUS_SIZE_READ_HOLDINGS_LOW) |
---|
50 | Console::WriteLine(S"ThreadProc: read holdings failed..."); |
---|
51 | Thread::Sleep(500); |
---|
52 | |
---|
53 | uint16_t wordPermuted[2]; |
---|
54 | float real = modbus_get_float(tab_rp_registers_low+6);//dP : float32 Normal |
---|
55 | *(wordPermuted+0)= tab_rp_registers_low[6+1];//dP : float32 Reverse |
---|
56 | *(wordPermuted+1)= tab_rp_registers_low[6+0];//dP : float32 Reverse |
---|
57 | float realReversed = modbus_get_float(wordPermuted+0);//dP : float32 Reverse |
---|
58 | |
---|
59 | Console::WriteLine(S"ThreadProc: read float..."); |
---|
60 | // if (real != UT_REAL) |
---|
61 | // Console::WriteLine(S"ThreadProc: read float failed..."); |
---|
62 | printf("real(2006d) = normal=%f reverse=%f\n", |
---|
63 | real, |
---|
64 | //word2float[0]+(word2float[1]<<16) |
---|
65 | //tab_rp_registers_low[6]+(tab_rp_registers_low[7]<<16)); |
---|
66 | realReversed); |
---|
67 | Thread::Sleep(500); |
---|
68 | |
---|
69 | uint16_t tab_rp_registers_high[MODBUS_SIZE_READ_HOLDINGS_HIGH]; |
---|
70 | Console::WriteLine(S"ThreadProc: read holdings..."); |
---|
71 | rc = modbus_read_registers(ctx, MODBUS_BASEADR_HIGH_HOLDINGS, |
---|
72 | MODBUS_SIZE_READ_HOLDINGS_HIGH, tab_rp_registers_high); |
---|
73 | if (rc != MODBUS_SIZE_READ_HOLDINGS_HIGH) |
---|
74 | Console::WriteLine(S"ThreadProc: read holdings failed..."); |
---|
75 | Thread::Sleep(500); |
---|
76 | |
---|
77 | real = modbus_get_float(tab_rp_registers_high+36);//Pi_max |
---|
78 | Console::WriteLine(S"ThreadProc: read float..."); |
---|
79 | // if (real != UT_REAL) |
---|
80 | // Console::WriteLine(S"ThreadProc: read float failed..."); |
---|
81 | printf("real(2118d) = %f\n", real); |
---|
82 | Thread::Sleep(500); |
---|
83 | } |
---|
84 | }; |
---|
85 | |
---|
86 | |
---|
87 | CGroupBox::CGroupBox(String* gname, int posX, int posY) |
---|
88 | { |
---|
89 | name=gname; |
---|
90 | nbInstance++; |
---|
91 | |
---|
92 | // Creation |
---|
93 | gbox = new GroupBox(); |
---|
94 | gbox->Text = name; |
---|
95 | gbox->Size = System::Drawing::Size(200, 200);//taille du groupbox en pixels |
---|
96 | gbox->Location = Point(posX,posY); |
---|
97 | |
---|
98 | // Num_P label tt seul |
---|
99 | Label* labNumP= new Label(); |
---|
100 | // labNumP->Location = Point(posX+10,posY+5); |
---|
101 | labNumP->Location = Point(70,35); |
---|
102 | labNumP->Size = System::Drawing::Size(50,16); |
---|
103 | labNumP->Text = "Num_P";//zone de texte initialisée |
---|
104 | labNumP->Font = new System::Drawing::Font(S"Arial", 9, FontStyle::Bold);; |
---|
105 | labNumP->TextAlign = ContentAlignment::MiddleRight; |
---|
106 | valNumP= new TextBox(); |
---|
107 | valNumP->Location = Point(70,55); |
---|
108 | valNumP->Size = System::Drawing::Size(60, 40); |
---|
109 | valNumP->Text = "xx";//zone de texte initialisée vide |
---|
110 | valNumP->Font = new System::Drawing::Font(S"Arial", 9, FontStyle::Bold); |
---|
111 | valNumP->ForeColor = Color::Brown; |
---|
112 | gbox->Controls->Add(labNumP); |
---|
113 | gbox->Controls->Add(valNumP); |
---|
114 | // Num_C1 label tt seul |
---|
115 | Label* labNumC1= new Label(); |
---|
116 | // labNumC1->Location = Point(posX+5, posY+20); |
---|
117 | labNumC1->Location = Point(20, 90); |
---|
118 | labNumC1->Size = System::Drawing::Size(50,16); |
---|
119 | labNumC1->Text = "1";//zone de texte initialisée |
---|
120 | labNumC1->Font = new System::Drawing::Font(S"Arial", 9, FontStyle::Bold);; |
---|
121 | labNumC1->TextAlign = ContentAlignment::MiddleRight; |
---|
122 | valNumC1= new TextBox(); |
---|
123 | valNumC1->Location = Point(30,110); |
---|
124 | valNumC1->Size = System::Drawing::Size(60, 40); |
---|
125 | valNumC1->Text = "xx";//zone de texte initialisée vide |
---|
126 | valNumC1->Font = new System::Drawing::Font(S"Arial", 9, FontStyle::Bold);; |
---|
127 | valNumC1->ForeColor = Color::Brown; |
---|
128 | gbox->Controls->Add(labNumC1); |
---|
129 | gbox->Controls->Add(valNumC1); |
---|
130 | // Num_C2 label tt seul |
---|
131 | Label* labNumC2= new Label(); |
---|
132 | // labNumC2->Location = Point(posX+60, posY+20); |
---|
133 | labNumC2->Location = Point(85, 90); |
---|
134 | labNumC2->Size = System::Drawing::Size(50,16); |
---|
135 | labNumC2->Text = "2";//zone de texte initialisée |
---|
136 | labNumC2->Font = new System::Drawing::Font(S"Arial", 9, FontStyle::Bold);; |
---|
137 | labNumC2->TextAlign = ContentAlignment::MiddleRight; |
---|
138 | valNumC2= new TextBox(); |
---|
139 | valNumC2->Location = Point(105,110); |
---|
140 | valNumC2->Size = System::Drawing::Size(60, 40); |
---|
141 | valNumC2->Text = "xx";//zone de texte initialisée vide |
---|
142 | valNumC2->Font = new System::Drawing::Font(S"Arial", 9, FontStyle::Bold);; |
---|
143 | valNumC2->ForeColor = Color::Brown; |
---|
144 | gbox->Controls->Add(labNumC2); |
---|
145 | gbox->Controls->Add(valNumC2); |
---|
146 | //bouton Appliquer |
---|
147 | appliquerBtn = new Button(); |
---|
148 | appliquerBtn->Location = Point(65, 170); |
---|
149 | appliquerBtn->Name = "Bouton Appliquer"; |
---|
150 | appliquerBtn->Text = "Appliquer"; |
---|
151 | appliquerBtn->Click += new EventHandler(this, &CGroupBox::AppliquerBtn_Clicked); |
---|
152 | gbox->Controls->Add(appliquerBtn); |
---|
153 | |
---|
154 | /* |
---|
155 | String* str; |
---|
156 | str=String::Concat(labNumC1->Text); |
---|
157 | Console::WriteLine(str); |
---|
158 | str=String::Concat(labNumC2->Text); |
---|
159 | Console::WriteLine(str); |
---|
160 | */ |
---|
161 | //.............. |
---|
162 | //.............. |
---|
163 | |
---|
164 | } |
---|
165 | |
---|
166 | Label* CGroupBox::GetLabelNumP() |
---|
167 | { |
---|
168 | return labNumP; |
---|
169 | } |
---|
170 | |
---|
171 | Label* CGroupBox::GetLabelNumC1() |
---|
172 | { |
---|
173 | return labNumC1; |
---|
174 | } |
---|
175 | |
---|
176 | Label* CGroupBox::GetLabelNumC2() |
---|
177 | { |
---|
178 | return labNumC2; |
---|
179 | } |
---|
180 | |
---|
181 | GroupBox* CGroupBox::GetGroupBox() |
---|
182 | { |
---|
183 | return gbox; |
---|
184 | } |
---|
185 | |
---|
186 | void CGroupBox::SetValNumP(String* value) |
---|
187 | { |
---|
188 | valNumP->Text=value; |
---|
189 | } |
---|
190 | |
---|
191 | void CGroupBox::SetValNumC1(String* value) |
---|
192 | { |
---|
193 | valNumC1->Text=value; |
---|
194 | } |
---|
195 | |
---|
196 | void CGroupBox::SetValNumC2(String* value) |
---|
197 | { |
---|
198 | valNumC2->Text=value; |
---|
199 | } |
---|
200 | |
---|
201 | String* CGroupBox::GetValNumP() |
---|
202 | { |
---|
203 | return valNumP->Text; |
---|
204 | } |
---|
205 | |
---|
206 | String* CGroupBox::GetValNumC1() |
---|
207 | { |
---|
208 | return valNumC1->Text; |
---|
209 | } |
---|
210 | |
---|
211 | String* CGroupBox::GetValNumC2() |
---|
212 | { |
---|
213 | return valNumC2->Text; |
---|
214 | } |
---|
215 | |
---|
216 | void CGroupBox::AppliquerBtn_Clicked(Object* pSender, EventArgs* pArgs)//gestionnaire d'evenements associés au bouton Appliquer |
---|
217 | { |
---|
218 | String* str; |
---|
219 | //lecture fichier pour comparaison avec saisie |
---|
220 | try |
---|
221 | { |
---|
222 | // FileStream* fs = new FileStream("..\\test1_4xsuc.txt",FileMode::Open); |
---|
223 | FileStream* fs = new FileStream("..\\couplers.txt",FileMode::Open); |
---|
224 | StreamReader* sr = new StreamReader(fs); |
---|
225 | int count=0; |
---|
226 | |
---|
227 | if(!String::Compare(name,"a")) |
---|
228 | { |
---|
229 | Console::WriteLine(S"appliquer a"); |
---|
230 | for (;;) |
---|
231 | { |
---|
232 | String* line = sr->ReadLine(); |
---|
233 | // if (count==0) |
---|
234 | if (count==1)//commentaire en 1ere ligne du fichier généré par xfile |
---|
235 | if(String::Compare(line,valNumP->Text)) |
---|
236 | { |
---|
237 | MessageBox::Show(S"a: NumP n'existe pas !!"); |
---|
238 | sr->Close(); |
---|
239 | break; |
---|
240 | } |
---|
241 | // if (count==1) |
---|
242 | if (count==2)//commentaire en 1ere ligne du fichier généré par xfile |
---|
243 | if(String::Compare(line,valNumC1->Text)) |
---|
244 | { |
---|
245 | MessageBox::Show(S"a: NumC1 n'existe pas !!"); |
---|
246 | sr->Close(); |
---|
247 | break; |
---|
248 | } |
---|
249 | // if (count==2) |
---|
250 | if (count==3)//commentaire en 1ere ligne du fichier généré par xfile |
---|
251 | if(String::Compare(line,valNumC2->Text)) |
---|
252 | { |
---|
253 | MessageBox::Show(S"a: NumC2 n'existe pas !!"); |
---|
254 | sr->Close(); |
---|
255 | break; |
---|
256 | } |
---|
257 | count++; |
---|
258 | if (line==0)//fin du fichier |
---|
259 | { |
---|
260 | sr->Close(); |
---|
261 | uint16_t tab_rp_registers[2]; |
---|
262 | int rc; |
---|
263 | int size; |
---|
264 | Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write NumP NumC1 et NumC2..."); |
---|
265 | size=1; |
---|
266 | tab_rp_registers[0] = Convert::ToInt16(valNumP->Text); |
---|
267 | rc=modbus_write_registers(ctx, 2070,size, tab_rp_registers);//NumP |
---|
268 | if (rc != size) |
---|
269 | Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding failed..."); |
---|
270 | // Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding..."); |
---|
271 | size=2; |
---|
272 | tab_rp_registers[0] = Convert::ToInt16(valNumC1->Text); |
---|
273 | tab_rp_registers[1] = Convert::ToInt16(valNumC2->Text); |
---|
274 | rc=modbus_write_registers(ctx, 2050,size, tab_rp_registers);//NumC1 et NumC2 |
---|
275 | if (rc != size) |
---|
276 | Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding failed..."); |
---|
277 | break; |
---|
278 | } |
---|
279 | } |
---|
280 | } |
---|
281 | if(!String::Compare(name,"b")) |
---|
282 | { |
---|
283 | Console::WriteLine(S"appliquer b"); |
---|
284 | for (;;) |
---|
285 | { |
---|
286 | String* line = sr->ReadLine(); |
---|
287 | // if (count==3) |
---|
288 | if (count==4)//commentaire en 1ere ligne du fichier généré par xfile |
---|
289 | if(String::Compare(line,valNumP->Text)) |
---|
290 | { |
---|
291 | MessageBox::Show(S"b: NumP n'existe pas !!"); |
---|
292 | sr->Close(); |
---|
293 | break; |
---|
294 | } |
---|
295 | // if (count==4) |
---|
296 | if (count==5)//commentaire en 1ere ligne du fichier généré par xfile |
---|
297 | if(String::Compare(line,valNumC1->Text)) |
---|
298 | { |
---|
299 | MessageBox::Show(S"b: NumC1 n'existe pas !!"); |
---|
300 | sr->Close(); |
---|
301 | break; |
---|
302 | } |
---|
303 | // if (count==5) |
---|
304 | if (count==6)//commentaire en 1ere ligne du fichier généré par xfile |
---|
305 | if(String::Compare(line,valNumC2->Text)) |
---|
306 | { |
---|
307 | MessageBox::Show(S"b: NumC2 n'existe pas !!"); |
---|
308 | sr->Close(); |
---|
309 | break; |
---|
310 | } |
---|
311 | count++; |
---|
312 | if (line==0)//fin du fichier |
---|
313 | { |
---|
314 | sr->Close(); |
---|
315 | uint16_t tab_rp_registers[2]; |
---|
316 | int rc; |
---|
317 | int size; |
---|
318 | Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write NumP NumC1 et NumC2..."); |
---|
319 | size=1; |
---|
320 | tab_rp_registers[0] = Convert::ToInt16(valNumP->Text); |
---|
321 | rc=modbus_write_registers(ctx, 2071,size, tab_rp_registers);//NumP |
---|
322 | if (rc != size) |
---|
323 | Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding failed..."); |
---|
324 | // Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding..."); |
---|
325 | size=2; |
---|
326 | tab_rp_registers[0] = Convert::ToInt16(valNumC1->Text); |
---|
327 | tab_rp_registers[1] = Convert::ToInt16(valNumC2->Text); |
---|
328 | rc=modbus_write_registers(ctx, 2052,size, tab_rp_registers);//NumC1 et NumC2 |
---|
329 | if (rc != size) |
---|
330 | Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding failed..."); |
---|
331 | break; |
---|
332 | } |
---|
333 | } |
---|
334 | } |
---|
335 | if(!String::Compare(name,"c")) |
---|
336 | { |
---|
337 | Console::WriteLine(S"appliquer c"); |
---|
338 | for (;;) |
---|
339 | { |
---|
340 | String* line = sr->ReadLine(); |
---|
341 | // if (count==6) |
---|
342 | if (count==7)//commentaire en 1ere ligne du fichier généré par xfile |
---|
343 | if(String::Compare(line,valNumP->Text)) |
---|
344 | { |
---|
345 | MessageBox::Show(S"c: NumP n'existe pas !!"); |
---|
346 | sr->Close(); |
---|
347 | break; |
---|
348 | } |
---|
349 | // if (count==7) |
---|
350 | if (count==8)//commentaire en 1ere ligne du fichier généré par xfile |
---|
351 | if(String::Compare(line,valNumC1->Text)) |
---|
352 | { |
---|
353 | MessageBox::Show(S"c: NumC1 n'existe pas !!"); |
---|
354 | sr->Close(); |
---|
355 | break; |
---|
356 | } |
---|
357 | // if (count==8) |
---|
358 | if (count==9)//commentaire en 1ere ligne du fichier généré par xfile |
---|
359 | if(String::Compare(line,valNumC2->Text)) |
---|
360 | { |
---|
361 | MessageBox::Show(S"c: NumC2 n'existe pas !!"); |
---|
362 | sr->Close(); |
---|
363 | break; |
---|
364 | } |
---|
365 | count++; |
---|
366 | if (line==0)//fin du fichier |
---|
367 | { |
---|
368 | sr->Close(); |
---|
369 | uint16_t tab_rp_registers[2]; |
---|
370 | int rc; |
---|
371 | int size; |
---|
372 | Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write NumP NumC1 et NumC2..."); |
---|
373 | size=1; |
---|
374 | tab_rp_registers[0] = Convert::ToInt16(valNumP->Text); |
---|
375 | rc=modbus_write_registers(ctx, 2072,size, tab_rp_registers);//NumP |
---|
376 | if (rc != size) |
---|
377 | Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding failed..."); |
---|
378 | // Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding..."); |
---|
379 | size=2; |
---|
380 | tab_rp_registers[0] = Convert::ToInt16(valNumC1->Text); |
---|
381 | tab_rp_registers[1] = Convert::ToInt16(valNumC2->Text); |
---|
382 | rc=modbus_write_registers(ctx, 2054,size, tab_rp_registers);//NumC1 et NumC2 |
---|
383 | if (rc != size) |
---|
384 | Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding failed..."); |
---|
385 | break; |
---|
386 | } |
---|
387 | } |
---|
388 | } |
---|
389 | if(!String::Compare(name,"d")) |
---|
390 | { |
---|
391 | Console::WriteLine(S"appliquer d"); |
---|
392 | for (;;) |
---|
393 | { |
---|
394 | String* line = sr->ReadLine(); |
---|
395 | // if (count==9) |
---|
396 | if (count==10)//commentaire en 1ere ligne du fichier généré par xfile |
---|
397 | if(String::Compare(line,valNumP->Text)) |
---|
398 | { |
---|
399 | MessageBox::Show(S"d: NumP n'existe pas !!"); |
---|
400 | sr->Close(); |
---|
401 | break; |
---|
402 | } |
---|
403 | // if (count==10) |
---|
404 | if (count==11)//commentaire en 1ere ligne du fichier généré par xfile |
---|
405 | if(String::Compare(line,valNumC1->Text)) |
---|
406 | { |
---|
407 | MessageBox::Show(S"d: NumC1 n'existe pas !!"); |
---|
408 | sr->Close(); |
---|
409 | break; |
---|
410 | } |
---|
411 | // if (count==11) |
---|
412 | if (count==12)//commentaire en 1ere ligne du fichier généré par xfile |
---|
413 | if(String::Compare(line,valNumC2->Text)) |
---|
414 | { |
---|
415 | MessageBox::Show(S"d: NumC2 n'existe pas !!"); |
---|
416 | sr->Close(); |
---|
417 | break; |
---|
418 | } |
---|
419 | count++; |
---|
420 | if (line==0)//fin du fichier |
---|
421 | { |
---|
422 | sr->Close(); |
---|
423 | uint16_t tab_rp_registers[2]; |
---|
424 | int rc; |
---|
425 | int size; |
---|
426 | Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write NumP NumC1 et NumC2..."); |
---|
427 | size=1; |
---|
428 | tab_rp_registers[0] = Convert::ToInt16(valNumP->Text); |
---|
429 | rc=modbus_write_registers(ctx, 2073,size, tab_rp_registers);//NumP |
---|
430 | if (rc != size) |
---|
431 | Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding failed..."); |
---|
432 | // Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding..."); |
---|
433 | size=2; |
---|
434 | tab_rp_registers[0] = Convert::ToInt16(valNumC1->Text); |
---|
435 | tab_rp_registers[1] = Convert::ToInt16(valNumC2->Text); |
---|
436 | rc=modbus_write_registers(ctx, 2056,size, tab_rp_registers);//NumC1 et NumC2 |
---|
437 | if (rc != size) |
---|
438 | Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding failed..."); |
---|
439 | break; |
---|
440 | } |
---|
441 | } |
---|
442 | } |
---|
443 | } |
---|
444 | catch (System::Exception* pe) |
---|
445 | { |
---|
446 | Console::WriteLine(pe->ToString()); |
---|
447 | } |
---|
448 | int count=0; |
---|
449 | |
---|
450 | } |
---|
451 | |
---|
452 | CDialogConfig::CDialogConfig() |
---|
453 | { |
---|
454 | // définit les paramètres du formulaire |
---|
455 | Text = S"XSUC - ecriture serveur"; |
---|
456 | FormBorderStyle = FormBorderStyle::Fixed3D;//impossible de modifier la taille |
---|
457 | Size = System::Drawing::Size(1000,800); |
---|
458 | |
---|
459 | // Creation de controle |
---|
460 | sortirBtn = new Button(); |
---|
461 | |
---|
462 | // bouton OK |
---|
463 | sortirBtn->Location = Point(900, 700); |
---|
464 | sortirBtn->Name = "Bouton Sortir"; |
---|
465 | sortirBtn->Text = "sortir"; |
---|
466 | sortirBtn->DialogResult = DialogResult::OK; |
---|
467 | |
---|
468 | // Ajoute les controles dans le formaulaire |
---|
469 | Controls->Add(sortirBtn); |
---|
470 | |
---|
471 | pal = new ArrayList(); |
---|
472 | int j=20;//depart affichage |
---|
473 | for (indexGroupBox=0;indexGroupBox<NB_BANCS;indexGroupBox++)//creation des controles dans le formulaire |
---|
474 | { |
---|
475 | pal->Add(new CGroupBox(gname[indexGroupBox],j,90)); |
---|
476 | j+=250; |
---|
477 | CGroupBox* gboxPtr = (CGroupBox *) pal->get_Item(indexGroupBox); |
---|
478 | Controls->Add(gboxPtr->GetGroupBox()); |
---|
479 | String* str; |
---|
480 | str=String::Concat(gboxPtr->GetGroupBox()->Text); |
---|
481 | Console::WriteLine(str); |
---|
482 | /* str=String::Concat(gboxPtr->GetLabelNumP()->Text); |
---|
483 | Console::WriteLine(str); |
---|
484 | str=String::Concat(gboxPtr->GetLabelNumC1()->Text); |
---|
485 | Console::WriteLine(str); |
---|
486 | */ } |
---|
487 | |
---|
488 | //configure les 2 propriétés : AcceptButton contient la réf du bouton par défaut du formulaire.. |
---|
489 | //..on peut cliquer sur le bouton OK ou bien sur la touche Entrée du clavier.. |
---|
490 | //..referme aussi la boite car DialogResult renvoie OK |
---|
491 | AcceptButton = sortirBtn; |
---|
492 | |
---|
493 | //Tp_max |
---|
494 | labTp_max = new Label(); |
---|
495 | valTp_max = new TextBox(); |
---|
496 | labN_cur = new Label(); |
---|
497 | valN_cur = new ComboBox(); |
---|
498 | btnAppliquer = new Button(); |
---|
499 | labTp_max->Location = Point(200,600); |
---|
500 | labTp_max->Size = System::Drawing::Size(86,16); |
---|
501 | labTp_max->Text = "Tp_max(min):"; |
---|
502 | labTp_max->TextAlign = ContentAlignment::MiddleRight; |
---|
503 | labTp_max->Font = new System::Drawing::Font(S"Arial", 9, FontStyle::Bold);; |
---|
504 | Controls->Add(labTp_max); |
---|
505 | valTp_max->Location = Point(290,600); |
---|
506 | valTp_max->Size = System::Drawing::Size(50,20); |
---|
507 | valTp_max->Text = ""; |
---|
508 | valTp_max->Font = new System::Drawing::Font(S"Arial", 9, FontStyle::Bold);; |
---|
509 | valTp_max->ForeColor = Color::Blue; |
---|
510 | Controls->Add(valTp_max); |
---|
511 | labN_cur->Location = Point(200,625); |
---|
512 | labN_cur->Size = System::Drawing::Size(80,16); |
---|
513 | labN_cur->Text = "N_cur:"; |
---|
514 | labN_cur->TextAlign = ContentAlignment::MiddleRight; |
---|
515 | labN_cur->Font = new System::Drawing::Font(S"Arial", 9, FontStyle::Bold);; |
---|
516 | Controls->Add(labN_cur); |
---|
517 | valN_cur->DropDownWidth=121; |
---|
518 | valN_cur->Location = Point(290,625); |
---|
519 | valN_cur->Size = System::Drawing::Size(50,121); |
---|
520 | valN_cur->Items->Add(S"1"); |
---|
521 | valN_cur->Items->Add(S"2"); |
---|
522 | valN_cur->Items->Add(S"3"); |
---|
523 | valN_cur->Items->Add(S"4"); |
---|
524 | valN_cur->Items->Add(S"5"); |
---|
525 | valN_cur->Items->Add(S"6"); |
---|
526 | valN_cur->Items->Add(S"7"); |
---|
527 | valN_cur->Font = new System::Drawing::Font(S"Arial", 9, FontStyle::Bold);; |
---|
528 | valN_cur->ForeColor = Color::Blue; |
---|
529 | valN_cur->SelectedIndex = 0;//affiche la 1ere chaine par defaut |
---|
530 | Controls->Add(valN_cur); |
---|
531 | btnAppliquer = new Button(); |
---|
532 | btnAppliquer->Location = Point(350, 600); |
---|
533 | btnAppliquer->Name = "Bouton Appliquer"; |
---|
534 | btnAppliquer->Text = "Appliquer"; |
---|
535 | btnAppliquer->Click += new EventHandler(this, &CDialogConfig::BtnAppliquer_Clicked); |
---|
536 | Controls->Add(btnAppliquer); |
---|
537 | |
---|
538 | // Creation du GroupBox |
---|
539 | gboxAuto = new GroupBox(); |
---|
540 | gboxAuto->Text = S"saisie auto"; |
---|
541 | gboxAuto->Size = System::Drawing::Size(200, 200);//taille du groupbox en pixels |
---|
542 | gboxAuto->Location = Point(600, 400); |
---|
543 | // Creation des boutons radio. |
---|
544 | rbAutoBdd = new RadioButton(); |
---|
545 | rbAutoBdd->Text = S"Base de données"; |
---|
546 | rbAutoBdd->Size = System::Drawing::Size(80,50); |
---|
547 | rbAutoBdd->Font = new System::Drawing::Font(S"Arial", 9, FontStyle::Bold);; |
---|
548 | rbAutoBdd->Location = Point(10,35); |
---|
549 | rbAutoBdd->Checked = true;//c'est la valeur par defaut |
---|
550 | rbAutoFichier = new RadioButton(); |
---|
551 | rbAutoFichier->Text = S"Fichier"; |
---|
552 | rbAutoFichier->Size = System::Drawing::Size(80,50); |
---|
553 | rbAutoFichier->Font = new System::Drawing::Font(S"Arial", 9, FontStyle::Bold);; |
---|
554 | rbAutoFichier->Location = Point(10,75); |
---|
555 | // creation du bouton Appliquer |
---|
556 | BtnAppliquerAuto = new Button(); |
---|
557 | BtnAppliquerAuto->Location = Point(60, 140); |
---|
558 | BtnAppliquerAuto->Name = "Bouton Appliquer"; |
---|
559 | BtnAppliquerAuto->Text = "Appliquer"; |
---|
560 | // ajout des controles dans le groupe |
---|
561 | gboxAuto->Controls->Add(rbAutoBdd); |
---|
562 | gboxAuto->Controls->Add(rbAutoFichier); |
---|
563 | gboxAuto->Controls->Add(BtnAppliquerAuto); |
---|
564 | // ajout du groupe dans le formulaire. |
---|
565 | Controls->Add(gboxAuto); |
---|
566 | // associe le gestionnaire au groupe d'options |
---|
567 | rbAutoBdd->Click += new EventHandler(this, &CDialogConfig::Radio_Clicked); |
---|
568 | rbAutoFichier->Click += new EventHandler(this, &CDialogConfig::Radio_Clicked); |
---|
569 | BtnAppliquerAuto->Click += new EventHandler(this, &CDialogConfig::BtnAppliquerAuto_Clicked); |
---|
570 | |
---|
571 | //N_cur |
---|
572 | labN_cur4Reprise = new Label(); |
---|
573 | valN_cur4Reprise = new TextBox(); |
---|
574 | labN_cur4Reprise->Location = Point(200,500); |
---|
575 | labN_cur4Reprise->Size = System::Drawing::Size(86,16); |
---|
576 | labN_cur4Reprise->Text = "N_cur:"; |
---|
577 | labN_cur4Reprise->TextAlign = ContentAlignment::MiddleRight; |
---|
578 | labN_cur4Reprise->Font = new System::Drawing::Font(S"Arial", 9, FontStyle::Bold);; |
---|
579 | Controls->Add(labN_cur4Reprise); |
---|
580 | valN_cur4Reprise->Location = Point(290,500); |
---|
581 | valN_cur4Reprise->Size = System::Drawing::Size(50,20); |
---|
582 | valN_cur4Reprise->Text = ""; |
---|
583 | valN_cur4Reprise->Font = new System::Drawing::Font(S"Arial", 9, FontStyle::Bold);; |
---|
584 | valN_cur4Reprise->ForeColor = Color::Blue; |
---|
585 | Controls->Add(valN_cur4Reprise); |
---|
586 | btnN_curAppliquer = new Button(); |
---|
587 | btnN_curAppliquer->Location = Point(350, 500); |
---|
588 | btnN_curAppliquer->Name = "Bouton Appliquer"; |
---|
589 | btnN_curAppliquer->Text = "Appliquer"; |
---|
590 | btnN_curAppliquer->Click += new EventHandler(this, &CDialogConfig::btnN_curAppliquer_Clicked); |
---|
591 | Controls->Add(btnN_curAppliquer); |
---|
592 | |
---|
593 | //gestionnnaire associé au bouton OK |
---|
594 | sortirBtn->Click += new EventHandler(this, &CDialogConfig::SortirBtn_Clicked); |
---|
595 | } |
---|
596 | |
---|
597 | CDialogConfig::CDialogConfig(uint16_t *tab_rp_registers_low,uint16_t *tab_rp_registers_high) |
---|
598 | { |
---|
599 | // définit les paramètres du formulaire |
---|
600 | Text = S"XSUC - ecriture serveur"; |
---|
601 | FormBorderStyle = FormBorderStyle::Fixed3D;//impossible de modifier la taille |
---|
602 | Size = System::Drawing::Size(1000,800); |
---|
603 | |
---|
604 | // Creation de controle |
---|
605 | sortirBtn = new Button(); |
---|
606 | |
---|
607 | // bouton OK |
---|
608 | sortirBtn->Location = Point(900, 700); |
---|
609 | sortirBtn->Name = "Bouton Sortir"; |
---|
610 | sortirBtn->Text = "sortir"; |
---|
611 | sortirBtn->DialogResult = DialogResult::OK; |
---|
612 | |
---|
613 | // Ajoute les controles dans le formaulaire |
---|
614 | Controls->Add(sortirBtn); |
---|
615 | |
---|
616 | pal = new ArrayList(); |
---|
617 | int j=20;//depart affichage |
---|
618 | for (indexGroupBox=0;indexGroupBox<NB_BANCS;indexGroupBox++)//creation des controles dans le formulaire |
---|
619 | { |
---|
620 | pal->Add(new CGroupBox(gname[indexGroupBox],j,90)); |
---|
621 | j+=250; |
---|
622 | CGroupBox* gboxPtr = (CGroupBox *) pal->get_Item(indexGroupBox); |
---|
623 | Controls->Add(gboxPtr->GetGroupBox()); |
---|
624 | String* str; |
---|
625 | str=String::Concat(gboxPtr->GetGroupBox()->Text); |
---|
626 | Console::WriteLine(str); |
---|
627 | /* str=String::Concat(gboxPtr->GetLabelNumP()->Text); |
---|
628 | Console::WriteLine(str); |
---|
629 | str=String::Concat(gboxPtr->GetLabelNumC1()->Text); |
---|
630 | Console::WriteLine(str); |
---|
631 | */ } |
---|
632 | |
---|
633 | //configure les 2 propriétés : AcceptButton contient la réf du bouton par défaut du formulaire.. |
---|
634 | //..on peut cliquer sur le bouton OK ou bien sur la touche Entrée du clavier.. |
---|
635 | //..referme aussi la boite car DialogResult renvoie OK |
---|
636 | AcceptButton = sortirBtn; |
---|
637 | |
---|
638 | //gestionnnaire associé au bouton OK |
---|
639 | sortirBtn->Click += new EventHandler(this, &CDialogConfig::SortirBtn_Clicked); |
---|
640 | } |
---|
641 | |
---|
642 | void CDialogConfig::SortirBtn_Clicked(Object* pSender,EventArgs* pArgs)//gestionnaire d'evenement de la boite dialogue |
---|
643 | { |
---|
644 | //fermer le formulaire lorsqu'on clique sur le bouton |
---|
645 | Close(); |
---|
646 | } |
---|
647 | |
---|
648 | void CDialogConfig::BtnAppliquer_Clicked(Object* pSender, EventArgs* pArgs)//gestionnaire d'evenement associé à la liste deroulante |
---|
649 | { |
---|
650 | int nCur=0; |
---|
651 | |
---|
652 | // String* ps = String::Concat(S"index is ",__box(valN_cur->SelectedIndex)->ToString()); |
---|
653 | // MessageBox::Show(ps,S"index"); |
---|
654 | String* ps = __box(valN_cur->SelectedIndex)->ToString(); |
---|
655 | if(String::Compare(ps,"0")==0) |
---|
656 | nCur=1; |
---|
657 | if(String::Compare(ps,"1")==0) |
---|
658 | nCur=2; |
---|
659 | if(String::Compare(ps,"2")==0) |
---|
660 | nCur=3; |
---|
661 | if(String::Compare(ps,"3")==0) |
---|
662 | nCur=4; |
---|
663 | if(String::Compare(ps,"4")==0) |
---|
664 | nCur=5; |
---|
665 | if(String::Compare(ps,"5")==0) |
---|
666 | nCur=6; |
---|
667 | if(String::Compare(ps,"6")==0) |
---|
668 | nCur=7; |
---|
669 | if (getTp_max()!=NULL)//case non vide uniquement |
---|
670 | { |
---|
671 | int result = Convert::ToInt16(getTp_max()); |
---|
672 | if ((result<60)||(result>840))//compris entre 1 heure et 14 heures |
---|
673 | { |
---|
674 | // MessageBox::Show(S"1 heure <= Tp_max <= 14 heures"); |
---|
675 | MessageBox::Show(S"60 minutes <= Tp_max <= 840 minutes"); |
---|
676 | return; |
---|
677 | } |
---|
678 | Console::WriteLine(S"ecriture Tp_max"); |
---|
679 | uint16_t tab_rp_registers[1]; |
---|
680 | int rc; |
---|
681 | int size; |
---|
682 | Console::WriteLine(S"CDialogConfig::BtnAppliquer_Clicked : write Tp_max..."); |
---|
683 | size=1; |
---|
684 | tab_rp_registers[0] = result; |
---|
685 | rc=modbus_write_registers(ctx, 2106+(nCur-1),size, tab_rp_registers);//Tp_max |
---|
686 | if (rc != size) |
---|
687 | Console::WriteLine(S"CDialogConfig::BtnAppliquer_Clicked : write Tp_max failed..."); |
---|
688 | } |
---|
689 | } |
---|
690 | |
---|
691 | void CDialogConfig::btnN_curAppliquer_Clicked(Object* pSender, EventArgs* pArgs)//gestionnaire d'evenement associé à la liste deroulante |
---|
692 | { |
---|
693 | int nCur; |
---|
694 | |
---|
695 | if (getN_cur()!=NULL)//case non vide uniquement |
---|
696 | { |
---|
697 | int result = Convert::ToInt16(getN_cur()); |
---|
698 | if ((result<0)||(result>8))//compris entre 1 et 8 |
---|
699 | { |
---|
700 | MessageBox::Show(S"0 <= N_cur <= 8"); |
---|
701 | return; |
---|
702 | } |
---|
703 | Console::WriteLine(S"ecriture N_cur"); |
---|
704 | uint16_t tab_rp_registers[1]; |
---|
705 | int rc; |
---|
706 | int size; |
---|
707 | Console::WriteLine(S"CDialogConfig::BtnAppliquer_Clicked : write N_cur..."); |
---|
708 | size=1; |
---|
709 | tab_rp_registers[0] = result; |
---|
710 | rc=modbus_write_registers(ctx, 2027, size, tab_rp_registers);//N_cur |
---|
711 | if (rc != size) |
---|
712 | Console::WriteLine(S"CDialogConfig::BtnAppliquer_Clicked : write N_cur failed..."); |
---|
713 | } |
---|
714 | } |
---|
715 | |
---|
716 | String* CDialogConfig::getTp_max() |
---|
717 | { |
---|
718 | return valTp_max->Text; |
---|
719 | } |
---|
720 | |
---|
721 | String* CDialogConfig::getN_cur() |
---|
722 | { |
---|
723 | return valN_cur4Reprise->Text; |
---|
724 | } |
---|
725 | |
---|
726 | void CDialogConfig::BtnAppliquerAuto_Clicked(Object* pSender,EventArgs* pArgs)//gestionnaire d'evenement de la boite dialogue |
---|
727 | { |
---|
728 | |
---|
729 | /*\*/ |
---|
730 | //.... |
---|
731 | //....lire la bd OU le fichier selon le rb |
---|
732 | //....msgbox en cas d'erreur |
---|
733 | //....afficher ds les zones saisies |
---|
734 | //....ecrire sur le modbus ts les perametres |
---|
735 | |
---|
736 | |
---|
737 | if (lectBddFic==true)//lecture bdd selectionnée |
---|
738 | { |
---|
739 | /* |
---|
740 | structure table stand_with_couplers dans la base de données : |
---|
741 | +----------------+--------------------------------------+------+-----+---------+-------+ |
---|
742 | | Field | Type | Null | Key | Default | Extra | |
---|
743 | +----------------+--------------------------------------+------+-----+---------+-------+ |
---|
744 | | idStand | char(1) | NO | | | | |
---|
745 | | idPair | char(11) | YES | | NULL | | |
---|
746 | | idCoupler1 | char(13) | NO | | | | |
---|
747 | | idCoupler2 | char(13) | NO | | | | |
---|
748 | | idConditioning | int(11) | YES | | NULL | | |
---|
749 | | status | enum('to-dryheat','to-conditioning') | YES | | NULL | | |
---|
750 | +----------------+--------------------------------------+------+-----+---------+-------+ |
---|
751 | */ |
---|
752 | // Console::WriteLine(S"CDialogConfig::BtnAppliquerAuto_Clicked : connexion bdd..."); |
---|
753 | |
---|
754 | //lecture fichier qui contient le host et la base |
---|
755 | String* sHost; |
---|
756 | String* sName; |
---|
757 | try |
---|
758 | { |
---|
759 | FileStream* fs = new FileStream("..\\condb.txt",FileMode::Open); |
---|
760 | StreamReader* sr = new StreamReader(fs); |
---|
761 | int count=0; |
---|
762 | for (;;) |
---|
763 | { |
---|
764 | String* line = sr->ReadLine(); |
---|
765 | //commentaire sur les 3éres lignes du fichier |
---|
766 | if (count==3) |
---|
767 | sHost=line; |
---|
768 | if (count==4) |
---|
769 | sName=line; |
---|
770 | count++; |
---|
771 | if (line==0)//fin du fichier |
---|
772 | { |
---|
773 | sr->Close(); |
---|
774 | String* stra[] = {S"Host=",sHost,S" Name=",sName}; |
---|
775 | String* str=String::Concat(stra); |
---|
776 | Console::WriteLine(str); |
---|
777 | break; |
---|
778 | } |
---|
779 | } |
---|
780 | } |
---|
781 | catch (System::Exception* pe) |
---|
782 | { |
---|
783 | Console::WriteLine(pe->ToString()); |
---|
784 | } |
---|
785 | |
---|
786 | // String* connStr = "server=lalsrv1.lal.in2p3.fr;User Id=xfel;Database=xfel_tst;port=3306;Password=pwd4xfel;"; |
---|
787 | String* str[] = {S"server=",sHost,S";User Id=xfel;Database=",sName,S";port=3306;Password=pwd4xfel;"}; |
---|
788 | String* connStr=String::Concat(str); |
---|
789 | MySqlConnection* conn = new MySqlConnection(connStr); |
---|
790 | try |
---|
791 | { |
---|
792 | conn->Open(); |
---|
793 | } |
---|
794 | catch (System::Exception* pe) |
---|
795 | { |
---|
796 | MessageBox::Show(pe->ToString()); |
---|
797 | // Console::WriteLine(pe->ToString()); |
---|
798 | } |
---|
799 | |
---|
800 | // String* sql = "select idstand,idpair, idcoupler1,idcoupler2 from stand_with_couplers where status='to-conditioning'"; |
---|
801 | String* sql = "select idstand,idpair, idcoupler1,idcoupler2,status from stand_with_couplers where status='to-conditioning' order by idStand"; |
---|
802 | MySqlCommand* cmd = new MySqlCommand(sql, conn); |
---|
803 | |
---|
804 | MySqlDataReader* myReader; |
---|
805 | myReader = cmd->ExecuteReader(); |
---|
806 | try |
---|
807 | { |
---|
808 | uint16_t tabNumP[4]={0,0,0,0}; |
---|
809 | uint16_t tabNumC1C2[8]={0,0,0,0,0,0,0,0}; |
---|
810 | int rc; |
---|
811 | int size; |
---|
812 | |
---|
813 | while(myReader->Read()) |
---|
814 | { |
---|
815 | String* str; |
---|
816 | if(!String::Compare(myReader->GetString(0),"a"))//banc a |
---|
817 | { |
---|
818 | Console::WriteLine(myReader->GetString(1)); |
---|
819 | CGroupBox* gboxPtr = (CGroupBox*)pal->get_Item(0); |
---|
820 | str = (myReader->GetString(1))->Remove(0,8); |
---|
821 | gboxPtr->SetValNumP(str); |
---|
822 | tabNumP[0] = Convert::ToInt16(str); |
---|
823 | str = (myReader->GetString(2))->Remove(0,8); |
---|
824 | gboxPtr->SetValNumC1(str); |
---|
825 | tabNumC1C2[0] = Convert::ToInt16(str); |
---|
826 | str = (myReader->GetString(3))->Remove(0,8); |
---|
827 | gboxPtr->SetValNumC2(str); |
---|
828 | tabNumC1C2[1] = Convert::ToInt16(str); |
---|
829 | } |
---|
830 | if(!String::Compare(myReader->GetString(0),"b"))//banc b |
---|
831 | { |
---|
832 | Console::WriteLine(myReader->GetString(1)); |
---|
833 | CGroupBox* gboxPtr = (CGroupBox*)pal->get_Item(1); |
---|
834 | str = (myReader->GetString(1))->Remove(0,8); |
---|
835 | gboxPtr->SetValNumP(str); |
---|
836 | tabNumP[1] = Convert::ToInt16(str); |
---|
837 | str = (myReader->GetString(2))->Remove(0,8); |
---|
838 | gboxPtr->SetValNumC1(str); |
---|
839 | tabNumC1C2[2] = Convert::ToInt16(str); |
---|
840 | str = (myReader->GetString(3))->Remove(0,8); |
---|
841 | gboxPtr->SetValNumC2(str); |
---|
842 | tabNumC1C2[3] = Convert::ToInt16(str); |
---|
843 | } |
---|
844 | if(!String::Compare(myReader->GetString(0),"c"))//banc c |
---|
845 | { |
---|
846 | Console::WriteLine(myReader->GetString(1)); |
---|
847 | CGroupBox* gboxPtr = (CGroupBox*)pal->get_Item(2); |
---|
848 | str = (myReader->GetString(1))->Remove(0,8); |
---|
849 | gboxPtr->SetValNumP(str); |
---|
850 | tabNumP[2] = Convert::ToInt16(str); |
---|
851 | str = (myReader->GetString(2))->Remove(0,8); |
---|
852 | gboxPtr->SetValNumC1(str); |
---|
853 | tabNumC1C2[4] = Convert::ToInt16(str); |
---|
854 | str = (myReader->GetString(3))->Remove(0,8); |
---|
855 | gboxPtr->SetValNumC2(str); |
---|
856 | tabNumC1C2[5] = Convert::ToInt16(str); |
---|
857 | } |
---|
858 | if(!String::Compare(myReader->GetString(0),"d"))//banc d |
---|
859 | { |
---|
860 | Console::WriteLine(myReader->GetString(1)); |
---|
861 | CGroupBox* gboxPtr = (CGroupBox*)pal->get_Item(3); |
---|
862 | str = (myReader->GetString(1))->Remove(0,8); |
---|
863 | gboxPtr->SetValNumP(str); |
---|
864 | tabNumP[3] = Convert::ToInt16(str); |
---|
865 | str = (myReader->GetString(2))->Remove(0,8); |
---|
866 | gboxPtr->SetValNumC1(str); |
---|
867 | tabNumC1C2[6] = Convert::ToInt16(str); |
---|
868 | str = (myReader->GetString(3))->Remove(0,8); |
---|
869 | gboxPtr->SetValNumC2(str); |
---|
870 | tabNumC1C2[7] = Convert::ToInt16(str); |
---|
871 | } |
---|
872 | }//while |
---|
873 | //fin du fichier : on ecrit sur le modbus |
---|
874 | Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write NumP NumC1 et NumC2..."); |
---|
875 | size=4; |
---|
876 | rc=modbus_write_registers(ctx, 2070,size, tabNumP);//NumP |
---|
877 | if (rc != size) |
---|
878 | Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding failed..."); |
---|
879 | size=8; |
---|
880 | rc=modbus_write_registers(ctx, 2050,size, tabNumC1C2);//NumC1 et NumC2 |
---|
881 | if (rc != size) |
---|
882 | Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding failed..."); |
---|
883 | } |
---|
884 | catch (System::Exception* pe) |
---|
885 | { |
---|
886 | Console::WriteLine(pe->ToString()); |
---|
887 | } |
---|
888 | myReader->Close(); |
---|
889 | conn->Close(); |
---|
890 | }//fin lectBddFic true |
---|
891 | else//lecture fichier selectionnée |
---|
892 | { |
---|
893 | /* |
---|
894 | format fichier couplers.txt (13 lignes) : |
---|
895 | #id conditionnement |
---|
896 | NumP banc a |
---|
897 | NumC1 banc a |
---|
898 | NumC2 banc a |
---|
899 | NumP banc b |
---|
900 | NumC1 banc b |
---|
901 | NumC2 banc b |
---|
902 | NumP banc c |
---|
903 | NumC1 banc c |
---|
904 | NumC2 banc c |
---|
905 | NumP banc d |
---|
906 | NumC1 banc d |
---|
907 | NumC2 banc d |
---|
908 | */ |
---|
909 | String* str; |
---|
910 | try |
---|
911 | { |
---|
912 | FileStream* fs = new FileStream("..\\couplers.txt",FileMode::Open); |
---|
913 | StreamReader* sr = new StreamReader(fs); |
---|
914 | int count=0; |
---|
915 | uint16_t tabNumP[4]={0,0,0,0}; |
---|
916 | uint16_t tabNumC1C2[8]={0,0,0,0,0,0,0,0}; |
---|
917 | int rc; |
---|
918 | int size; |
---|
919 | |
---|
920 | for (;;) |
---|
921 | { |
---|
922 | String* line = sr->ReadLine(); |
---|
923 | CGroupBox* gboxPtr; |
---|
924 | if (count) |
---|
925 | { |
---|
926 | switch (count) |
---|
927 | { |
---|
928 | case 1 : case 2 : case 3 : |
---|
929 | {//banc a |
---|
930 | Console::WriteLine(line); |
---|
931 | CGroupBox* gboxPtr = (CGroupBox*)pal->get_Item(0); |
---|
932 | if (count == 1) |
---|
933 | { |
---|
934 | gboxPtr->SetValNumP(line); |
---|
935 | tabNumP[0] = Convert::ToInt16(line); |
---|
936 | } |
---|
937 | if (count == 2) |
---|
938 | { |
---|
939 | gboxPtr->SetValNumC1(line); |
---|
940 | tabNumC1C2[0] = Convert::ToInt16(line); |
---|
941 | } |
---|
942 | if (count == 3) |
---|
943 | { |
---|
944 | gboxPtr->SetValNumC2(line); |
---|
945 | tabNumC1C2[1] = Convert::ToInt16(line); |
---|
946 | } |
---|
947 | } |
---|
948 | break; |
---|
949 | case 4 : case 5 : case 6 : |
---|
950 | {//banc b |
---|
951 | Console::WriteLine(line); |
---|
952 | CGroupBox* gboxPtr = (CGroupBox*)pal->get_Item(1); |
---|
953 | if (count == 4) |
---|
954 | { |
---|
955 | gboxPtr->SetValNumP(line); |
---|
956 | tabNumP[1] = Convert::ToInt16(line); |
---|
957 | } |
---|
958 | if (count == 5) |
---|
959 | { |
---|
960 | gboxPtr->SetValNumC1(line); |
---|
961 | tabNumC1C2[2] = Convert::ToInt16(line); |
---|
962 | } |
---|
963 | if (count == 6) |
---|
964 | { |
---|
965 | gboxPtr->SetValNumC2(line); |
---|
966 | tabNumC1C2[3] = Convert::ToInt16(line); |
---|
967 | } |
---|
968 | } |
---|
969 | break; |
---|
970 | case 7 : case 8 : case 9 : |
---|
971 | {//banc c |
---|
972 | Console::WriteLine(line); |
---|
973 | gboxPtr = (CGroupBox*)pal->get_Item(2); |
---|
974 | if (count == 7) |
---|
975 | { |
---|
976 | gboxPtr->SetValNumP(line); |
---|
977 | tabNumP[2] = Convert::ToInt16(line); |
---|
978 | } |
---|
979 | if (count == 8) |
---|
980 | { |
---|
981 | gboxPtr->SetValNumC1(line); |
---|
982 | tabNumC1C2[4] = Convert::ToInt16(line); |
---|
983 | } |
---|
984 | if (count == 9) |
---|
985 | { |
---|
986 | gboxPtr->SetValNumC2(line); |
---|
987 | tabNumC1C2[5] = Convert::ToInt16(line); |
---|
988 | } |
---|
989 | } |
---|
990 | break; |
---|
991 | case 10 : case 11 : case 12 : |
---|
992 | {//banc d |
---|
993 | Console::WriteLine(line); |
---|
994 | CGroupBox* gboxPtr = (CGroupBox*)pal->get_Item(3); |
---|
995 | if (count == 10) |
---|
996 | { |
---|
997 | gboxPtr->SetValNumP(line); |
---|
998 | tabNumP[3] = Convert::ToInt16(line); |
---|
999 | } |
---|
1000 | if (count == 11) |
---|
1001 | { |
---|
1002 | gboxPtr->SetValNumC1(line); |
---|
1003 | tabNumC1C2[6] = Convert::ToInt16(line); |
---|
1004 | } |
---|
1005 | if (count == 12) |
---|
1006 | { |
---|
1007 | gboxPtr->SetValNumC2(line); |
---|
1008 | tabNumC1C2[7] = Convert::ToInt16(line); |
---|
1009 | } |
---|
1010 | } |
---|
1011 | break; |
---|
1012 | } |
---|
1013 | } |
---|
1014 | count++; |
---|
1015 | if (line==0)//fin du fichier : on ecrit sur le modbus |
---|
1016 | { |
---|
1017 | sr->Close(); |
---|
1018 | Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write NumP NumC1 et NumC2..."); |
---|
1019 | size=4; |
---|
1020 | rc=modbus_write_registers(ctx, 2070,size, tabNumP);//NumP |
---|
1021 | if (rc != size) |
---|
1022 | Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding failed..."); |
---|
1023 | size=8; |
---|
1024 | rc=modbus_write_registers(ctx, 2050,size, tabNumC1C2);//NumC1 et NumC2 |
---|
1025 | if (rc != size) |
---|
1026 | Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding failed..."); |
---|
1027 | break; |
---|
1028 | } |
---|
1029 | } |
---|
1030 | } |
---|
1031 | catch (System::Exception* pe) |
---|
1032 | { |
---|
1033 | Console::WriteLine(pe->ToString()); |
---|
1034 | } |
---|
1035 | |
---|
1036 | }//fin lectBddFic false |
---|
1037 | } |
---|
1038 | |
---|
1039 | void CDialogConfig::Radio_Clicked(Object* pSender, EventArgs* pArgs)//remplit automatiquement la zone de texte |
---|
1040 | { |
---|
1041 | for(int index=0;index<NB_BANCS;index++) |
---|
1042 | {//zones de texte initialisée vide |
---|
1043 | CGroupBox* gboxPtr = (CGroupBox*)pal->get_Item(index); |
---|
1044 | gboxPtr->SetValNumP("xx"); |
---|
1045 | gboxPtr->SetValNumC1("xx"); |
---|
1046 | gboxPtr->SetValNumC2("xx"); |
---|
1047 | } |
---|
1048 | |
---|
1049 | if (pSender == rbAutoBdd) |
---|
1050 | { |
---|
1051 | Console::WriteLine(S"CDialogConfig::Radio_Clicked : lecture bdd activée..."); |
---|
1052 | lectBddFic=true; |
---|
1053 | } |
---|
1054 | else if (pSender == rbAutoFichier) |
---|
1055 | { |
---|
1056 | Console::WriteLine(S"CDialogConfig::Radio_Clicked : lecture fichier activée..."); |
---|
1057 | lectBddFic=false; |
---|
1058 | } |
---|
1059 | } |
---|
1060 | |
---|
1061 | |
---|
1062 | CLabelTextBox::CLabelTextBox(String* labString, int posX, int posY, int sizeX, int sizeY, int sizeText) |
---|
1063 | { |
---|
1064 | name=labString; |
---|
1065 | labPosX=posX; |
---|
1066 | labPosY=posY; |
---|
1067 | labSizeX=sizeX; |
---|
1068 | labSizeY=sizeY; |
---|
1069 | nbInstance++; |
---|
1070 | |
---|
1071 | lab= new Label(); |
---|
1072 | val= new TextBox(); |
---|
1073 | |
---|
1074 | // dPLabel et dPBox : label et zone de saisie sont placés l'un à côté de l'autre |
---|
1075 | lab->Location = Point(labPosX, labPosY); |
---|
1076 | lab->Size = System::Drawing::Size(labSizeX,labSizeY); |
---|
1077 | lab->Text = name;//zone de texte initialisée |
---|
1078 | lab->TextAlign = ContentAlignment::MiddleRight; |
---|
1079 | val->Location = Point(labPosX+labSizeX, labPosY); |
---|
1080 | val->Size = System::Drawing::Size(sizeText, 20); |
---|
1081 | val->Text = "";//zone de texte initialisée vide |
---|
1082 | val->Font = new System::Drawing::Font(S"Arial", 9, FontStyle::Bold);; |
---|
1083 | val->ForeColor = Color::Brown; |
---|
1084 | } |
---|
1085 | |
---|
1086 | Label* CLabelTextBox::GetLabel() |
---|
1087 | { |
---|
1088 | return lab; |
---|
1089 | } |
---|
1090 | |
---|
1091 | TextBox* CLabelTextBox::GetTextBox() |
---|
1092 | { |
---|
1093 | return val; |
---|
1094 | } |
---|
1095 | |
---|
1096 | String* CLabelTextBox::GetName() |
---|
1097 | { |
---|
1098 | return name; |
---|
1099 | } |
---|
1100 | |
---|
1101 | void CLabelTextBox::SetVal(String* value) |
---|
1102 | { |
---|
1103 | val->Text=value; |
---|
1104 | } |
---|
1105 | |
---|
1106 | String* CLabelTextBox::GetVal() |
---|
1107 | { |
---|
1108 | return val->Text; |
---|
1109 | } |
---|
1110 | |
---|
1111 | void CLabelTextBox::SetColor(int value) |
---|
1112 | { |
---|
1113 | /* if(value) |
---|
1114 | val->BackColor=Color::Red; |
---|
1115 | else |
---|
1116 | val->BackColor=Color::White; |
---|
1117 | */ |
---|
1118 | if(!value) |
---|
1119 | val->BackColor=Color::White; |
---|
1120 | if(value==1) |
---|
1121 | val->BackColor=Color::Red; |
---|
1122 | if(value==2) |
---|
1123 | val->BackColor=Color::LemonChiffon; |
---|
1124 | } |
---|
1125 | |
---|
1126 | |
---|
1127 | MaDialogUser::MaDialogUser() |
---|
1128 | { |
---|
1129 | // définit les paramètres du formulaire |
---|
1130 | Text = S"XSUC - lecture serveur"; |
---|
1131 | // FormBorderStyle = FormBorderStyle::Fixed3D;//impossible de modifier la taille |
---|
1132 | FormBorderStyle = FormBorderStyle::FixedDialog; |
---|
1133 | MaximizeBox = false; |
---|
1134 | MinimizeBox = false; |
---|
1135 | this->ControlBox=false; |
---|
1136 | Size = System::Drawing::Size(1250,800); |
---|
1137 | |
---|
1138 | // Creation de controle |
---|
1139 | OKBtn = new Button(); |
---|
1140 | EcritureBtn = new Button(); |
---|
1141 | // CancelBtn = new Button(); |
---|
1142 | |
---|
1143 | // bouton OK |
---|
1144 | OKBtn->Location = Point(900, 700); |
---|
1145 | OKBtn->Name = "Bouton OK"; |
---|
1146 | OKBtn->Text = "OK"; |
---|
1147 | OKBtn->DialogResult = DialogResult::OK; |
---|
1148 | /* |
---|
1149 | // bouton Cancel |
---|
1150 | CancelBtn->Location = Point(192, 136); |
---|
1151 | CancelBtn->Name = "Bouton Cancel"; |
---|
1152 | CancelBtn->Text = "Annuler"; |
---|
1153 | CancelBtn->DialogResult = DialogResult::Cancel; |
---|
1154 | */ |
---|
1155 | // bouton Ecriture |
---|
1156 | EcritureBtn->Location = Point(900, 600); |
---|
1157 | EcritureBtn->Name = "Bouton Ecriture"; |
---|
1158 | EcritureBtn->Text = "Ecriture"; |
---|
1159 | // EcritureBtn->DialogResult = DialogResult::OK;//sinon fermera aussi la fenetre parente |
---|
1160 | |
---|
1161 | // Ajoute les controles dans le formaulaire |
---|
1162 | Controls->Add(OKBtn); |
---|
1163 | Controls->Add(EcritureBtn); |
---|
1164 | |
---|
1165 | pal = new ArrayList(); |
---|
1166 | for (indexTextBox=0;indexTextBox<20;indexTextBox++)//creation des controles dans le formulaire |
---|
1167 | { |
---|
1168 | int posX=650, j=indexTextBox; |
---|
1169 | if (indexTextBox>=10) |
---|
1170 | { |
---|
1171 | posX=810; |
---|
1172 | j=indexTextBox-10; |
---|
1173 | } |
---|
1174 | pal->Add(new CLabelTextBox(nameLab_1[indexTextBox],posX,(25*j)+10,100,16,70)); |
---|
1175 | CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox); |
---|
1176 | Controls->Add(cltbPtr->GetLabel()); |
---|
1177 | Controls->Add(cltbPtr->GetTextBox()); |
---|
1178 | } |
---|
1179 | for (;indexTextBox<26;indexTextBox++)//creation des controles dans le formulaire |
---|
1180 | { |
---|
1181 | int posX=400, j=indexTextBox-20; |
---|
1182 | int sizeText=70; |
---|
1183 | if (indexTextBox==20)sizeText=20; |
---|
1184 | pal->Add(new CLabelTextBox(nameLab_1[indexTextBox],posX,(25*j)+10,100,16,sizeText)); |
---|
1185 | CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox); |
---|
1186 | Controls->Add(cltbPtr->GetLabel()); |
---|
1187 | Controls->Add(cltbPtr->GetTextBox()); |
---|
1188 | } |
---|
1189 | |
---|
1190 | Setup_Group_Conditionning(); |
---|
1191 | |
---|
1192 | // Mode tt seul |
---|
1193 | pal->Add(new CLabelTextBox("MODE",20,100,50,16,75)); |
---|
1194 | CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox++); |
---|
1195 | Controls->Add(cltbPtr->GetLabel()); |
---|
1196 | Controls->Add(cltbPtr->GetTextBox()); |
---|
1197 | |
---|
1198 | //sauve l'index condionning |
---|
1199 | indexTextBoxSave=indexTextBox;//04-07-2013 : nouveaux controles |
---|
1200 | // Ln |
---|
1201 | // Ln tt seul |
---|
1202 | Label* ln= new Label(); |
---|
1203 | ln->Location = Point(950, 300); |
---|
1204 | ln->Size = System::Drawing::Size(70,16); |
---|
1205 | ln->Text = nameLab_5[1];//zone de texte initialisée |
---|
1206 | ln->TextAlign = ContentAlignment::MiddleCenter; |
---|
1207 | Controls->Add(ln); |
---|
1208 | int j=0; |
---|
1209 | for (;indexTextBox<(indexTextBoxSave+8);indexTextBox++)//creation des controles dans le formulaire |
---|
1210 | { |
---|
1211 | int posX=850;int posY=300; |
---|
1212 | int sizeText=70; |
---|
1213 | pal->Add(new CLabelTextBox(nameLab_6[indexTextBox-indexTextBoxSave],posX,posY+(j+=20),100,16,sizeText)); |
---|
1214 | CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox); |
---|
1215 | Controls->Add(cltbPtr->GetLabel()); |
---|
1216 | Controls->Add(cltbPtr->GetTextBox()); |
---|
1217 | // Console::WriteLine(indexTextBox); |
---|
1218 | // Console::WriteLine(posX); |
---|
1219 | // Console::WriteLine(posY); |
---|
1220 | } |
---|
1221 | |
---|
1222 | //sauve l'index condionning |
---|
1223 | indexTextBoxSave=indexTextBox;//04-07-2013 : nouveaux controles |
---|
1224 | //Tp_max |
---|
1225 | //Tp_max tt seul |
---|
1226 | Label* tp_max= new Label(); |
---|
1227 | tp_max->Location = Point(1050, 300); |
---|
1228 | tp_max->Size = System::Drawing::Size(75,16); |
---|
1229 | tp_max->Text = nameLab_5[2];//zone de texte initialisée |
---|
1230 | tp_max->TextAlign = ContentAlignment::MiddleCenter; |
---|
1231 | Controls->Add(tp_max); |
---|
1232 | j=0; |
---|
1233 | for (;indexTextBox<(indexTextBoxSave+7);indexTextBox++)//creation des controles dans le formulaire |
---|
1234 | { |
---|
1235 | int posX=950;int posY=300; |
---|
1236 | int sizeText=70; |
---|
1237 | pal->Add(new CLabelTextBox(nameLab_6[indexTextBox-indexTextBoxSave],posX,posY+(j+=20),100,16,sizeText)); |
---|
1238 | CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox); |
---|
1239 | Controls->Add(cltbPtr->GetLabel()); |
---|
1240 | Controls->Add(cltbPtr->GetTextBox()); |
---|
1241 | // Console::WriteLine(indexTextBox); |
---|
1242 | // Console::WriteLine(posX); |
---|
1243 | // Console::WriteLine(posY); |
---|
1244 | } |
---|
1245 | |
---|
1246 | //sauve l'index condionning |
---|
1247 | indexTextBoxSave=indexTextBox;//04-07-2013 : nouveaux controles |
---|
1248 | //Pi_max |
---|
1249 | //Pi_max tt seul |
---|
1250 | Label* pi_max= new Label(); |
---|
1251 | pi_max->Location = Point(1150, 300); |
---|
1252 | pi_max->Size = System::Drawing::Size(70,16); |
---|
1253 | pi_max->Text = nameLab_5[3];//zone de texte initialisée |
---|
1254 | pi_max->TextAlign = ContentAlignment::MiddleCenter; |
---|
1255 | Controls->Add(pi_max); |
---|
1256 | j=0; |
---|
1257 | for (;indexTextBox<(indexTextBoxSave+8);indexTextBox++)//creation des controles dans le formulaire |
---|
1258 | { |
---|
1259 | int posX=1050;int posY=300; |
---|
1260 | int sizeText=70; |
---|
1261 | pal->Add(new CLabelTextBox(nameLab_6[indexTextBox-indexTextBoxSave],posX,posY+(j+=20),100,16,sizeText)); |
---|
1262 | CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox); |
---|
1263 | Controls->Add(cltbPtr->GetLabel()); |
---|
1264 | Controls->Add(cltbPtr->GetTextBox()); |
---|
1265 | // Console::WriteLine(indexTextBox); |
---|
1266 | // Console::WriteLine(posX); |
---|
1267 | // Console::WriteLine(posY); |
---|
1268 | } |
---|
1269 | |
---|
1270 | // ERREUR tt seul |
---|
1271 | //sauve l'index condionning |
---|
1272 | indexTextBoxSave=indexTextBox;//04-07-2013 : nouveaux controles |
---|
1273 | for (;indexTextBox<(indexTextBoxSave+1);indexTextBox++)//creation des controles dans le formulaire |
---|
1274 | { |
---|
1275 | int sizeText=100; |
---|
1276 | pal->Add(new CLabelTextBox("Erreur",900,550,100,16,sizeText)); |
---|
1277 | CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox); |
---|
1278 | Controls->Add(cltbPtr->GetLabel()); |
---|
1279 | Controls->Add(cltbPtr->GetTextBox()); |
---|
1280 | } |
---|
1281 | |
---|
1282 | |
---|
1283 | //configure les 2 propriétés : AcceptButton contient la réf du bouton par défaut du formulaire.. |
---|
1284 | //..on peut cliquer sur le bouton OK ou bien sur la touche Entrée du clavier.. |
---|
1285 | //..referme aussi la boite car DialogResult renvoie OK |
---|
1286 | AcceptButton = OKBtn; |
---|
1287 | //CancelButton contient la réf du bouton associée à la touche Echap du clavier |
---|
1288 | // CancelButton = CancelBtn; |
---|
1289 | |
---|
1290 | //gestionnnaire associé aux boutons |
---|
1291 | OKBtn->Click += new EventHandler(this, &MaDialogUser::OKMaDBtn_Clicked); |
---|
1292 | EcritureBtn->Click += new EventHandler(this, &MaDialogUser::EcritureBtn_Clicked); |
---|
1293 | |
---|
1294 | Setup_Group(); |
---|
1295 | } |
---|
1296 | |
---|
1297 | void MaDialogUser::EcritureBtn_Clicked(Object* pSender,EventArgs* pArgs)//gestionnaire d'evenement de la boite dialogue |
---|
1298 | { |
---|
1299 | //crée la boite de dialogue utilisateur |
---|
1300 | CDialogConfig* box = new CDialogConfig(); |
---|
1301 | //affiche la boite de dialogue |
---|
1302 | if (box->ShowDialog() == DialogResult::OK) |
---|
1303 | { |
---|
1304 | //si la valeur OK est renvoyée, on affiche le nom |
---|
1305 | //MessageBox::Show(S"Ecriture"); |
---|
1306 | } |
---|
1307 | } |
---|
1308 | |
---|
1309 | void MaDialogUser::OKMaDBtn_Clicked(Object* pSender,EventArgs* pArgs)//gestionnaire d'evenement de la boite dialogue |
---|
1310 | { |
---|
1311 | //arrete le lecture si activée et fermer le formulaire lorsqu'on clique sur le bouton |
---|
1312 | if ((uThread!=NULL)&&(uThread->IsAlive)) |
---|
1313 | { |
---|
1314 | // Stop the thread. |
---|
1315 | uThread->Suspend(); |
---|
1316 | uThread=NULL; |
---|
1317 | } |
---|
1318 | Close(); |
---|
1319 | } |
---|
1320 | |
---|
1321 | float MaDialogUser::PermutToReversed(uint16_t* tab_rp_registers,int index)//permute float32 en float32 Reverse |
---|
1322 | { |
---|
1323 | uint16_t wordPermuted[2]; |
---|
1324 | |
---|
1325 | *(wordPermuted+0)= tab_rp_registers[index+1]; |
---|
1326 | *(wordPermuted+1)= tab_rp_registers[index+0]; |
---|
1327 | return (modbus_get_float(wordPermuted+0));//float32 Reverse |
---|
1328 | } |
---|
1329 | |
---|
1330 | void MaDialogUser::ThreadProc()//gestionnaire d'evenement du thread de la boite dialogue |
---|
1331 | { |
---|
1332 | uint8_t tab_rp_bits[MODBUS_SIZE_READ_COILS]; |
---|
1333 | uint16_t tab_rp_registers_low[MODBUS_SIZE_READ_HOLDINGS_LOW]; |
---|
1334 | uint16_t tab_rp_registers_high[MODBUS_SIZE_READ_HOLDINGS_HIGH]; |
---|
1335 | int rc, adress, size; |
---|
1336 | CLabelTextBox* cltbPtr; |
---|
1337 | |
---|
1338 | for (;;) |
---|
1339 | { |
---|
1340 | Thread::Sleep(500); |
---|
1341 | Console::WriteLine(S"ThreadProc: read coils..."); |
---|
1342 | adress=MODBUS_BASEADR_COILS;//adresse coils=MODBUS_BASEADR_COILS |
---|
1343 | size=MODBUS_SIZE_READ_COILS; |
---|
1344 | rc = modbus_read_bits(ctx, adress, size, tab_rp_bits);////JCM : adresse coils=MODBUS_BASEADR_COILS |
---|
1345 | if (rc != size) |
---|
1346 | Console::WriteLine(S"ThreadProc: read coils failed..."); |
---|
1347 | |
---|
1348 | Thread::Sleep(500); |
---|
1349 | Console::WriteLine(S"ThreadProc: read holdings..."); |
---|
1350 | adress=MODBUS_BASEADR_LOW_HOLDINGS;//adresse holding=MODBUS_BASEADR_LOW_HOLDINGS |
---|
1351 | size=82; |
---|
1352 | rc = modbus_read_registers(ctx, adress, size, tab_rp_registers_low); |
---|
1353 | if (rc != size) |
---|
1354 | Console::WriteLine(S"ThreadProc: read holdings failed..."); |
---|
1355 | |
---|
1356 | int indexArrayList=0; |
---|
1357 | //dtp : ui16 |
---|
1358 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1359 | cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[4])); |
---|
1360 | //dt : ui16 |
---|
1361 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1362 | cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[5])); |
---|
1363 | //dP : float32 |
---|
1364 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1365 | cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_low,6))); |
---|
1366 | //dPsecu : float32 |
---|
1367 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1368 | cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_low,8))); |
---|
1369 | |
---|
1370 | //NBal : ui16 |
---|
1371 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1372 | cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[42])); |
---|
1373 | cltbPtr->SetColor(2); |
---|
1374 | //P_cde : float32 |
---|
1375 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1376 | cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_low,43))); |
---|
1377 | cltbPtr->SetColor(2); |
---|
1378 | //Pp : float32 |
---|
1379 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1380 | cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_low,45))); |
---|
1381 | |
---|
1382 | //Nbal_max : ui16 |
---|
1383 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1384 | cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[25])); |
---|
1385 | //Fr : ui16 |
---|
1386 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1387 | cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[26])); |
---|
1388 | //N_cur : ui16 |
---|
1389 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1390 | if (tab_rp_registers_low[27]==(NB_ETAPES-4))//N_cur s'arrete a 8 |
---|
1391 | cltbPtr->SetVal("Balayage..."); |
---|
1392 | else |
---|
1393 | cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[27])); |
---|
1394 | cltbPtr->SetColor(2); |
---|
1395 | |
---|
1396 | //SVd : ui16 |
---|
1397 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1398 | cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[0])); |
---|
1399 | //SVfin : ui16 |
---|
1400 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1401 | cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[1])); |
---|
1402 | //SV1 : ui16 |
---|
1403 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1404 | cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[2])); |
---|
1405 | //SV2 : ui16 |
---|
1406 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1407 | cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[3])); |
---|
1408 | |
---|
1409 | //V_cur : ui16 |
---|
1410 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1411 | cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[37])); |
---|
1412 | cltbPtr->SetColor(2); |
---|
1413 | //Pic : float32 |
---|
1414 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1415 | cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_low,38))); |
---|
1416 | //Timer : uint32 |
---|
1417 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1418 | cltbPtr->SetVal(Convert::ToString((tab_rp_registers_low[40]<<16)+(tab_rp_registers_low[41]))); |
---|
1419 | cltbPtr->SetColor(2); |
---|
1420 | |
---|
1421 | //SVil : ui16 |
---|
1422 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1423 | cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[20])); |
---|
1424 | //Sleil : float32 |
---|
1425 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1426 | cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_low,21))); |
---|
1427 | //STc : float32 |
---|
1428 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1429 | cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_low,23))); |
---|
1430 | |
---|
1431 | //Eil : bool |
---|
1432 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1433 | cltbPtr->SetVal(Convert::ToString(tab_rp_bits[0])); |
---|
1434 | if(tab_rp_bits[0])//echec changer couleur |
---|
1435 | cltbPtr->SetColor(1); |
---|
1436 | else |
---|
1437 | cltbPtr->SetColor(2); |
---|
1438 | //Nil : ui16 |
---|
1439 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1440 | cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[30])); |
---|
1441 | if(tab_rp_registers_low[30])//echec changer couleur |
---|
1442 | cltbPtr->SetColor(1); |
---|
1443 | else |
---|
1444 | cltbPtr->SetColor(2); |
---|
1445 | //Nil_stat : ui16 |
---|
1446 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1447 | cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[31])); |
---|
1448 | cltbPtr->SetColor(2); |
---|
1449 | //P_last : float32 |
---|
1450 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1451 | cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_low,32))); |
---|
1452 | cltbPtr->SetColor(2); |
---|
1453 | //N_last : ui16 |
---|
1454 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1455 | cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[34])); |
---|
1456 | cltbPtr->SetColor(2); |
---|
1457 | //DPil : float32 |
---|
1458 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1459 | cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_low,35))); |
---|
1460 | |
---|
1461 | //Num_C : tab ui16 |
---|
1462 | for (int indexMbArray=50;(indexArrayList<34 && indexMbArray<58);indexMbArray++) |
---|
1463 | { |
---|
1464 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1465 | cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[indexMbArray])); |
---|
1466 | cltbPtr->SetColor(2); |
---|
1467 | } |
---|
1468 | |
---|
1469 | //Stat_C : tab bool |
---|
1470 | for (int indexMbArray=1;(indexArrayList<46 && indexMbArray<13);indexMbArray++) |
---|
1471 | { |
---|
1472 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1473 | cltbPtr->SetVal(Convert::ToString(tab_rp_bits[indexMbArray])); |
---|
1474 | /* if(!tab_rp_bits[indexMbArray])//echec changer couleur |
---|
1475 | cltbPtr->SetColor(1); |
---|
1476 | else |
---|
1477 | cltbPtr->SetColor(0); |
---|
1478 | */ } |
---|
1479 | |
---|
1480 | //Temp_cond : tab ui16 |
---|
1481 | for (int indexMbArray=58;(indexArrayList<58 && indexMbArray<71);indexMbArray++) |
---|
1482 | { |
---|
1483 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1484 | cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[indexMbArray])); |
---|
1485 | cltbPtr->SetColor(2); |
---|
1486 | } |
---|
1487 | |
---|
1488 | //status : ui16 |
---|
1489 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1490 | cltbPtr->SetColor(2); |
---|
1491 | if (tab_rp_registers_low[49] != 4)//on n'est pas ds le mode pulsing |
---|
1492 | { |
---|
1493 | cltbPtr->SetVal("ARRET"); |
---|
1494 | btnStart->Enabled=false;//bouton start |
---|
1495 | btnStop->Enabled=false;//bouton stop |
---|
1496 | btnPause->Enabled=false;//bouton pause |
---|
1497 | btnReprise->Enabled=false;//bouton reprise |
---|
1498 | } |
---|
1499 | else |
---|
1500 | {//mode pulsing |
---|
1501 | /* |
---|
1502 | switch (tab_rp_registers_low[28]){//RetMAPR |
---|
1503 | case 0://conditionnement arreté |
---|
1504 | cltbPtr->SetVal("ARRET"); |
---|
1505 | btnStart->Enabled=true;//bouton start |
---|
1506 | btnStop->Enabled=false;//bouton stop |
---|
1507 | btnPause->Enabled=false;//bouton pause |
---|
1508 | btnReprise->Enabled=false;//bouton reprise |
---|
1509 | break; |
---|
1510 | case 2: case 3://conditionnement démarré ou repris |
---|
1511 | cltbPtr->SetVal("MARCHE"); |
---|
1512 | btnStart->Enabled=false;//bouton start |
---|
1513 | btnStop->Enabled=true;//bouton stop |
---|
1514 | btnPause->Enabled=true;//bouton pause |
---|
1515 | btnReprise->Enabled=false;//bouton reprise |
---|
1516 | break; |
---|
1517 | case 1://conditionnement en pause |
---|
1518 | cltbPtr->SetVal("PAUSE"); |
---|
1519 | btnStart->Enabled=false;//bouton start |
---|
1520 | btnStop->Enabled=true;//bouton stop |
---|
1521 | btnPause->Enabled=false;//bouton pause |
---|
1522 | btnReprise->Enabled=true;//bouton reprise |
---|
1523 | break; |
---|
1524 | } |
---|
1525 | if (tab_rp_registers_low[28] != tab_rp_registers_low[48])//message affiché |
---|
1526 | { |
---|
1527 | String* stra[] = {S"RetMAPR=",Convert::ToString(tab_rp_registers_low[28]), |
---|
1528 | S" not equal to MAPR=",Convert::ToString(tab_rp_registers_low[48])}; |
---|
1529 | String* str=String::Concat(stra); |
---|
1530 | Console::WriteLine(str); |
---|
1531 | } |
---|
1532 | */ |
---|
1533 | if ((tab_rp_registers_low[28] == 1)|| tab_rp_registers_low[29]) |
---|
1534 | {//RetMAR conditionnement arreté ou defaut |
---|
1535 | cltbPtr->SetVal("ARRET"); |
---|
1536 | btnStart->Enabled=false;//bouton start |
---|
1537 | btnStop->Enabled=true;//bouton stop |
---|
1538 | btnReprise->Enabled=false;//bouton reprise |
---|
1539 | } |
---|
1540 | switch (tab_rp_registers_low[28]){//RetMAR |
---|
1541 | case 0://conditionnement arreté |
---|
1542 | cltbPtr->SetVal("ARRET"); |
---|
1543 | btnStart->Enabled=true;//bouton start |
---|
1544 | btnStop->Enabled=false;//bouton stop |
---|
1545 | btnReprise->Enabled=true;//bouton reprise |
---|
1546 | break; |
---|
1547 | case 2: case 3://conditionnement démarré ou repris |
---|
1548 | cltbPtr->SetVal("MARCHE"); |
---|
1549 | btnStart->Enabled=false;//bouton start |
---|
1550 | btnStop->Enabled=true;//bouton stop |
---|
1551 | btnReprise->Enabled=false;//bouton reprise |
---|
1552 | break; |
---|
1553 | } |
---|
1554 | if (tab_rp_registers_low[28] != tab_rp_registers_low[48])//message affiché |
---|
1555 | { |
---|
1556 | String* stra[] = {S"RetMAPR=",Convert::ToString(tab_rp_registers_low[28]), |
---|
1557 | S" not equal to MAPR=",Convert::ToString(tab_rp_registers_low[48])}; |
---|
1558 | String* str=String::Concat(stra); |
---|
1559 | Console::WriteLine(str); |
---|
1560 | } |
---|
1561 | }//fin mode pulsing |
---|
1562 | |
---|
1563 | //N_Seqcond : ui16 |
---|
1564 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1565 | cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[47])); |
---|
1566 | cltbPtr->SetColor(2); |
---|
1567 | |
---|
1568 | Thread::Sleep(500); |
---|
1569 | Console::WriteLine(S"ThreadProc: read holdings..."); |
---|
1570 | adress=MODBUS_BASEADR_HIGH_HOLDINGS;//adresse holding=MODBUS_BASEADR_HIGH_HOLDINGS |
---|
1571 | size=MODBUS_SIZE_READ_HOLDINGS_HIGH; |
---|
1572 | rc = modbus_read_registers(ctx, adress, size, tab_rp_registers_high); |
---|
1573 | if (rc != size) |
---|
1574 | Console::WriteLine(S"ThreadProc: read holdings failed..."); |
---|
1575 | |
---|
1576 | //DateD HeureD : tab ui16 |
---|
1577 | String* str; |
---|
1578 | String* strDD[] = { |
---|
1579 | Convert::ToString(tab_rp_registers_high[84]), |
---|
1580 | "-", |
---|
1581 | Convert::ToString(tab_rp_registers_high[85]), |
---|
1582 | "-", |
---|
1583 | Convert::ToString(tab_rp_registers_high[86])}; |
---|
1584 | str=String::Concat(strDD); |
---|
1585 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1586 | cltbPtr->SetVal(str); |
---|
1587 | cltbPtr->SetColor(2); |
---|
1588 | String* strHD[] = { |
---|
1589 | Convert::ToString(tab_rp_registers_high[87]), |
---|
1590 | ":", |
---|
1591 | Convert::ToString(tab_rp_registers_high[88]), |
---|
1592 | ":", |
---|
1593 | Convert::ToString(tab_rp_registers_high[89])}; |
---|
1594 | str=String::Concat(strHD); |
---|
1595 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1596 | cltbPtr->SetVal(str); |
---|
1597 | cltbPtr->SetColor(2); |
---|
1598 | |
---|
1599 | //DateF HeureF : tab ui16 |
---|
1600 | String* strDF[] = { |
---|
1601 | Convert::ToString(tab_rp_registers_high[90]), |
---|
1602 | "-", |
---|
1603 | Convert::ToString(tab_rp_registers_high[91]), |
---|
1604 | "-", |
---|
1605 | Convert::ToString(tab_rp_registers_high[92])}; |
---|
1606 | str=String::Concat(strDF); |
---|
1607 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1608 | cltbPtr->SetVal(str); |
---|
1609 | cltbPtr->SetColor(2); |
---|
1610 | String* strHF[] = { |
---|
1611 | Convert::ToString(tab_rp_registers_high[93]), |
---|
1612 | ":", |
---|
1613 | Convert::ToString(tab_rp_registers_high[94]), |
---|
1614 | ":", |
---|
1615 | Convert::ToString(tab_rp_registers_high[95])}; |
---|
1616 | str=String::Concat(strHF); |
---|
1617 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1618 | cltbPtr->SetVal(str); |
---|
1619 | cltbPtr->SetColor(2); |
---|
1620 | |
---|
1621 | //Vides : tab ui16 |
---|
1622 | for (int indexMbArray=98;indexMbArray<110;indexMbArray++) |
---|
1623 | { |
---|
1624 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1625 | cltbPtr->SetVal(Convert::ToString(tab_rp_registers_high[indexMbArray])); |
---|
1626 | cltbPtr->SetColor(2); |
---|
1627 | } |
---|
1628 | |
---|
1629 | //Prc : tab float32 |
---|
1630 | for (int indexMbArray=68;indexMbArray<76;indexMbArray+=2) |
---|
1631 | { |
---|
1632 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1633 | cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_high,indexMbArray))); |
---|
1634 | cltbPtr->SetColor(2); |
---|
1635 | } |
---|
1636 | |
---|
1637 | //Pic : tab float32 |
---|
1638 | for (int indexMbArray=60;indexMbArray<68;indexMbArray+=2) |
---|
1639 | { |
---|
1640 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1641 | cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_high,indexMbArray))); |
---|
1642 | cltbPtr->SetColor(2); |
---|
1643 | } |
---|
1644 | |
---|
1645 | //Pch : tab float32 |
---|
1646 | for (int indexMbArray=76;indexMbArray<84;indexMbArray+=2) |
---|
1647 | { |
---|
1648 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1649 | cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_high,indexMbArray))); |
---|
1650 | cltbPtr->SetColor(2); |
---|
1651 | } |
---|
1652 | |
---|
1653 | //Ie_cur : tab float32 |
---|
1654 | for (int indexMbArray=10;indexMbArray<18;indexMbArray+=2) |
---|
1655 | { |
---|
1656 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1657 | cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_low,indexMbArray))); |
---|
1658 | cltbPtr->SetColor(2); |
---|
1659 | } |
---|
1660 | |
---|
1661 | //Num_P : tab ui16 |
---|
1662 | for (int indexMbArray=70;indexMbArray<74;indexMbArray++) |
---|
1663 | { |
---|
1664 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1665 | cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[indexMbArray])); |
---|
1666 | cltbPtr->SetColor(2); |
---|
1667 | } |
---|
1668 | |
---|
1669 | //Mode : ui16 |
---|
1670 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1671 | switch (tab_rp_registers_low[49]){ |
---|
1672 | case 0://station en mode init |
---|
1673 | cltbPtr->SetVal("INIT"); |
---|
1674 | break; |
---|
1675 | case 1://station en mode off |
---|
1676 | cltbPtr->SetVal("OFF"); |
---|
1677 | break; |
---|
1678 | case 2://station en mode heater |
---|
1679 | cltbPtr->SetVal("HEATER"); |
---|
1680 | break; |
---|
1681 | case 3://station en mode standby |
---|
1682 | cltbPtr->SetVal("STANDBY"); |
---|
1683 | break; |
---|
1684 | case 4://station en mode pulsing=conditionnement |
---|
1685 | cltbPtr->SetVal("PULSING"); |
---|
1686 | break; |
---|
1687 | case 5://station en mode off |
---|
1688 | cltbPtr->SetVal("STOP"); |
---|
1689 | break; |
---|
1690 | } |
---|
1691 | |
---|
1692 | //Ln : tab ui16 |
---|
1693 | for (int indexMbArray=0;indexMbArray<8;indexMbArray++) |
---|
1694 | { |
---|
1695 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1696 | cltbPtr->SetVal(Convert::ToString(tab_rp_registers_high[indexMbArray])); |
---|
1697 | } |
---|
1698 | |
---|
1699 | //Tp_max : tab ui16 |
---|
1700 | for (int indexMbArray=24;indexMbArray<31;indexMbArray++) |
---|
1701 | { |
---|
1702 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1703 | cltbPtr->SetVal(Convert::ToString(tab_rp_registers_high[indexMbArray])); |
---|
1704 | } |
---|
1705 | |
---|
1706 | //Pi_max : tab float32 |
---|
1707 | for (int indexMbArray=36;indexMbArray<52;indexMbArray+=2) |
---|
1708 | { |
---|
1709 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1710 | cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_high,indexMbArray))); |
---|
1711 | } |
---|
1712 | |
---|
1713 | //Erreur : ui16 |
---|
1714 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++); |
---|
1715 | switch (tab_rp_registers_low[29]){//Erreur |
---|
1716 | case 1: |
---|
1717 | cltbPtr->SetVal("IL_HARD"); |
---|
1718 | cltbPtr->SetColor(1); |
---|
1719 | break; |
---|
1720 | case 2: |
---|
1721 | cltbPtr->SetVal("Timer_m_ko"); |
---|
1722 | cltbPtr->SetColor(1); |
---|
1723 | break; |
---|
1724 | case 3: |
---|
1725 | cltbPtr->SetVal("Nil_sup_max"); |
---|
1726 | cltbPtr->SetColor(1); |
---|
1727 | break; |
---|
1728 | case 4: |
---|
1729 | cltbPtr->SetVal("Pcde_sup_max"); |
---|
1730 | cltbPtr->SetColor(1); |
---|
1731 | break; |
---|
1732 | case 5: |
---|
1733 | cltbPtr->SetVal("Def_Vcur_Sweep"); |
---|
1734 | cltbPtr->SetColor(1); |
---|
1735 | break; |
---|
1736 | case 6: |
---|
1737 | cltbPtr->SetVal("Vcur_sup_SVfin"); |
---|
1738 | cltbPtr->SetColor(1); |
---|
1739 | break; |
---|
1740 | case 7: |
---|
1741 | cltbPtr->SetVal("Pref_Coupleur"); |
---|
1742 | cltbPtr->SetColor(1); |
---|
1743 | break; |
---|
1744 | case 8: |
---|
1745 | cltbPtr->SetVal("Temp_Coupleur"); |
---|
1746 | cltbPtr->SetColor(1); |
---|
1747 | break; |
---|
1748 | case 9: |
---|
1749 | cltbPtr->SetVal("Arc Coupleur A1"); |
---|
1750 | cltbPtr->SetColor(1); |
---|
1751 | break; |
---|
1752 | case 10: |
---|
1753 | cltbPtr->SetVal("Arc Coupleur A2"); |
---|
1754 | cltbPtr->SetColor(1); |
---|
1755 | break; |
---|
1756 | case 11: |
---|
1757 | cltbPtr->SetVal("Arc Coupleur B1"); |
---|
1758 | cltbPtr->SetColor(1); |
---|
1759 | break; |
---|
1760 | case 12: |
---|
1761 | cltbPtr->SetVal("Arc Coupleur B2"); |
---|
1762 | cltbPtr->SetColor(1); |
---|
1763 | break; |
---|
1764 | case 13: |
---|
1765 | cltbPtr->SetVal("Arc Coupleur C1"); |
---|
1766 | cltbPtr->SetColor(1); |
---|
1767 | break; |
---|
1768 | case 14: |
---|
1769 | cltbPtr->SetVal("Arc Coupleur C2"); |
---|
1770 | cltbPtr->SetColor(1); |
---|
1771 | break; |
---|
1772 | case 15: |
---|
1773 | cltbPtr->SetVal("Arc Coupleur D1"); |
---|
1774 | cltbPtr->SetColor(1); |
---|
1775 | break; |
---|
1776 | case 16: |
---|
1777 | cltbPtr->SetVal("Arc Coupleur D2"); |
---|
1778 | cltbPtr->SetColor(1); |
---|
1779 | break; |
---|
1780 | case 17: |
---|
1781 | cltbPtr->SetVal("Arc Klystron"); |
---|
1782 | cltbPtr->SetColor(1); |
---|
1783 | break; |
---|
1784 | default: |
---|
1785 | cltbPtr->SetVal("pas d'erreur"); |
---|
1786 | cltbPtr->SetColor(0); |
---|
1787 | break; |
---|
1788 | } |
---|
1789 | } |
---|
1790 | } |
---|
1791 | |
---|
1792 | void MaDialogUser::Setup_Group ()//creation et configuration d'un groupe d'options |
---|
1793 | { |
---|
1794 | // Creation |
---|
1795 | gbox = new GroupBox(); |
---|
1796 | gbox->Text = S"lecture"; |
---|
1797 | gbox->Size = System::Drawing::Size(200, 150);//taille du groupbox en pixels |
---|
1798 | gbox->Location = Point(200, 90); |
---|
1799 | |
---|
1800 | // Creation des boutons radio. |
---|
1801 | rb1 = new RadioButton(); |
---|
1802 | rb1->Text = S"oui"; |
---|
1803 | rb1->Location = Point(10,25); |
---|
1804 | |
---|
1805 | rb2 = new RadioButton(); |
---|
1806 | rb2->Text = S"non"; |
---|
1807 | rb2->Location = Point(10,55); |
---|
1808 | |
---|
1809 | // ajout des controles dans le groupe |
---|
1810 | gbox->Controls->Add(rb1); |
---|
1811 | gbox->Controls->Add(rb2); |
---|
1812 | |
---|
1813 | // ajout du groupe dans le formulaire. |
---|
1814 | Controls->Add(gbox); |
---|
1815 | |
---|
1816 | // associe le gestionnaire au groupe d'options |
---|
1817 | rb1->Click += new EventHandler(this, &MaDialogUser::Radio_Clicked); |
---|
1818 | rb2->Click += new EventHandler(this, &MaDialogUser::Radio_Clicked); |
---|
1819 | } |
---|
1820 | |
---|
1821 | void MaDialogUser::Setup_Group_Conditionning()//creation et configuration d'un groupe d'options |
---|
1822 | { |
---|
1823 | // Creation |
---|
1824 | GroupBox* gboxC = new GroupBox(); |
---|
1825 | gboxC->Text = S"CONDITIONNEMENT"; |
---|
1826 | // gboxC->Size = System::Drawing::Size(800, 450);//taille du groupbox en pixels |
---|
1827 | gboxC->Size = System::Drawing::Size(810, 450);//taille du groupbox en pixels |
---|
1828 | // gboxC->Location = Point(40,300); |
---|
1829 | gboxC->Location = Point(30,300); |
---|
1830 | |
---|
1831 | Setup_Buttons_Conditionning();//configure les boutons du formulaire |
---|
1832 | |
---|
1833 | // Num_C label tt seul |
---|
1834 | Label* num_C= new Label(); |
---|
1835 | num_C->Location = Point(50, 390); |
---|
1836 | num_C->Size = System::Drawing::Size(50,16); |
---|
1837 | num_C->Text = "Num_C";//zone de texte initialisée |
---|
1838 | num_C->TextAlign = ContentAlignment::MiddleRight; |
---|
1839 | Controls->Add(num_C); |
---|
1840 | int j=60;//depart affichage |
---|
1841 | /* for (int i=0;i<NB_COUPLEURS;indexTextBox++,i++,j+=80)//creation des controles dans le formulaire |
---|
1842 | { |
---|
1843 | int posX=70; |
---|
1844 | pal->Add(new CLabelTextBox(nameLab_2[i],posX+j,390,25,16,50)); |
---|
1845 | CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox); |
---|
1846 | Controls->Add(cltbPtr->GetLabel()); |
---|
1847 | Controls->Add(cltbPtr->GetTextBox()); |
---|
1848 | } |
---|
1849 | */ |
---|
1850 | int posX; |
---|
1851 | for (int i=0;i<NB_COUPLEURS;indexTextBox++,i++)//creation des controles dans le formulaire |
---|
1852 | { |
---|
1853 | switch (i) |
---|
1854 | { |
---|
1855 | case 0:posX=120;break; |
---|
1856 | case 1:posX=190;break; |
---|
1857 | case 2:posX=300;break; |
---|
1858 | case 3:posX=370;break; |
---|
1859 | case 4:posX=480;break; |
---|
1860 | case 5:posX=550;break; |
---|
1861 | case 6:posX=660;break; |
---|
1862 | case 7:posX=730;break; |
---|
1863 | } |
---|
1864 | Console::WriteLine(posX); |
---|
1865 | pal->Add(new CLabelTextBox(nameLab_2[i],posX,390,25,16,50)); |
---|
1866 | CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox); |
---|
1867 | Controls->Add(cltbPtr->GetLabel()); |
---|
1868 | Controls->Add(cltbPtr->GetTextBox()); |
---|
1869 | } |
---|
1870 | |
---|
1871 | // Stat_C label tt seul |
---|
1872 | Label* stat_C= new Label(); |
---|
1873 | stat_C->Location = Point(50, 630); |
---|
1874 | stat_C->Size = System::Drawing::Size(50,16); |
---|
1875 | stat_C->Text = "Stat_C";//zone de texte initialisée |
---|
1876 | stat_C->TextAlign = ContentAlignment::MiddleRight; |
---|
1877 | //4-07-13 Controls->Add(stat_C); |
---|
1878 | j=20;//depart affichage |
---|
1879 | // for (int i=0;indexTextBox<46;indexTextBox++,i++,j+=60)//creation des controles dans le formulaire |
---|
1880 | for (int i=0;i<NB_ETAPES;indexTextBox++,i++,j+=60)//creation des controles dans le formulaire |
---|
1881 | { |
---|
1882 | int posX=100; |
---|
1883 | pal->Add(new CLabelTextBox(Convert::ToString(i+1),posX+j,630,25,16,20)); |
---|
1884 | CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox); |
---|
1885 | //4-07-13 Controls->Add(cltbPtr->GetLabel()); |
---|
1886 | //4-07-13 Controls->Add(cltbPtr->GetTextBox()); |
---|
1887 | } |
---|
1888 | |
---|
1889 | // Temp_cond label tt seul |
---|
1890 | Label* temp_cond= new Label(); |
---|
1891 | temp_cond->Location = Point(50, 665); |
---|
1892 | temp_cond->Size = System::Drawing::Size(65,32); |
---|
1893 | temp_cond->Text = "Temp_cond (min)";//zone de texte initialisée |
---|
1894 | temp_cond->TextAlign = ContentAlignment::MiddleRight; |
---|
1895 | Controls->Add(temp_cond); |
---|
1896 | j=20;//depart affichage |
---|
1897 | for (int i=0;i<NB_ETAPES;indexTextBox++,i++,j+=60)//creation des controles dans le formulaire |
---|
1898 | { |
---|
1899 | int posX=90; |
---|
1900 | pal->Add(new CLabelTextBox(Convert::ToString(i+1),posX+j,670,25,16,40)); |
---|
1901 | CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox); |
---|
1902 | if (i<8)//7 etapes et 1 balayage |
---|
1903 | { |
---|
1904 | Controls->Add(cltbPtr->GetLabel()); |
---|
1905 | Controls->Add(cltbPtr->GetTextBox()); |
---|
1906 | } |
---|
1907 | } |
---|
1908 | |
---|
1909 | // status, N_Seqcond, DateD et heureD , DateF et HeureF labels tt seul |
---|
1910 | Label* status= new Label(); |
---|
1911 | status->Location = Point(370, 700); |
---|
1912 | status->Size = System::Drawing::Size(65,16); |
---|
1913 | status->Text = "status";//zone de texte initialisée |
---|
1914 | status->TextAlign = ContentAlignment::MiddleRight; |
---|
1915 | Controls->Add(status); |
---|
1916 | Label* n_seqcond= new Label(); |
---|
1917 | n_seqcond->Location = Point(450, 700); |
---|
1918 | n_seqcond->Size = System::Drawing::Size(65,16); |
---|
1919 | n_seqcond->Text = "N_Seqcond";//zone de texte initialisée |
---|
1920 | n_seqcond->TextAlign = ContentAlignment::MiddleRight; |
---|
1921 | Controls->Add(n_seqcond); |
---|
1922 | Label* dateD= new Label(); |
---|
1923 | dateD->Location = Point(510, 700); |
---|
1924 | dateD->Size = System::Drawing::Size(65,16); |
---|
1925 | dateD->Text = "DateD";//zone de texte initialisée |
---|
1926 | dateD->TextAlign = ContentAlignment::MiddleRight; |
---|
1927 | Controls->Add(dateD); |
---|
1928 | Label* heureD= new Label(); |
---|
1929 | heureD->Location = Point(580, 700); |
---|
1930 | heureD->Size = System::Drawing::Size(65,16); |
---|
1931 | heureD->Text = "HeureD";//zone de texte initialisée |
---|
1932 | heureD->TextAlign = ContentAlignment::MiddleRight; |
---|
1933 | Controls->Add(heureD); |
---|
1934 | Label* dateF= new Label(); |
---|
1935 | dateF->Location = Point(650, 700); |
---|
1936 | dateF->Size = System::Drawing::Size(65,16); |
---|
1937 | dateF->Text = "DateF";//zone de texte initialisée |
---|
1938 | dateF->TextAlign = ContentAlignment::MiddleRight; |
---|
1939 | Controls->Add(dateF); |
---|
1940 | Label* heureF= new Label(); |
---|
1941 | heureF->Location = Point(720, 700); |
---|
1942 | heureF->Size = System::Drawing::Size(65,16); |
---|
1943 | heureF->Text = "HeureF";//zone de texte initialisée |
---|
1944 | heureF->TextAlign = ContentAlignment::MiddleRight; |
---|
1945 | Controls->Add(heureF); |
---|
1946 | j=330;//depart affichage |
---|
1947 | // for (int i=0;indexTextBox<62;indexTextBox++,i++,j+=100)//creation des controles dans le formulaire |
---|
1948 | for (int i=0;i<6;indexTextBox++,i++,j+=70)//creation des controles dans le formulaire |
---|
1949 | { |
---|
1950 | int posX=0; |
---|
1951 | pal->Add(new CLabelTextBox("",posX+j,720,55,16,70)); |
---|
1952 | CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox); |
---|
1953 | Controls->Add(cltbPtr->GetTextBox()); |
---|
1954 | } |
---|
1955 | |
---|
1956 | // Vides label tt seul |
---|
1957 | Label* vides = new Label(); |
---|
1958 | // vides->Location = Point(50, 590); |
---|
1959 | vides->Location = Point(35, 590); |
---|
1960 | // vides->Size = System::Drawing::Size(60,32); |
---|
1961 | vides->Size = System::Drawing::Size(70,40); |
---|
1962 | vides->Text = " Vides (10-10mbar)";//zone de texte initialisée |
---|
1963 | vides->TextAlign = ContentAlignment::MiddleRight; |
---|
1964 | Controls->Add(vides); |
---|
1965 | j=40;//depart affichage |
---|
1966 | for (int i=0;i<(NB_BANCS*3);indexTextBox++,i++,j+=60)//creation des controles dans le formulaire |
---|
1967 | { |
---|
1968 | int posX=70; |
---|
1969 | pal->Add(new CLabelTextBox(nameLab_4[i],posX+j,590,10,16,50)); |
---|
1970 | CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox); |
---|
1971 | Controls->Add(cltbPtr->GetLabel()); |
---|
1972 | Controls->Add(cltbPtr->GetTextBox()); |
---|
1973 | } |
---|
1974 | |
---|
1975 | // Prc label tt seul |
---|
1976 | Label* prc = new Label(); |
---|
1977 | prc->Location = Point(50, 430); |
---|
1978 | prc->Size = System::Drawing::Size(50,32); |
---|
1979 | prc->Text = "Prc (kW)";//zone de texte initialisée |
---|
1980 | prc->TextAlign = ContentAlignment::MiddleRight; |
---|
1981 | Controls->Add(prc); |
---|
1982 | j=100;//depart affichage |
---|
1983 | for (int i=0;i<NB_BANCS;indexTextBox++,i++,j+=180)//creation des controles dans le formulaire |
---|
1984 | { |
---|
1985 | int posX=70; |
---|
1986 | pal->Add(new CLabelTextBox(nameLab_3[i],posX+j,430,10,16,50)); |
---|
1987 | CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox); |
---|
1988 | Controls->Add(cltbPtr->GetLabel()); |
---|
1989 | Controls->Add(cltbPtr->GetTextBox()); |
---|
1990 | } |
---|
1991 | |
---|
1992 | // Pic label tt seul |
---|
1993 | Label* pic = new Label(); |
---|
1994 | pic->Location = Point(50, 470); |
---|
1995 | pic->Size = System::Drawing::Size(50,32); |
---|
1996 | pic->Text = "Pic (kW)";//zone de texte initialisée |
---|
1997 | pic->TextAlign = ContentAlignment::MiddleRight; |
---|
1998 | Controls->Add(pic); |
---|
1999 | j=100;//depart affichage |
---|
2000 | for (int i=0;i<NB_BANCS;indexTextBox++,i++,j+=180)//creation des controles dans le formulaire |
---|
2001 | { |
---|
2002 | int posX=70; |
---|
2003 | pal->Add(new CLabelTextBox(nameLab_3[i],posX+j,470,10,16,50)); |
---|
2004 | CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox); |
---|
2005 | Controls->Add(cltbPtr->GetLabel()); |
---|
2006 | Controls->Add(cltbPtr->GetTextBox()); |
---|
2007 | } |
---|
2008 | |
---|
2009 | // Pch label tt seul |
---|
2010 | Label* pch = new Label(); |
---|
2011 | pch->Location = Point(50, 510); |
---|
2012 | pch->Size = System::Drawing::Size(50,32); |
---|
2013 | pch->Text = "Pch (kW)";//zone de texte initialisée |
---|
2014 | pch->TextAlign = ContentAlignment::MiddleRight; |
---|
2015 | Controls->Add(pch); |
---|
2016 | j=100;//depart affichage |
---|
2017 | for (int i=0;i<NB_BANCS;indexTextBox++,i++,j+=180)//creation des controles dans le formulaire |
---|
2018 | { |
---|
2019 | int posX=70; |
---|
2020 | pal->Add(new CLabelTextBox(nameLab_3[i],posX+j,510,10,16,50)); |
---|
2021 | CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox); |
---|
2022 | Controls->Add(cltbPtr->GetLabel()); |
---|
2023 | Controls->Add(cltbPtr->GetTextBox()); |
---|
2024 | } |
---|
2025 | |
---|
2026 | // Ie_cur label tt seul |
---|
2027 | Label* ie_cur = new Label(); |
---|
2028 | ie_cur->Location = Point(50, 550); |
---|
2029 | ie_cur->Size = System::Drawing::Size(50,32); |
---|
2030 | ie_cur->Text = "Ie_cur (V)";//zone de texte initialisée |
---|
2031 | ie_cur->TextAlign = ContentAlignment::MiddleRight; |
---|
2032 | Controls->Add(ie_cur); |
---|
2033 | j=100;//depart affichage |
---|
2034 | for (int i=0;i<NB_BANCS;indexTextBox++,i++,j+=180)//creation des controles dans le formulaire |
---|
2035 | { |
---|
2036 | int posX=70; |
---|
2037 | pal->Add(new CLabelTextBox(nameLab_3[i],posX+j,550,10,16,50)); |
---|
2038 | CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox); |
---|
2039 | Controls->Add(cltbPtr->GetLabel()); |
---|
2040 | Controls->Add(cltbPtr->GetTextBox()); |
---|
2041 | } |
---|
2042 | |
---|
2043 | // Num_P label tt seul |
---|
2044 | Label* num_P = new Label(); |
---|
2045 | num_P->Location = Point(50, 350); |
---|
2046 | num_P->Size = System::Drawing::Size(50,32); |
---|
2047 | num_P->Text = "Num_P";//zone de texte initialisée |
---|
2048 | num_P->TextAlign = ContentAlignment::MiddleRight; |
---|
2049 | Controls->Add(num_P); |
---|
2050 | j=100;//depart affichage |
---|
2051 | for (int i=0;i<NB_BANCS;indexTextBox++,i++,j+=180)//creation des controles dans le formulaire |
---|
2052 | { |
---|
2053 | int posX=70; |
---|
2054 | pal->Add(new CLabelTextBox(nameLab_3[i],posX+j,350,10,16,50)); |
---|
2055 | CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox); |
---|
2056 | Controls->Add(cltbPtr->GetLabel()); |
---|
2057 | Controls->Add(cltbPtr->GetTextBox()); |
---|
2058 | } |
---|
2059 | /* |
---|
2060 | // crée un objet graphique |
---|
2061 | Graphics* pg = this->CreateGraphics(); |
---|
2062 | //crée un objet pen |
---|
2063 | Pen* pen1 = new Pen(Color::Red); |
---|
2064 | //trace une ligne |
---|
2065 | pg->DrawLine(pen1,20,20,100,100); |
---|
2066 | //dispose l'objet Graphics |
---|
2067 | pg->Dispose(); |
---|
2068 | */ |
---|
2069 | // ajout du groupe dans le formulaire. |
---|
2070 | Controls->Add(gboxC); |
---|
2071 | |
---|
2072 | /* |
---|
2073 | // associe le gestionnaire au groupe d'options |
---|
2074 | rb1->Click += new EventHandler(this, &MaDialogUser::Radio_Clicked); |
---|
2075 | rb2->Click += new EventHandler(this, &MaDialogUser::Radio_Clicked); |
---|
2076 | */ } |
---|
2077 | |
---|
2078 | void MaDialogUser::Setup_Buttons_Conditionning()//creation et definition des boutons |
---|
2079 | { |
---|
2080 | // ajoute bouton START |
---|
2081 | btnStart = new Button(); |
---|
2082 | btnStart->Text = S"MARCHE";//se sert de sa propriété Text pour definir son titre |
---|
2083 | btnStart->Size = System::Drawing::Size(70, 20);//taille du bouton en pixels |
---|
2084 | btnStart->Location = Point(70, 720);//emplacement |
---|
2085 | btnStart->Click += new EventHandler(this, &MaDialogUser::BtnStart_Clicked);//creation d'un objet EventHandler en.. |
---|
2086 | //..lui transmettant un ptr sur le bouotn et l'adresse de la fonction en charge de.. |
---|
2087 | //..l'evenement |
---|
2088 | Controls->Add(btnStart);//pour avertir le formulaire de la présence du bouton, on ajoute le bouton.. |
---|
2089 | //.. dans la collection des controles du formulaire |
---|
2090 | |
---|
2091 | // idem bouton STOP |
---|
2092 | btnStop = new Button(); |
---|
2093 | btnStop->Text = S"ARRET"; |
---|
2094 | btnStop->Size = System::Drawing::Size(70, 20); |
---|
2095 | btnStop->Location = Point(150, 720); |
---|
2096 | btnStop->Click += new EventHandler(this, &MaDialogUser::BtnStop_Clicked); |
---|
2097 | Controls->Add(btnStop); |
---|
2098 | |
---|
2099 | // idem bouton PAUSE |
---|
2100 | btnPause = new Button(); |
---|
2101 | btnPause->Text = S"PAUSE"; |
---|
2102 | btnPause->Size = System::Drawing::Size(70, 20); |
---|
2103 | btnPause->Location = Point(230, 720); |
---|
2104 | // btnPause->Click += new EventHandler(this, &MaDialogUser::BtnPause_Clicked); |
---|
2105 | // Controls->Add(btnPause); |
---|
2106 | |
---|
2107 | // idem bouton REPRISE |
---|
2108 | btnReprise = new Button(); |
---|
2109 | btnReprise->Text = S"REPRISE"; |
---|
2110 | btnReprise->Size = System::Drawing::Size(70, 20); |
---|
2111 | btnReprise->Location = Point(310, 720); |
---|
2112 | btnReprise->Click += new EventHandler(this, &MaDialogUser::BtnReprise_Clicked); |
---|
2113 | Controls->Add(btnReprise); |
---|
2114 | } |
---|
2115 | |
---|
2116 | void MaDialogUser::Radio_Clicked(Object* pSender, EventArgs* pArgs)//remplit automatiquement la zone de texte |
---|
2117 | { |
---|
2118 | if (pSender == rb1) |
---|
2119 | { |
---|
2120 | Console::WriteLine(S"MaDialogUser::Radio_Clicked : lecture activée..."); |
---|
2121 | Console::WriteLine(S"Main thread: Start a second thread."); |
---|
2122 | // Create the thread, passing a ThreadStart delegate that |
---|
2123 | // represents the ThreadReadModbus::ThreadProc method. |
---|
2124 | if (uThread==NULL) |
---|
2125 | { |
---|
2126 | uThread = new Thread(new ThreadStart(0, &MaDialogUser::ThreadProc)); |
---|
2127 | // Start the thread. |
---|
2128 | uThread->Start(); |
---|
2129 | } |
---|
2130 | } |
---|
2131 | else if (pSender == rb2) |
---|
2132 | { |
---|
2133 | Console::WriteLine(S"MaDialogUser::Radio_Clicked : lecture désactivée..."); |
---|
2134 | if ((uThread!=NULL)&&(uThread->IsAlive)) |
---|
2135 | { |
---|
2136 | // Stop the thread. |
---|
2137 | uThread->Suspend(); |
---|
2138 | uThread=NULL; |
---|
2139 | } |
---|
2140 | } |
---|
2141 | } |
---|
2142 | |
---|
2143 | void MaDialogUser::BtnStart_Clicked(Object* pSender, EventArgs* pArgs)//gestionnaire d'evenements associés au bouton 1 |
---|
2144 | { |
---|
2145 | // MessageBox::Show(S"ça marche!", S"bouton START...");//MessageBox fait partie de l'espace de noms Forms |
---|
2146 | //unique methode Show surchargée acceptant differents parametres |
---|
2147 | CLabelTextBox* cltbPtr; |
---|
2148 | for (int indexArrayList=0;(indexArrayList<MAX_NB_LABEL_TEXTBOX);indexArrayList++)//on cherche le LabelBox "MODE" |
---|
2149 | { |
---|
2150 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList); |
---|
2151 | if(String::Compare(cltbPtr->GetName(),"MODE")) |
---|
2152 | break;//on y est |
---|
2153 | if(indexArrayList==(MAX_NB_LABEL_TEXTBOX-1))return;//il faut sortir si non trouvé |
---|
2154 | } |
---|
2155 | if(String::Compare(cltbPtr->GetVal(),"PULSING")) |
---|
2156 | { |
---|
2157 | uint16_t tab_rp_registers[1] = { 0x2 }; |
---|
2158 | Console::WriteLine(S"MaDialogUser::BtnStart_Clicked : write holding..."); |
---|
2159 | int rc = modbus_write_registers(ctx, 2048,1 , tab_rp_registers); |
---|
2160 | if (rc != 1) |
---|
2161 | Console::WriteLine(S"MaDialogUser::BtnStart_Clicked : write holding failed..."); |
---|
2162 | } |
---|
2163 | } |
---|
2164 | |
---|
2165 | void MaDialogUser::BtnStop_Clicked(Object* pSender, EventArgs* pArgs)//gestionnaire d'evenements associés au bouton 1 |
---|
2166 | { |
---|
2167 | // MessageBox::Show(S"ça marche!", S"bouton STOP...");//MessageBox fait partie de l'espace de noms Forms |
---|
2168 | //unique methode Show surchargée acceptant differents parametres |
---|
2169 | CLabelTextBox* cltbPtr; |
---|
2170 | for (int indexArrayList=0;(indexArrayList<MAX_NB_LABEL_TEXTBOX);indexArrayList++)//on cherche le LabelBox "MODE" |
---|
2171 | { |
---|
2172 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList); |
---|
2173 | if(String::Compare(cltbPtr->GetName(),"MODE")) |
---|
2174 | break;//on y est |
---|
2175 | if(indexArrayList==(MAX_NB_LABEL_TEXTBOX-1))return;//il faut sortir si non trouvé |
---|
2176 | } |
---|
2177 | if(String::Compare(cltbPtr->GetVal(),"PULSING")) |
---|
2178 | { |
---|
2179 | uint16_t tab_rp_registers[1] = { 0x0 }; |
---|
2180 | Console::WriteLine(S"MaDialogUser::BtnStart_Clicked : write holding..."); |
---|
2181 | int rc = modbus_write_registers(ctx, 2048,1 , tab_rp_registers); |
---|
2182 | if (rc != 1) |
---|
2183 | Console::WriteLine(S"MaDialogUser::BtnStart_Clicked : write holding failed..."); |
---|
2184 | } |
---|
2185 | } |
---|
2186 | |
---|
2187 | void MaDialogUser::BtnPause_Clicked(Object* pSender, EventArgs* pArgs)//gestionnaire d'evenements associés au bouton 1 |
---|
2188 | { |
---|
2189 | // MessageBox::Show(S"ça marche!", S"bouton PAUSE...");//MessageBox fait partie de l'espace de noms Forms |
---|
2190 | //unique methode Show surchargée acceptant differents parametres |
---|
2191 | CLabelTextBox* cltbPtr; |
---|
2192 | for (int indexArrayList=0;(indexArrayList<MAX_NB_LABEL_TEXTBOX);indexArrayList++)//on cherche le LabelBox "MODE" |
---|
2193 | { |
---|
2194 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList); |
---|
2195 | if(String::Compare(cltbPtr->GetName(),"MODE")) |
---|
2196 | break;//on y est |
---|
2197 | if(indexArrayList==(MAX_NB_LABEL_TEXTBOX-1))return;//il faut sortir si non trouvé |
---|
2198 | } |
---|
2199 | if(String::Compare(cltbPtr->GetVal(),"PULSING")) |
---|
2200 | { |
---|
2201 | uint16_t tab_rp_registers[1] = { 0x1 }; |
---|
2202 | Console::WriteLine(S"MaDialogUser::BtnStart_Clicked : write holding..."); |
---|
2203 | int rc = modbus_write_registers(ctx, 2048,1 , tab_rp_registers); |
---|
2204 | if (rc != 1) |
---|
2205 | Console::WriteLine(S"MaDialogUser::BtnStart_Clicked : write holding failed..."); |
---|
2206 | } |
---|
2207 | } |
---|
2208 | |
---|
2209 | void MaDialogUser::BtnReprise_Clicked(Object* pSender, EventArgs* pArgs)//gestionnaire d'evenements associés au bouton 1 |
---|
2210 | { |
---|
2211 | // MessageBox::Show(S"ça marche!", S"bouton REPRISE...");//MessageBox fait partie de l'espace de noms Forms |
---|
2212 | //unique methode Show surchargée acceptant differents parametres |
---|
2213 | CLabelTextBox* cltbPtr; |
---|
2214 | for (int indexArrayList=0;(indexArrayList<MAX_NB_LABEL_TEXTBOX);indexArrayList++)//on cherche le LabelBox "MODE" |
---|
2215 | { |
---|
2216 | cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList); |
---|
2217 | if(String::Compare(cltbPtr->GetName(),"MODE")) |
---|
2218 | break;//on y est |
---|
2219 | if(indexArrayList==(MAX_NB_LABEL_TEXTBOX-1))return;//il faut sortir si non trouvé |
---|
2220 | } |
---|
2221 | if(String::Compare(cltbPtr->GetVal(),"PULSING")) |
---|
2222 | { |
---|
2223 | uint16_t tab_rp_registers[1] = { 0x3 }; |
---|
2224 | Console::WriteLine(S"MaDialogUser::BtnStart_Clicked : write holding..."); |
---|
2225 | int rc = modbus_write_registers(ctx, 2048,1 , tab_rp_registers); |
---|
2226 | if (rc != 1) |
---|
2227 | Console::WriteLine(S"MaDialogUser::BtnStart_Clicked : write holding failed..."); |
---|
2228 | } |
---|
2229 | } |
---|
2230 | |
---|
2231 | |
---|
2232 | void AboutBox::OKButton_Clicked(Object* pSender,EventArgs* pArgs)//gestionnaire d'evenement de la boite dialogue |
---|
2233 | { |
---|
2234 | //se contente de fermer le formulaire lorsqu'on clique sur le bouton |
---|
2235 | Close(); |
---|
2236 | } |
---|
2237 | |
---|
2238 | AboutBox::AboutBox()//constructeur |
---|
2239 | { |
---|
2240 | // qqs propriétés |
---|
2241 | Text = S"A propos cxfel"; |
---|
2242 | FormBorderStyle = FormBorderStyle::Fixed3D;//impossible de modifier la taille |
---|
2243 | Size = System::Drawing::Size(300,150); |
---|
2244 | |
---|
2245 | // ajout de 2 labels au formulaire. |
---|
2246 | Label* label1 = new Label(); |
---|
2247 | label1->Text = "Application client XFEL"; |
---|
2248 | label1->Size = System::Drawing::Size(label1->PreferredWidth, |
---|
2249 | label1->PreferredHeight); |
---|
2250 | label1->Location = Point(20, 30); |
---|
2251 | |
---|
2252 | Label* label2 = new Label(); |
---|
2253 | label2->Text = "JC Marrucho, 2013"; |
---|
2254 | label2->Size = System::Drawing::Size(label1->PreferredWidth, |
---|
2255 | label1->PreferredHeight);//sert à modifier auto la taille des labels.. |
---|
2256 | //..selon le texte |
---|
2257 | label2->Location = Point(20, 30+label1->PreferredHeight+10);//sert à calculer la position du 2ème label |
---|
2258 | |
---|
2259 | // Ajoute les controles dans le formulaire |
---|
2260 | Controls->Add(label1); |
---|
2261 | Controls->Add(label2); |
---|
2262 | |
---|
2263 | // Ajout d'un bouton OK. |
---|
2264 | OKButton = new Button(); |
---|
2265 | OKButton->Text = S"OK"; |
---|
2266 | OKButton->DialogResult = System::Windows::Forms::DialogResult::OK;//renvoi de la valeur OK.. |
---|
2267 | //.. plus besoin d'associer le gestionnaire à sa fonction.. voir plus bas |
---|
2268 | OKButton->Size = System::Drawing::Size(40,25); |
---|
2269 | OKButton->Location = Point(240,85); |
---|
2270 | |
---|
2271 | //configure un gestionnaire : pas nécessaire si le formulaire renvoie une valeur.. voir + haut |
---|
2272 | //OKButton->Click += new EventHandler(this,&AboutBox::OKButton_Clicked); |
---|
2273 | |
---|
2274 | // Ajoute le bouton au formulaire. |
---|
2275 | Controls->Add(OKButton); |
---|
2276 | } |
---|
2277 | |
---|
2278 | |
---|
2279 | MaDialog::MaDialog() |
---|
2280 | { |
---|
2281 | // définit les paramètres du formulaire |
---|
2282 | Text = S"détails serveur"; |
---|
2283 | FormBorderStyle = FormBorderStyle::Fixed3D;//impossible de modifier la taille |
---|
2284 | Size = System::Drawing::Size(280,200); |
---|
2285 | |
---|
2286 | // Creation de tous les controles : TextBox pour io/port et ComboBox pour timeout |
---|
2287 | ipLabel = new Label(); |
---|
2288 | ipBox = new TextBox(); |
---|
2289 | portLabel = new Label(); |
---|
2290 | portBox = new TextBox(); |
---|
2291 | timeoutLabel = new Label(); |
---|
2292 | timeoutCombo = new ComboBox(); |
---|
2293 | OKBtn = new Button(); |
---|
2294 | CancelBtn = new Button(); |
---|
2295 | |
---|
2296 | // ipLabel et ipBox : label et zone de saisie sont placés l'un à côté de l'autre |
---|
2297 | ipLabel->Location = Point(16, 24); |
---|
2298 | ipLabel->Size = System::Drawing::Size(48, 16); |
---|
2299 | ipLabel->Text = "n°IP:";//zone de texte initialisée vide |
---|
2300 | ipLabel->TextAlign = ContentAlignment::MiddleRight; |
---|
2301 | ipBox->Location = Point(72, 24); |
---|
2302 | ipBox->Size = System::Drawing::Size(152, 20); |
---|
2303 | ipBox->Text = "";//zone de texte initialisée vide |
---|
2304 | |
---|
2305 | // portLabel et portBox |
---|
2306 | portLabel->Location = Point(16, 56); |
---|
2307 | portLabel->Size = System::Drawing::Size(48, 16); |
---|
2308 | portLabel->Text = "n°port:";//zone de texte initialisée vide |
---|
2309 | portLabel->TextAlign = ContentAlignment::MiddleRight; |
---|
2310 | portBox->Location = Point(72, 56); |
---|
2311 | portBox->Size = System::Drawing::Size(152, 20); |
---|
2312 | portBox->Text = "";//zone de texte initialisée |
---|
2313 | |
---|
2314 | // timeoutLabel et timeoutCombo : : liste déroulante spécifiant le tiemout et son label |
---|
2315 | timeoutLabel->Location = Point(16, 88); |
---|
2316 | timeoutLabel->Size = System::Drawing::Size(48, 16); |
---|
2317 | timeoutLabel->Text = "Timeout(ms):"; |
---|
2318 | timeoutLabel->TextAlign = ContentAlignment::MiddleRight; |
---|
2319 | timeoutCombo->DropDownWidth = 121; |
---|
2320 | timeoutCombo->Location = Point(72, 88); |
---|
2321 | timeoutCombo->Size = System::Drawing::Size(121, 21); |
---|
2322 | //5 items, pas de valeur par défaut |
---|
2323 | timeoutCombo->Items->Add(S"500"); |
---|
2324 | timeoutCombo->Items->Add(S"1000"); |
---|
2325 | timeoutCombo->Items->Add(S"1500"); |
---|
2326 | timeoutCombo->Items->Add(S"2000"); |
---|
2327 | timeoutCombo->Items->Add(S"3000"); |
---|
2328 | |
---|
2329 | // bouton OK |
---|
2330 | OKBtn->Location = Point(104, 136); |
---|
2331 | OKBtn->Name = "Bouton OK"; |
---|
2332 | OKBtn->Text = "OK"; |
---|
2333 | OKBtn->DialogResult = DialogResult::OK; |
---|
2334 | |
---|
2335 | // bouton Cancel |
---|
2336 | CancelBtn->Location = Point(192, 136); |
---|
2337 | CancelBtn->Name = "Bouton Annuler"; |
---|
2338 | CancelBtn->Text = "Annuler"; |
---|
2339 | CancelBtn->DialogResult = DialogResult::Cancel; |
---|
2340 | |
---|
2341 | // Ajoute les controles dans le formaulaire |
---|
2342 | Controls->Add(ipBox); |
---|
2343 | Controls->Add(portBox); |
---|
2344 | Controls->Add(ipLabel); |
---|
2345 | Controls->Add(portLabel); |
---|
2346 | Controls->Add(timeoutLabel); |
---|
2347 | Controls->Add(timeoutCombo); |
---|
2348 | Controls->Add(OKBtn); |
---|
2349 | Controls->Add(CancelBtn); |
---|
2350 | |
---|
2351 | //configure les 2 propriétés : AcceptButton contient la réf du bouton par défaut du formulaire.. |
---|
2352 | //..on peut cliquer sur le bouton OK ou bien sur la touche Entrée du clavier.. |
---|
2353 | //..referme aussi la boite car DialogResult renvoie OK |
---|
2354 | AcceptButton = OKBtn; |
---|
2355 | //CancelButton contient la réf du bouton associée à la touche Echap du clavier |
---|
2356 | CancelButton = CancelBtn; |
---|
2357 | |
---|
2358 | //gestionnnaire associé au bouton OK |
---|
2359 | OKBtn->Click += new EventHandler(this, &MaDialog::OKMaDBtn_Clicked); |
---|
2360 | } |
---|
2361 | |
---|
2362 | void MaDialog::OKMaDBtn_Clicked(Object* pSender,EventArgs* pArgs)//gestionnaire d'evenement de la boite dialogue |
---|
2363 | { |
---|
2364 | //se contente de fermer le formulaire lorsqu'on clique sur le bouton |
---|
2365 | Close(); |
---|
2366 | } |
---|
2367 | |
---|
2368 | void MaDialog::setIp(String* theIp) |
---|
2369 | { |
---|
2370 | ipBox->Text = theIp; |
---|
2371 | } |
---|
2372 | |
---|
2373 | String* MaDialog::getIp() |
---|
2374 | { |
---|
2375 | return ipBox->Text; |
---|
2376 | } |
---|
2377 | |
---|
2378 | void MaDialog::setPort(String* thePort) |
---|
2379 | { |
---|
2380 | portBox->Text = thePort; |
---|
2381 | } |
---|
2382 | |
---|
2383 | String* MaDialog::getPort() |
---|
2384 | { |
---|
2385 | return portBox->Text; |
---|
2386 | } |
---|
2387 | |
---|
2388 | void MaDialog::setTimeout(int theTimeout) |
---|
2389 | { |
---|
2390 | timeoutCombo->SelectedIndex = theTimeout; |
---|
2391 | } |
---|
2392 | |
---|
2393 | int MaDialog::getTimeout() |
---|
2394 | { |
---|
2395 | return timeoutCombo->SelectedIndex; |
---|
2396 | } |
---|
2397 | |
---|
2398 | |
---|
2399 | CppForm::CppForm()//constructeur |
---|
2400 | { |
---|
2401 | // définit la légende du formulaire |
---|
2402 | //la propriété Text est héritée de Control |
---|
2403 | Text = S"XSUC"; |
---|
2404 | |
---|
2405 | // définit le style des bords |
---|
2406 | //la propriété FormBorder est membre de Form |
---|
2407 | FormBorderStyle = FormBorderStyle::Fixed3D; |
---|
2408 | |
---|
2409 | // Set up controls on the form. |
---|
2410 | Setup_Menu(); |
---|
2411 | Setup_Context_Menu(); |
---|
2412 | Setup_Buttons();//configure les boutons du formulaire |
---|
2413 | Setup_Label(); |
---|
2414 | // Setup_Group(); |
---|
2415 | // Setup_Combo(); |
---|
2416 | Setup_Text(); |
---|
2417 | |
---|
2418 | // pour agrandir la zone de saisie, on rajoute des pixels, par defaut 300x300 |
---|
2419 | // Size = System::Drawing::Size(450, 300); |
---|
2420 | Size = System::Drawing::Size(650, 500); |
---|
2421 | |
---|
2422 | } |
---|
2423 | |
---|
2424 | void CppForm::Btn1_Clicked(Object* pSender, EventArgs* pArgs)//gestionnaire d'evenements associés au bouton 1 |
---|
2425 | { |
---|
2426 | MessageBox::Show(S"ça marche!", S"A FAIRE...");//MessageBox fait partie de l'espace de noms Forms |
---|
2427 | //unique methode Show surchargée acceptant differents parametres |
---|
2428 | } |
---|
2429 | |
---|
2430 | void CppForm::Btn2_Clicked(Object* pSender, EventArgs* pArgs)//gestionnaire d'evenements associés au bouton 2 |
---|
2431 | { |
---|
2432 | MessageBox::Show(S"ça marche aussi!", S"A FAIRE...");//MessageBox fait partie de l'espace de noms Forms |
---|
2433 | //unique methode Show surchargée acceptant differents parametres |
---|
2434 | } |
---|
2435 | |
---|
2436 | void CppForm::Btn3_Clicked(Object* pSender, EventArgs* pArgs)//gestionnaire d'evenements associés au bouton 3 |
---|
2437 | { |
---|
2438 | MessageBox::Show(S"connexion et lecture serveur", S"A FAIRE...");//MessageBox fait partie de l'espace de noms Forms |
---|
2439 | //unique methode Show surchargée acceptant differents parametres |
---|
2440 | } |
---|
2441 | |
---|
2442 | void CppForm::Btn4_Clicked(Object* pSender, EventArgs* pArgs)//gestionnaire d'evenements associés au bouton 4 |
---|
2443 | { |
---|
2444 | /* uint16_t tab_rp_registers_low[MODBUS_SIZE_READ_HOLDINGS_LOW]; |
---|
2445 | uint16_t tab_rp_registers_high[MODBUS_SIZE_READ_HOLDINGS_HIGH]; |
---|
2446 | int rc, adress, size; |
---|
2447 | Console::WriteLine(S"ThreadProc: read holdings..."); |
---|
2448 | adress=MODBUS_BASE_LOW_HOLDINGS;//adresse holding=MODBUS_BASE_LOW_HOLDINGS |
---|
2449 | size=82; |
---|
2450 | rc = modbus_read_registers(ctx, adress, size, tab_rp_registers_low); |
---|
2451 | if (rc != size) |
---|
2452 | Console::WriteLine(S"ThreadProc: read holdings failed..."); |
---|
2453 | Thread::Sleep(500); |
---|
2454 | Console::WriteLine(S"ThreadProc: read holdings..."); |
---|
2455 | adress=MODBUS_BASEADR_HIGH_HOLDINGS;//adresse holding=MODBUS_BASEADR_HIGH_HOLDINGS |
---|
2456 | size=MODBUS_SIZE_READ_HOLDINGS_HIGH; |
---|
2457 | rc = modbus_read_registers(ctx, adress, size, tab_rp_registers_high); |
---|
2458 | if (rc != size) |
---|
2459 | Console::WriteLine(S"ThreadProc: read holdings failed..."); |
---|
2460 | */ |
---|
2461 | //crée la boite de dialogue utilisateur |
---|
2462 | CDialogConfig* box = new CDialogConfig(); |
---|
2463 | //affiche la boite de dialogue |
---|
2464 | if (box->ShowDialog() == DialogResult::OK) |
---|
2465 | { |
---|
2466 | //si la valeur OK est renvoyée, on affiche le nom |
---|
2467 | //MessageBox::Show(S"Ecriture"); |
---|
2468 | } |
---|
2469 | //unique methode Show surchargée acceptant differents parametres |
---|
2470 | } |
---|
2471 | |
---|
2472 | void CppForm::Combo1_SelChanged(Object* pSender, EventArgs* pArgs)//gestionnaire d'evenement associé à la liste deroulante |
---|
2473 | { |
---|
2474 | if (pSender == combo1) |
---|
2475 | { |
---|
2476 | // String* ps = String::Concat(S"New index is ", |
---|
2477 | // __box(combo1->SelectedIndex)->ToString()); |
---|
2478 | // MessageBox::Show(ps, S"Index Change"); |
---|
2479 | String* ps = __box(combo1->SelectedIndex)->ToString(); |
---|
2480 | if(String::Compare(ps,"1")==0) |
---|
2481 | { |
---|
2482 | Console::WriteLine(S"Main thread: Start a second thread."); |
---|
2483 | // Create the thread, passing a ThreadStart delegate that |
---|
2484 | // represents the ThreadReadModbus::ThreadProc method. |
---|
2485 | Thread *oThread = new Thread(new ThreadStart(0, &ThreadReadModbus::ThreadProc)); |
---|
2486 | // Start the thread. |
---|
2487 | oThread->Start(); |
---|
2488 | } |
---|
2489 | } |
---|
2490 | } |
---|
2491 | |
---|
2492 | void CppForm::MenuItem_Clicked(Object* pSender, EventArgs* pArgs)//gestionnaire des elements de menu |
---|
2493 | { |
---|
2494 | if (pSender == item1) |
---|
2495 | { |
---|
2496 | //affiche la boite de dialogue modale qui doit etre fermée avant de pouvoir revenir à l'application |
---|
2497 | // MessageBox::Show(S"ITEM à propos", S"Menu"); |
---|
2498 | AboutBox* box = new AboutBox(); |
---|
2499 | box->ShowDialog(); |
---|
2500 | } |
---|
2501 | else if (pSender == item2) |
---|
2502 | { |
---|
2503 | // Exit application. |
---|
2504 | Application::Exit(); |
---|
2505 | } |
---|
2506 | else if (pSender == item11) |
---|
2507 | { |
---|
2508 | //crée la boite de dialogue |
---|
2509 | MaDialog* box = new MaDialog(); |
---|
2510 | //données initiales |
---|
2511 | /* String* path = new String("c:\\temp\\condip.txt.txt"); |
---|
2512 | if (!File::Exists(path)) |
---|
2513 | { |
---|
2514 | Console::WriteLine("le fichier n'existe pas!"); |
---|
2515 | } |
---|
2516 | */ |
---|
2517 | //lecture du n°IP dans le fichier condip |
---|
2518 | try |
---|
2519 | { |
---|
2520 | FileStream* fs = new FileStream("..\\condip.txt",FileMode::Open); |
---|
2521 | StreamReader* sr = new StreamReader(fs); |
---|
2522 | String* line = sr->ReadLine(); |
---|
2523 | box->setIp(line); |
---|
2524 | sr->Close; |
---|
2525 | fs->Flush(); |
---|
2526 | fs->Close(); |
---|
2527 | } |
---|
2528 | catch (System::Exception* pe) |
---|
2529 | { |
---|
2530 | Console::WriteLine(pe->ToString()); |
---|
2531 | } |
---|
2532 | // box->setIp(S"134.158.91.254"); |
---|
2533 | box->setPort(S"502"); |
---|
2534 | box->setTimeout(1); |
---|
2535 | |
---|
2536 | //affiche la boite de dialogue |
---|
2537 | if (box->ShowDialog() == DialogResult::OK) |
---|
2538 | { |
---|
2539 | //si la valeur OK est renvoyée, on affiche le nom |
---|
2540 | MessageBox::Show(box->getIp(), S"IP du serveur"); |
---|
2541 | } |
---|
2542 | |
---|
2543 | } |
---|
2544 | else if (pSender == anotherItem) |
---|
2545 | { |
---|
2546 | //crée la boite de dialogue utilisateur |
---|
2547 | MaDialogUser* box = new MaDialogUser(); |
---|
2548 | //données initiales |
---|
2549 | /* box->setIp(S"134.158.91.254"); |
---|
2550 | box->setPort(S"502"); |
---|
2551 | box->setTimeout(1); |
---|
2552 | */ //affiche la boite de dialogue |
---|
2553 | if (box->ShowDialog() == DialogResult::OK) |
---|
2554 | { |
---|
2555 | //si la valeur OK est renvoyée, on affiche le nom |
---|
2556 | // MessageBox::Show(S"Lecture"); |
---|
2557 | } |
---|
2558 | } |
---|
2559 | else if (pSender == item1_1 || pSender == item1_2) |
---|
2560 | { |
---|
2561 | // modbus_t *ctx; |
---|
2562 | if(pSender == item1_1) |
---|
2563 | { |
---|
2564 | // ctx = (modbus_t *) malloc(sizeof(modbus_t)); |
---|
2565 | // Ex20cSquareRoot(4); |
---|
2566 | // char* ptr = GetHeure(1); |
---|
2567 | /* String* psone = String::Concat(S"il est ", GetHeure(1)); |
---|
2568 | MessageBox::Show(psone, S"heure"); |
---|
2569 | int* monInt = allou(); |
---|
2570 | int taille=sizeof(monInt); |
---|
2571 | Console::WriteLine(taille); |
---|
2572 | libere(monInt); |
---|
2573 | */ |
---|
2574 | //lecture du n°IP dans le fichier condip |
---|
2575 | String* lineIp; |
---|
2576 | try |
---|
2577 | { |
---|
2578 | FileStream* fs = new FileStream("..\\condip.txt",FileMode::Open); |
---|
2579 | StreamReader* sr = new StreamReader(fs); |
---|
2580 | lineIp = sr->ReadLine(); |
---|
2581 | sr->Close; |
---|
2582 | fs->Flush(); |
---|
2583 | fs->Close(); |
---|
2584 | } |
---|
2585 | catch (System::Exception* pe) |
---|
2586 | { |
---|
2587 | Console::WriteLine(pe->ToString()); |
---|
2588 | } |
---|
2589 | |
---|
2590 | Console::WriteLine(S"CppForm::MenuItem_Clicked : modbus_new_tcp..."); |
---|
2591 | // ctx = modbus_new_tcp("134.158.91.254", 502);//JCM |
---|
2592 | char* chaineChar = static_cast<char *>(System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(lineIp).ToPointer()); |
---|
2593 | ctx = modbus_new_tcp(chaineChar,502);//JCM |
---|
2594 | modbus_set_debug(ctx, 1); |
---|
2595 | // modbus_set_error_recovery(ctx, |
---|
2596 | // MODBUS_ERROR_RECOVERY_LINK | |
---|
2597 | // MODBUS_ERROR_RECOVERY_PROTOCOL); |
---|
2598 | modbus_set_slave(ctx,1);//JCM: avec le serveur python slave=1 |
---|
2599 | if (modbus_connect(ctx) == -1) { |
---|
2600 | Console::WriteLine(modbus_strerror(errno)); |
---|
2601 | modbus_free(ctx); |
---|
2602 | } |
---|
2603 | } |
---|
2604 | else |
---|
2605 | { |
---|
2606 | modbus_free(ctx); |
---|
2607 | } |
---|
2608 | } |
---|
2609 | else if (pSender == fontDlgItem) |
---|
2610 | { |
---|
2611 | FontDialog* fd = new FontDialog(); |
---|
2612 | fd->Font = labelFont; |
---|
2613 | |
---|
2614 | if (fd->ShowDialog() == DialogResult::OK)//la police du label est modifiée selon le choix d el'uitlisateur |
---|
2615 | { |
---|
2616 | MessageBox::Show(fd->Font->Name, S"la police était..."); |
---|
2617 | labelFont = fd->Font; |
---|
2618 | theLabel->Font = labelFont; |
---|
2619 | } |
---|
2620 | } |
---|
2621 | else |
---|
2622 | MessageBox::Show(S"AUTRE ITEM", S"Menu"); |
---|
2623 | } |
---|
2624 | |
---|
2625 | void CppForm::Radio_Clicked(Object* pSender, EventArgs* pArgs)//remplit automatiquement la zone de texte |
---|
2626 | { |
---|
2627 | if (pSender == rb1) |
---|
2628 | { |
---|
2629 | text1->Text = "Read Coils choisi : \r\n\r\n" |
---|
2630 | "FC01"; |
---|
2631 | uint8_t tab_rp_bits[1]; |
---|
2632 | int rc = modbus_read_bits(ctx, MODBUS_BASEADR_COILS, 1, tab_rp_bits);////JCM : adresse coils=MODBUS_BASEADR_COILS |
---|
2633 | Console::WriteLine(S"CppForm::Radio_Clicked : read one coil..."); |
---|
2634 | if (rc != 1) |
---|
2635 | Console::WriteLine(S"CppForm::Radio_Clicked : read one coil failed..."); |
---|
2636 | } |
---|
2637 | else if (pSender == rb2) |
---|
2638 | { |
---|
2639 | text1->Text = "Write Coils choisi : \r\n\r\n" |
---|
2640 | "FC15"; |
---|
2641 | uint8_t tab_value[77];//JCM |
---|
2642 | modbus_set_bits_from_bytes(tab_value, 0, 77, UT_BITS_TAB); |
---|
2643 | printf("tab[0]=%d,tab[1]=%d,tab[2]=%d\n", tab_value[0], tab_value[1], tab_value[2]); |
---|
2644 | int rc = modbus_write_bits(ctx, MODBUS_BASEADR_COILS,//JCM : adresse coils=MODBUS_BASEADR_COILS |
---|
2645 | 77, tab_value); |
---|
2646 | if (rc != 77) |
---|
2647 | Console::WriteLine(S"CppForm::Radio_Clicked : write coil failed..."); |
---|
2648 | } |
---|
2649 | else if (pSender == rb3) |
---|
2650 | { |
---|
2651 | text1->Text = "Read Holdings choisi : \r\n\r\n" |
---|
2652 | "FC03"; |
---|
2653 | uint16_t tab_rp_registers[UT_REGISTERS_NB]; |
---|
2654 | int rc = modbus_read_registers(ctx, MODBUS_BASEADR_LOW_HOLDINGS,//JCM : adresse holding=MODBUS_BASEADR_LOW_HOLDINGS |
---|
2655 | UT_REGISTERS_NB, tab_rp_registers); |
---|
2656 | Console::WriteLine(S"CppForm::Radio_Clicked : read holding..."); |
---|
2657 | if (rc != UT_REGISTERS_NB) |
---|
2658 | Console::WriteLine(S"CppForm::Radio_Clicked : read holding failed..."); |
---|
2659 | } |
---|
2660 | else if (pSender == rb4) |
---|
2661 | { |
---|
2662 | text1->Text = "Write Holdings choisi :\r\n\r\n" |
---|
2663 | "FC16"; |
---|
2664 | Random* myRnd = new Random(); |
---|
2665 | float realToWrite, real = myRnd->NextDouble(); |
---|
2666 | printf("random = %f\n", real<0.5 ? realToWrite=-1000*real:realToWrite=1000*real); |
---|
2667 | |
---|
2668 | uint16_t tab_rp_registers[48]; |
---|
2669 | Console::WriteLine(S"CppForm::Radio_Clicked : write holding..."); |
---|
2670 | modbus_set_float(realToWrite, tab_rp_registers);//Pi_min |
---|
2671 | int rc = modbus_write_registers(ctx, 2118,48 , tab_rp_registers); |
---|
2672 | if (rc != 48) |
---|
2673 | Console::WriteLine(S"CppForm::Radio_Clicked : write holding failed..."); |
---|
2674 | } |
---|
2675 | } |
---|
2676 | |
---|
2677 | void CppForm::Setup_Buttons()//creation et definition du bouton |
---|
2678 | { |
---|
2679 | // ajoute un bouton |
---|
2680 | btn1 = new Button(); |
---|
2681 | btn1->Text = S"OK";//se sert de sa propriété Text pour definir son titre |
---|
2682 | |
---|
2683 | btn1->Size = System::Drawing::Size(70, 25);//taille du bouton en pixels |
---|
2684 | btn1->Location = Point(230, 400);//emplacement |
---|
2685 | // btn1->Font = new System::Drawing::Font(S"Verdana", 16, FontStyle::Bold);;//l'objet Font est sauvegardé dans l'objet LabelFont grâce au pointeur |
---|
2686 | // btn1->ForeColor = Color::Brown; |
---|
2687 | |
---|
2688 | btn1->Click += new EventHandler(this, &CppForm::Btn1_Clicked);//creation d'un objet EventHandler en.. |
---|
2689 | //..lui transmettant un ptr sur le bouotn et l'adresse de la fonction en charge de.. |
---|
2690 | //..l'evenement |
---|
2691 | |
---|
2692 | Controls->Add(btn1);//pour avertir le formulaire de la présence du bouton, on ajoute le bouton.. |
---|
2693 | //.. dans la collection des controles du formulaire |
---|
2694 | |
---|
2695 | // idem pour 2eme bouton |
---|
2696 | btn2 = new Button(); |
---|
2697 | btn2->Text = S"Annuler";//.. |
---|
2698 | |
---|
2699 | btn2->Size = System::Drawing::Size(70, 25);//.. |
---|
2700 | btn2->Location = Point(310, 400);//.. |
---|
2701 | btn2->Click += new EventHandler(this, &CppForm::Btn2_Clicked); |
---|
2702 | Controls->Add(btn2);//.. |
---|
2703 | //.. |
---|
2704 | |
---|
2705 | // idem pour 3eme bouton |
---|
2706 | btn3 = new Button(); |
---|
2707 | btn3->Text = S"Connexion";//.. |
---|
2708 | |
---|
2709 | btn3->Size = System::Drawing::Size(120, 25);//.. |
---|
2710 | btn3->Location = Point(50, 220);//.. |
---|
2711 | btn3->Font = new System::Drawing::Font(S"Verdana", 12, FontStyle::Bold);;//l'objet Font est sauvegardé dans l'objet LabelFont grâce au pointeur |
---|
2712 | btn3->ForeColor = Color::Brown; |
---|
2713 | |
---|
2714 | btn3->Click += new EventHandler(this, &CppForm::Btn3_Clicked); |
---|
2715 | Controls->Add(btn3);//.. |
---|
2716 | //.. |
---|
2717 | // idem pour 4eme bouton |
---|
2718 | btn4 = new Button(); |
---|
2719 | btn4->Text = S"Ecriture";//.. |
---|
2720 | |
---|
2721 | btn4->Size = System::Drawing::Size(120, 25);//.. |
---|
2722 | btn4->Location = Point(475, 220);//.. |
---|
2723 | btn4->Font = new System::Drawing::Font(S"Verdana", 12, FontStyle::Bold);;//l'objet Font est sauvegardé dans l'objet LabelFont grâce au pointeur |
---|
2724 | btn4->ForeColor = Color::Brown; |
---|
2725 | |
---|
2726 | btn4->Click += new EventHandler(this, &CppForm::Btn4_Clicked); |
---|
2727 | Controls->Add(btn4);//.. |
---|
2728 | //.. |
---|
2729 | } |
---|
2730 | |
---|
2731 | void CppForm::Setup_Combo ()//configuration de la liste deroulmnte |
---|
2732 | { |
---|
2733 | // creation |
---|
2734 | combo1 = new ComboBox(); |
---|
2735 | combo1->DropDownStyle = ComboBoxStyle::DropDownList; |
---|
2736 | // combo1->Location = Point(20,180); |
---|
2737 | combo1->Location = Point(20,280); |
---|
2738 | |
---|
2739 | // pour ajuster la taille en fonction de la plus longue chaine |
---|
2740 | // la valeur 20 correspond à la taille du bouton situé à droite du bouton d'édition |
---|
2741 | Label* l1 = new Label(); |
---|
2742 | l1->Text = S"Automatique"; |
---|
2743 | combo1->Width = l1->PreferredWidth + 20; |
---|
2744 | |
---|
2745 | // ajout de qqs chaines et association avec tous les controles du formulaire |
---|
2746 | combo1->Items->Add(S"Manuel"); |
---|
2747 | combo1->Items->Add(S"Automatique"); |
---|
2748 | combo1->Items->Add(S"..."); |
---|
2749 | combo1->SelectedIndex = 0;//affiche la 1ere chaine par defaut |
---|
2750 | |
---|
2751 | // ajout du groupe dans le formulaire |
---|
2752 | Controls->Add(combo1); |
---|
2753 | |
---|
2754 | // associe le gestionnaire à liste deroulante. |
---|
2755 | combo1->SelectedIndexChanged += new EventHandler(this, &CppForm::Combo1_SelChanged); |
---|
2756 | } |
---|
2757 | |
---|
2758 | void CppForm::Setup_Context_Menu ()//menu contextuel |
---|
2759 | { |
---|
2760 | // Creation |
---|
2761 | popupMenu = new System::Windows::Forms::ContextMenu(); |
---|
2762 | |
---|
2763 | // Creation des items. |
---|
2764 | item_p1 = new MenuItem("UN"); |
---|
2765 | popupMenu->MenuItems->Add(item_p1); |
---|
2766 | item_p2 = new MenuItem("DEUX"); |
---|
2767 | popupMenu->MenuItems->Add(item_p2); |
---|
2768 | item_p3 = new MenuItem("TROIS"); |
---|
2769 | popupMenu->MenuItems->Add(item_p3); |
---|
2770 | |
---|
2771 | //associe le menu contextuel au formulaire |
---|
2772 | ContextMenu = popupMenu; |
---|
2773 | } |
---|
2774 | |
---|
2775 | void CppForm::Setup_Group ()//creation et configuration d'un groupe d'options |
---|
2776 | { |
---|
2777 | // Creation |
---|
2778 | gbox = new GroupBox(); |
---|
2779 | gbox->Text = S"Fonction Code"; |
---|
2780 | gbox->Size = System::Drawing::Size(200, 150);//taille du groupbox en pixels |
---|
2781 | gbox->Location = Point(20, 90); |
---|
2782 | |
---|
2783 | // Creation des boutons radio. |
---|
2784 | rb1 = new RadioButton(); |
---|
2785 | rb1->Text = S"Read Coils"; |
---|
2786 | rb1->Location = Point(10,25); |
---|
2787 | |
---|
2788 | rb2 = new RadioButton(); |
---|
2789 | rb2->Text = S"Write Coils"; |
---|
2790 | rb2->Location = Point(10,55); |
---|
2791 | |
---|
2792 | rb3 = new RadioButton(); |
---|
2793 | rb3->Text = S"Read Holdings"; |
---|
2794 | rb3->Location = Point(10,85); |
---|
2795 | // rb3->Checked = true;//c'est la valeur par defaut |
---|
2796 | |
---|
2797 | rb4 = new RadioButton(); |
---|
2798 | rb4->Text = S"Write Holdings"; |
---|
2799 | rb4->Location = Point(10,115); |
---|
2800 | rb4->Checked = true;//c'est la valeur par defaut |
---|
2801 | |
---|
2802 | // ajout des controles dans le groupe |
---|
2803 | gbox->Controls->Add(rb1); |
---|
2804 | gbox->Controls->Add(rb2); |
---|
2805 | gbox->Controls->Add(rb3); |
---|
2806 | gbox->Controls->Add(rb4); |
---|
2807 | |
---|
2808 | // ajout du groupe dans le formulaire. |
---|
2809 | Controls->Add(gbox); |
---|
2810 | |
---|
2811 | // associe le gestionnaire au groupe d'options |
---|
2812 | rb1->Click += new EventHandler(this, &CppForm::Radio_Clicked); |
---|
2813 | rb2->Click += new EventHandler(this, &CppForm::Radio_Clicked); |
---|
2814 | rb3->Click += new EventHandler(this, &CppForm::Radio_Clicked); |
---|
2815 | rb4->Click += new EventHandler(this, &CppForm::Radio_Clicked); |
---|
2816 | } |
---|
2817 | |
---|
2818 | void CppForm::Setup_Label()//description textuelle dans le formulaire |
---|
2819 | { |
---|
2820 | theLabel = new Label(); |
---|
2821 | theLabel->AutoSize = true; |
---|
2822 | |
---|
2823 | theLabel->Text = S" XFEL Supervision Client";//les espaces sont prévus pour inserer uen image |
---|
2824 | |
---|
2825 | // definition de la police |
---|
2826 | // labelFont = new System::Drawing::Font(S"Verdana", 20, FontStyle::Italic); |
---|
2827 | labelFont = new System::Drawing::Font(S"Arial", 20, FontStyle::Italic); |
---|
2828 | theLabel->Font = labelFont;//l'objet Font est sauvegardé dans l'objet LabelFont grâce au pointeur |
---|
2829 | theLabel->ForeColor = Color::Black; |
---|
2830 | |
---|
2831 | // taille et emplacement |
---|
2832 | // theLabel->Location = Point(300,20); |
---|
2833 | theLabel->Location = Point(125,40); |
---|
2834 | theLabel->Size = System::Drawing::Size(theLabel->PreferredWidth, |
---|
2835 | theLabel->PreferredHeight); |
---|
2836 | |
---|
2837 | // ajout de l'image |
---|
2838 | // Bitmap* theImage = new Bitmap("SAVE.BMP"); |
---|
2839 | Bitmap* theImage = new Bitmap("..//image1.BMP"); |
---|
2840 | theLabel->Image = theImage; |
---|
2841 | theLabel->ImageAlign = ContentAlignment::MiddleLeft; |
---|
2842 | |
---|
2843 | // ajout du label dans la collection des controles du formulaire |
---|
2844 | Controls->Add(theLabel); |
---|
2845 | } |
---|
2846 | |
---|
2847 | void CppForm::Setup_Menu()//barre de menu |
---|
2848 | { |
---|
2849 | // Creation de la barre de menu principal |
---|
2850 | menuBar = new MainMenu(); |
---|
2851 | |
---|
2852 | // Cree le menu fichier. |
---|
2853 | fileMenu = new MenuItem("&Fichier"); |
---|
2854 | menuBar->MenuItems->Add(fileMenu); |
---|
2855 | |
---|
2856 | // Cree les elements du menu et les affiche. |
---|
2857 | item1 = new MenuItem("&A propos..."); |
---|
2858 | item11 = new MenuItem("&Choisir Serveur..."); |
---|
2859 | fontDlgItem = new MenuItem("&Choisir la police..."); |
---|
2860 | item2 = new MenuItem("S&ortie"); |
---|
2861 | fileMenu->MenuItems->Add(item1); |
---|
2862 | fileMenu->MenuItems->Add(item11); |
---|
2863 | fileMenu->MenuItems->Add(fontDlgItem); |
---|
2864 | fileMenu->MenuItems->Add(item2); |
---|
2865 | |
---|
2866 | // associe le gestionnaire ayx elements du menu. |
---|
2867 | item1->Click += new EventHandler(this, &CppForm::MenuItem_Clicked); |
---|
2868 | item11->Click += new EventHandler(this, &CppForm::MenuItem_Clicked); |
---|
2869 | fontDlgItem->Click += new EventHandler(this, &CppForm::MenuItem_Clicked); |
---|
2870 | item2->Click += new EventHandler(this, &CppForm::MenuItem_Clicked); |
---|
2871 | |
---|
2872 | // ajoute le menu principal dans le formulaire |
---|
2873 | Menu = menuBar; |
---|
2874 | |
---|
2875 | //,menu déroulant ajouté à la barre de menu, puis 2 éléments |
---|
2876 | actionMenu =new MenuItem("Action"); |
---|
2877 | menuBar->MenuItems->Add(actionMenu); |
---|
2878 | subMenu1=new MenuItem("Faire"); |
---|
2879 | actionMenu->MenuItems->Add(subMenu1); |
---|
2880 | //barre de séparation, le ptr n'est pas sauvegardé car le sépérateur ne peut être sélectionné |
---|
2881 | actionMenu->MenuItems->Add(new MenuItem("-")); |
---|
2882 | anotherItem=new MenuItem("lecture serveur"); |
---|
2883 | actionMenu->MenuItems->Add(anotherItem); |
---|
2884 | //crée les 2 élements du menu et les ajoute |
---|
2885 | item1_1 =new MenuItem("connexion serveur..."); |
---|
2886 | item1_2 = new MenuItem("deconnexion serveur..."); |
---|
2887 | subMenu1->MenuItems->Add(item1_1); |
---|
2888 | subMenu1->MenuItems->Add(item1_2); |
---|
2889 | //on pourrait aussi utiliser des propriétés pour afficher un syumbole.. |
---|
2890 | //..disant élémen tselectionné (Checked) et griser des éléments du menu (Enabled) |
---|
2891 | |
---|
2892 | // associe le gestionnaire aux elements du menu. |
---|
2893 | anotherItem->Click += new EventHandler(this, &CppForm::MenuItem_Clicked); |
---|
2894 | item1_1->Click += new EventHandler(this, &CppForm::MenuItem_Clicked); |
---|
2895 | item1_2->Click += new EventHandler(this, &CppForm::MenuItem_Clicked); |
---|
2896 | } |
---|
2897 | |
---|
2898 | void CppForm::Setup_Text()//controle d'edition |
---|
2899 | { |
---|
2900 | text1 = new TextBox(); |
---|
2901 | text1->Location = Point(200,110); |
---|
2902 | text1->Size = System::Drawing::Size(250,250); |
---|
2903 | text1->Multiline = true; |
---|
2904 | |
---|
2905 | text1->ReadOnly = true; |
---|
2906 | // text1->Text = "Pour se connecter au Serveur : cliquer sur le bouton Connexion \r\n\r\n" |
---|
2907 | // "Pour configurer des paramètres : cliquer sur le bouton Ecriture \r\n\r\n"; |
---|
2908 | text1->Text = "Pour se connecter au Serveur : dans le menu 'Action', cliquer sur 'Faire' puis sur 'connexion serveur'.\r\n\r\n" |
---|
2909 | "on peut alors accéder aux paramètres : dans le menu 'Action', cliquer sur 'Faire' puis sur 'lecture serveur'\r\n\r\n" |
---|
2910 | "ou bien configurer des paramètres : cliquer sur le bouton Ecriture \r\n\r\n"; |
---|
2911 | |
---|
2912 | |
---|
2913 | Controls->Add(text1); |
---|
2914 | } |
---|