source: trunk/XSUCLWF/Cxfel.cpp@ 24

Last change on this file since 24 was 18, checked in by marrucho, 12 years ago

Rajout de la saisie de numP et numC

File size: 75.5 KB
RevLine 
[16]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
11using namespace System;
12using namespace System::ComponentModel;//contient des classes pour les composants et les contrôles
13using namespace System::Windows::Forms;//contient des classes dédiées à la génération des formulaires
14using namespace System::Drawing;//contient les classes Point et Size du bouton
15
16using namespace System::IO;//contient les classes pour les I/O
17
18using namespace System::Threading;
19
20#undef MessageBox
21
22modbus_t *ctx;//modbus
23
24
25public __gc class ThreadReadModbus
26{
27public:
28 // The ThreadProc method is called when the thread starts.
29 static void ThreadProc()
30 {
31 uint8_t tab_rp_bits[MODBUS_SIZE_READ_COILS];
32 Console::WriteLine(S"ThreadProc: read coils...");
[18]33 int rc = modbus_read_bits(ctx, MODBUS_BASEADR_COILS, MODBUS_SIZE_READ_COILS, tab_rp_bits);////JCM : adresse coils=MODBUS_BASEADR_COILS
34 if (rc != MODBUS_SIZE_READ_COILS)
[16]35 Console::WriteLine(S"ThreadProc: read coils failed...");
36 Thread::Sleep(500);
37
38 uint16_t tab_rp_registers_low[MODBUS_SIZE_READ_HOLDINGS_LOW];
39 Console::WriteLine(S"ThreadProc: read holdings...");
[18]40 rc = modbus_read_registers(ctx, MODBUS_BASEADR_LOW_HOLDINGS,//JCM : adresse holding=MODBUS_BASEADR_LOW_HOLDINGS
41 MODBUS_SIZE_READ_HOLDINGS_LOW, tab_rp_registers_low);
42 if (rc != MODBUS_SIZE_READ_HOLDINGS_LOW)
[16]43 Console::WriteLine(S"ThreadProc: read holdings failed...");
44 Thread::Sleep(500);
45
46 uint16_t wordPermuted[2];
47 float real = modbus_get_float(tab_rp_registers_low+6);//dP : float32 Normal
48 *(wordPermuted+0)= tab_rp_registers_low[6+1];//dP : float32 Reverse
49 *(wordPermuted+1)= tab_rp_registers_low[6+0];//dP : float32 Reverse
50 float realReversed = modbus_get_float(wordPermuted+0);//dP : float32 Reverse
51
52 Console::WriteLine(S"ThreadProc: read float...");
53// if (real != UT_REAL)
54// Console::WriteLine(S"ThreadProc: read float failed...");
55 printf("real(2006d) = normal=%f reverse=%f\n",
56 real,
57 //word2float[0]+(word2float[1]<<16)
58 //tab_rp_registers_low[6]+(tab_rp_registers_low[7]<<16));
59 realReversed);
60 Thread::Sleep(500);
61
62 uint16_t tab_rp_registers_high[MODBUS_SIZE_READ_HOLDINGS_HIGH];
63 Console::WriteLine(S"ThreadProc: read holdings...");
[18]64 rc = modbus_read_registers(ctx, MODBUS_BASEADR_HIGH_HOLDINGS,
65 MODBUS_SIZE_READ_HOLDINGS_HIGH, tab_rp_registers_high);
66 if (rc != MODBUS_SIZE_READ_HOLDINGS_HIGH)
[16]67 Console::WriteLine(S"ThreadProc: read holdings failed...");
68 Thread::Sleep(500);
69
70 real = modbus_get_float(tab_rp_registers_high+36);//Pi_max
71 Console::WriteLine(S"ThreadProc: read float...");
72// if (real != UT_REAL)
73// Console::WriteLine(S"ThreadProc: read float failed...");
74 printf("real(2118d) = %f\n", real);
75 Thread::Sleep(500);
76 }
77};
78
79
80CGroupBox::CGroupBox(String* gname, int posX, int posY)
81{
82 name=gname;
83 nbInstance++;
84
85 // Creation
86 gbox = new GroupBox();
87 gbox->Text = name;
88 gbox->Size = System::Drawing::Size(200, 200);//taille du groupbox en pixels
89 gbox->Location = Point(posX,posY);
90
91 // Num_P label tt seul
92 Label* labNumP= new Label();
93// labNumP->Location = Point(posX+10,posY+5);
94 labNumP->Location = Point(70,35);
95 labNumP->Size = System::Drawing::Size(50,16);
96 labNumP->Text = "Num_P";//zone de texte initialisée
97 labNumP->Font = new System::Drawing::Font(S"Arial", 9, FontStyle::Bold);;
98 labNumP->TextAlign = ContentAlignment::MiddleRight;
99 valNumP= new TextBox();
100 valNumP->Location = Point(70,55);
101 valNumP->Size = System::Drawing::Size(60, 40);
[18]102 valNumP->Text = "xx";//zone de texte initialisée vide
[16]103 valNumP->Font = new System::Drawing::Font(S"Arial", 9, FontStyle::Bold);
104 valNumP->ForeColor = Color::Brown;
105 gbox->Controls->Add(labNumP);
106 gbox->Controls->Add(valNumP);
107 // Num_C1 label tt seul
108 Label* labNumC1= new Label();
109// labNumC1->Location = Point(posX+5, posY+20);
110 labNumC1->Location = Point(20, 90);
111 labNumC1->Size = System::Drawing::Size(50,16);
112 labNumC1->Text = "1";//zone de texte initialisée
113 labNumC1->Font = new System::Drawing::Font(S"Arial", 9, FontStyle::Bold);;
114 labNumC1->TextAlign = ContentAlignment::MiddleRight;
115 valNumC1= new TextBox();
116 valNumC1->Location = Point(30,110);
117 valNumC1->Size = System::Drawing::Size(60, 40);
[18]118 valNumC1->Text = "xx";//zone de texte initialisée vide
[16]119 valNumC1->Font = new System::Drawing::Font(S"Arial", 9, FontStyle::Bold);;
120 valNumC1->ForeColor = Color::Brown;
121 gbox->Controls->Add(labNumC1);
122 gbox->Controls->Add(valNumC1);
123 // Num_C2 label tt seul
124 Label* labNumC2= new Label();
125// labNumC2->Location = Point(posX+60, posY+20);
126 labNumC2->Location = Point(85, 90);
127 labNumC2->Size = System::Drawing::Size(50,16);
128 labNumC2->Text = "2";//zone de texte initialisée
129 labNumC2->Font = new System::Drawing::Font(S"Arial", 9, FontStyle::Bold);;
130 labNumC2->TextAlign = ContentAlignment::MiddleRight;
131 valNumC2= new TextBox();
132 valNumC2->Location = Point(105,110);
133 valNumC2->Size = System::Drawing::Size(60, 40);
[18]134 valNumC2->Text = "xx";//zone de texte initialisée vide
[16]135 valNumC2->Font = new System::Drawing::Font(S"Arial", 9, FontStyle::Bold);;
136 valNumC2->ForeColor = Color::Brown;
137 gbox->Controls->Add(labNumC2);
138 gbox->Controls->Add(valNumC2);
139 //bouton Appliquer
140 appliquerBtn = new Button();
141 appliquerBtn->Location = Point(65, 170);
142 appliquerBtn->Name = "Bouton Appliquer";
143 appliquerBtn->Text = "Appliquer";
144 appliquerBtn->Click += new EventHandler(this, &CGroupBox::AppliquerBtn_Clicked);
145 gbox->Controls->Add(appliquerBtn);
146
147/*
148 String* str;
149 str=String::Concat(labNumC1->Text);
150 Console::WriteLine(str);
151 str=String::Concat(labNumC2->Text);
152 Console::WriteLine(str);
153*/
154 //..............
155 //..............
156
157}
158
159Label* CGroupBox::GetLabelNumP()
160{
161 return labNumP;
162}
163
164Label* CGroupBox::GetLabelNumC1()
165{
166 return labNumC1;
167}
168
169Label* CGroupBox::GetLabelNumC2()
170{
171 return labNumC2;
172}
173
174GroupBox* CGroupBox::GetGroupBox()
175{
176 return gbox;
177}
178
179void CGroupBox::AppliquerBtn_Clicked(Object* pSender, EventArgs* pArgs)//gestionnaire d'evenements associés au bouton Appliquer
180 {
[18]181 String* str;
182 //lecture fichier ou BDD pour comparaison avec saisie
183 try
184 {
185 FileStream* fs = new FileStream("..\\test1_4xsuc.txt",FileMode::Open);
186 StreamReader* sr = new StreamReader(fs);
187 int count=0;
188
[16]189 if(!String::Compare(name,"a"))
190 {
[18]191 Console::WriteLine(S"appliquer a");
192 for (;;)
193 {
194 String* line = sr->ReadLine();
195 if (count==0)
196 if(String::Compare(line,valNumP->Text))
197 {
198 MessageBox::Show(S"a: NumP n'existe pas !!");
199 sr->Close();
200 break;
201 }
202 if (count==1)
203 if(String::Compare(line,valNumC1->Text))
204 {
205 MessageBox::Show(S"a: NumC1 n'existe pas !!");
206 sr->Close();
207 break;
208 }
209 if (count==2)
210 if(String::Compare(line,valNumC2->Text))
211 {
212 MessageBox::Show(S"a: NumC2 n'existe pas !!");
213 sr->Close();
214 break;
215 }
216 count++;
217 if (line==0)//fin du fichier
218 {
219 sr->Close();
220 uint16_t tab_rp_registers[2];
221 int rc;
222 int size;
223 Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write NumP NumC1 et NumC2...");
224 size=1;
225 tab_rp_registers[0] = Convert::ToInt16(valNumP->Text);
226 modbus_write_registers(ctx, 2070,size, tab_rp_registers);//NumP
227 if (rc != size)
228 Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding failed...");
229 // Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding...");
230 size=2;
231 tab_rp_registers[0] = Convert::ToInt16(valNumC1->Text);
232 tab_rp_registers[1] = Convert::ToInt16(valNumC2->Text);
233 modbus_write_registers(ctx, 2050,size, tab_rp_registers);//NumC1 et NumC2
234 if (rc != size)
235 Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding failed...");
236 break;
237 }
238 }
[16]239 }
240 if(!String::Compare(name,"b"))
241 {
242 Console::WriteLine(S"appliquer b");
[18]243 for (;;)
244 {
245 String* line = sr->ReadLine();
246 if (count==3)
247 if(String::Compare(line,valNumP->Text))
248 {
249 MessageBox::Show(S"b: NumP n'existe pas !!");
250 sr->Close();
251 break;
252 }
253 if (count==4)
254 if(String::Compare(line,valNumC1->Text))
255 {
256 MessageBox::Show(S"b: NumC1 n'existe pas !!");
257 sr->Close();
258 break;
259 }
260 if (count==5)
261 if(String::Compare(line,valNumC2->Text))
262 {
263 MessageBox::Show(S"b: NumC2 n'existe pas !!");
264 sr->Close();
265 break;
266 }
267 count++;
268 if (line==0)//fin du fichier
269 {
270 sr->Close();
271 uint16_t tab_rp_registers[2];
272 int rc;
273 int size;
274 Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write NumP NumC1 et NumC2...");
275 size=1;
276 tab_rp_registers[0] = Convert::ToInt16(valNumP->Text);
277 modbus_write_registers(ctx, 2071,size, tab_rp_registers);//NumP
278 if (rc != size)
279 Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding failed...");
280 // Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding...");
281 size=2;
282 tab_rp_registers[0] = Convert::ToInt16(valNumC1->Text);
283 tab_rp_registers[1] = Convert::ToInt16(valNumC2->Text);
284 modbus_write_registers(ctx, 2052,size, tab_rp_registers);//NumC1 et NumC2
285 if (rc != size)
286 Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding failed...");
287 break;
288 }
289 }
[16]290 }
291 if(!String::Compare(name,"c"))
292 {
293 Console::WriteLine(S"appliquer c");
[18]294 for (;;)
295 {
296 String* line = sr->ReadLine();
297 if (count==6)
298 if(String::Compare(line,valNumP->Text))
299 {
300 MessageBox::Show(S"c: NumP n'existe pas !!");
301 sr->Close();
302 break;
303 }
304 if (count==7)
305 if(String::Compare(line,valNumC1->Text))
306 {
307 MessageBox::Show(S"c: NumC1 n'existe pas !!");
308 sr->Close();
309 break;
310 }
311 if (count==8)
312 if(String::Compare(line,valNumC2->Text))
313 {
314 MessageBox::Show(S"c: NumC2 n'existe pas !!");
315 sr->Close();
316 break;
317 }
318 count++;
319 if (line==0)//fin du fichier
320 {
321 sr->Close();
322 uint16_t tab_rp_registers[2];
323 int rc;
324 int size;
325 Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write NumP NumC1 et NumC2...");
326 size=1;
327 tab_rp_registers[0] = Convert::ToInt16(valNumP->Text);
328 modbus_write_registers(ctx, 2072,size, tab_rp_registers);//NumP
329 if (rc != size)
330 Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding failed...");
331 // Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding...");
332 size=2;
333 tab_rp_registers[0] = Convert::ToInt16(valNumC1->Text);
334 tab_rp_registers[1] = Convert::ToInt16(valNumC2->Text);
335 modbus_write_registers(ctx, 2054,size, tab_rp_registers);//NumC1 et NumC2
336 if (rc != size)
337 Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding failed...");
338 break;
339 }
340 }
[16]341 }
342 if(!String::Compare(name,"d"))
343 {
344 Console::WriteLine(S"appliquer d");
[18]345 for (;;)
346 {
347 String* line = sr->ReadLine();
348 if (count==9)
349 if(String::Compare(line,valNumP->Text))
350 {
351 MessageBox::Show(S"d: NumP n'existe pas !!");
352 sr->Close();
353 break;
354 }
355 if (count==10)
356 if(String::Compare(line,valNumC1->Text))
357 {
358 MessageBox::Show(S"d: NumC1 n'existe pas !!");
359 sr->Close();
360 break;
361 }
362 if (count==11)
363 if(String::Compare(line,valNumC2->Text))
364 {
365 MessageBox::Show(S"d: NumC2 n'existe pas !!");
366 sr->Close();
367 break;
368 }
369 count++;
370 if (line==0)//fin du fichier
371 {
372 sr->Close();
373 uint16_t tab_rp_registers[2];
374 int rc;
375 int size;
376 Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write NumP NumC1 et NumC2...");
377 size=1;
378 tab_rp_registers[0] = Convert::ToInt16(valNumP->Text);
379 modbus_write_registers(ctx, 2073,size, tab_rp_registers);//NumP
380 if (rc != size)
381 Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding failed...");
382 // Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding...");
383 size=2;
384 tab_rp_registers[0] = Convert::ToInt16(valNumC1->Text);
385 tab_rp_registers[1] = Convert::ToInt16(valNumC2->Text);
386 modbus_write_registers(ctx, 2056,size, tab_rp_registers);//NumC1 et NumC2
387 if (rc != size)
388 Console::WriteLine(S"CGroupBox::::AppliquerBtn_Clicked : write holding failed...");
389 break;
390 }
391 }
[16]392 }
[18]393 }
394 catch (System::Exception* pe)
395 {
396 Console::WriteLine(pe->ToString());
397 }
398 int count=0;
399
[16]400 }
401
402CDialogConfig::CDialogConfig()
403 {
404 // définit les paramètres du formulaire
405 Text = S"XSUC - ecriture serveur";
406 FormBorderStyle = FormBorderStyle::Fixed3D;//impossible de modifier la taille
407 Size = System::Drawing::Size(1000,800);
408
409 // Creation de controle
410 sortirBtn = new Button();
411
412 // bouton OK
413 sortirBtn->Location = Point(900, 700);
414 sortirBtn->Name = "Bouton Sortir";
415 sortirBtn->Text = "sortir";
416 sortirBtn->DialogResult = DialogResult::OK;
417
418 // Ajoute les controles dans le formaulaire
419 Controls->Add(sortirBtn);
420
421/* GroupBox* gbox = new GroupBox();
422 gbox->Text = S"name";
423 gbox->Size = System::Drawing::Size(200, 150);//taille du groupbox en pixels
424 gbox->Location = Point(200,90);
425 Label* labNumP= new Label();
426 labNumP->Location = Point(10, 20);
427 labNumP->Size = System::Drawing::Size(50,16);
428 labNumP->Text = "Num_P";//zone de texte initialisée
429 labNumP->TextAlign = ContentAlignment::MiddleRight;
430 gbox->Controls->Add(labNumP);
431 Controls->Add(gbox);
432*/
433 pal = new ArrayList();
434 int j=20;//depart affichage
435 for (indexGroupBox=0;indexGroupBox<NB_BANCS;indexGroupBox++)//creation des controles dans le formulaire
436 {
437 pal->Add(new CGroupBox(gname[indexGroupBox],j,90));
438 j+=250;
439 CGroupBox* gboxPtr = (CGroupBox *) pal->get_Item(indexGroupBox);
440// gboxPtr->Controls->Add(gboxPtr->GetLabelNumP());
441// gboxPtr->GetGroupBox()->Controls->Add(gboxPtr->GetLabelNumC1());
442// gboxPtr->Controls->Add(gboxPtr->GetLabelNumC2());
443 Controls->Add(gboxPtr->GetGroupBox());
444 String* str;
445 str=String::Concat(gboxPtr->GetGroupBox()->Text);
446 Console::WriteLine(str);
447/* str=String::Concat(gboxPtr->GetLabelNumP()->Text);
448 Console::WriteLine(str);
449 str=String::Concat(gboxPtr->GetLabelNumC1()->Text);
450 Console::WriteLine(str);
451*/ }
452
453 //configure les 2 propriétés : AcceptButton contient la réf du bouton par défaut du formulaire..
454 //..on peut cliquer sur le bouton OK ou bien sur la touche Entrée du clavier..
455 //..referme aussi la boite car DialogResult renvoie OK
456 AcceptButton = sortirBtn;
457
458 //gestionnnaire associé au bouton OK
459 sortirBtn->Click += new EventHandler(this, &CDialogConfig::SortirBtn_Clicked);
460 }
461
[18]462CDialogConfig::CDialogConfig(uint16_t *tab_rp_registers_low,uint16_t *tab_rp_registers_high)
463 {
464 // définit les paramètres du formulaire
465 Text = S"XSUC - ecriture serveur";
466 FormBorderStyle = FormBorderStyle::Fixed3D;//impossible de modifier la taille
467 Size = System::Drawing::Size(1000,800);
468
469 // Creation de controle
470 sortirBtn = new Button();
471
472 // bouton OK
473 sortirBtn->Location = Point(900, 700);
474 sortirBtn->Name = "Bouton Sortir";
475 sortirBtn->Text = "sortir";
476 sortirBtn->DialogResult = DialogResult::OK;
477
478 // Ajoute les controles dans le formaulaire
479 Controls->Add(sortirBtn);
480
481/* GroupBox* gbox = new GroupBox();
482 gbox->Text = S"name";
483 gbox->Size = System::Drawing::Size(200, 150);//taille du groupbox en pixels
484 gbox->Location = Point(200,90);
485 Label* labNumP= new Label();
486 labNumP->Location = Point(10, 20);
487 labNumP->Size = System::Drawing::Size(50,16);
488 labNumP->Text = "Num_P";//zone de texte initialisée
489 labNumP->TextAlign = ContentAlignment::MiddleRight;
490 gbox->Controls->Add(labNumP);
491 Controls->Add(gbox);
492*/
493 pal = new ArrayList();
494 int j=20;//depart affichage
495 for (indexGroupBox=0;indexGroupBox<NB_BANCS;indexGroupBox++)//creation des controles dans le formulaire
496 {
497 pal->Add(new CGroupBox(gname[indexGroupBox],j,90));
498 j+=250;
499 CGroupBox* gboxPtr = (CGroupBox *) pal->get_Item(indexGroupBox);
500// gboxPtr->Controls->Add(gboxPtr->GetLabelNumP());
501// gboxPtr->GetGroupBox()->Controls->Add(gboxPtr->GetLabelNumC1());
502// gboxPtr->Controls->Add(gboxPtr->GetLabelNumC2());
503 Controls->Add(gboxPtr->GetGroupBox());
504 String* str;
505 str=String::Concat(gboxPtr->GetGroupBox()->Text);
506 Console::WriteLine(str);
507/* str=String::Concat(gboxPtr->GetLabelNumP()->Text);
508 Console::WriteLine(str);
509 str=String::Concat(gboxPtr->GetLabelNumC1()->Text);
510 Console::WriteLine(str);
511*/ }
512
513 //configure les 2 propriétés : AcceptButton contient la réf du bouton par défaut du formulaire..
514 //..on peut cliquer sur le bouton OK ou bien sur la touche Entrée du clavier..
515 //..referme aussi la boite car DialogResult renvoie OK
516 AcceptButton = sortirBtn;
517
518 //gestionnnaire associé au bouton OK
519 sortirBtn->Click += new EventHandler(this, &CDialogConfig::SortirBtn_Clicked);
520 }
521
[16]522void CDialogConfig::SortirBtn_Clicked(Object* pSender,EventArgs* pArgs)//gestionnaire d'evenement de la boite dialogue
523 {
524 //fermer le formulaire lorsqu'on clique sur le bouton
525 Close();
526 }
527
528
529CLabelTextBox::CLabelTextBox(String* labString, int posX, int posY, int sizeX, int sizeY, int sizeText)
530{
531 name=labString;
532 labPosX=posX;
533 labPosY=posY;
534 labSizeX=sizeX;
535 labSizeY=sizeY;
536 nbInstance++;
537
538 lab= new Label();
539 val= new TextBox();
540
541 // dPLabel et dPBox : label et zone de saisie sont placés l'un à côté de l'autre
542 lab->Location = Point(labPosX, labPosY);
543 lab->Size = System::Drawing::Size(labSizeX,labSizeY);
544 lab->Text = name;//zone de texte initialisée
545 lab->TextAlign = ContentAlignment::MiddleRight;
546 val->Location = Point(labPosX+labSizeX, labPosY);
547 val->Size = System::Drawing::Size(sizeText, 20);
548 val->Text = "";//zone de texte initialisée vide
549}
550
551Label* CLabelTextBox::GetLabel()
552{
553 return lab;
554}
555
556TextBox* CLabelTextBox::GetTextBox()
557{
558 return val;
559}
560
561String* CLabelTextBox::GetName()
562{
563return name;
564}
565
566void CLabelTextBox::SetVal(String* value)
567{
568 val->Text=value;
569}
570
571String* CLabelTextBox::GetVal()
572{
573 return val->Text;
574}
575
576void CLabelTextBox::SetColor(int value)
577{
578 if(value)
579 val->BackColor=Color::Red;
580 else
581 val->BackColor=Color::White;
582}
583
584
585MaDialogUser::MaDialogUser()
586 {
587 // définit les paramètres du formulaire
588 Text = S"XSUC - lecture serveur";
589 FormBorderStyle = FormBorderStyle::Fixed3D;//impossible de modifier la taille
590 Size = System::Drawing::Size(1000,800);
591
592 // Creation de controle
593 OKBtn = new Button();
594 EcritureBtn = new Button();
595// CancelBtn = new Button();
596
597 // bouton OK
598 OKBtn->Location = Point(900, 700);
599 OKBtn->Name = "Bouton OK";
600 OKBtn->Text = "OK";
601 OKBtn->DialogResult = DialogResult::OK;
602/*
603 // bouton Cancel
604 CancelBtn->Location = Point(192, 136);
605 CancelBtn->Name = "Bouton Cancel";
606 CancelBtn->Text = "Annuler";
607 CancelBtn->DialogResult = DialogResult::Cancel;
608*/
609 // bouton Ecriture
610 EcritureBtn->Location = Point(900, 600);
611 EcritureBtn->Name = "Bouton Ecriture";
612 EcritureBtn->Text = "Ecriture";
613 EcritureBtn->DialogResult = DialogResult::OK;
614
615 // Ajoute les controles dans le formaulaire
616 Controls->Add(OKBtn);
617 Controls->Add(EcritureBtn);
618
619 pal = new ArrayList();
620 for (indexTextBox=0;indexTextBox<20;indexTextBox++)//creation des controles dans le formulaire
621 {
622 int posX=650, j=indexTextBox;
623 if (indexTextBox>=10)
624 {
625 posX=800;
626 j=indexTextBox-10;
627 }
628 pal->Add(new CLabelTextBox(nameLab_1[indexTextBox],posX,(25*j)+10,100,16,70));
629 CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox);
630 Controls->Add(cltbPtr->GetLabel());
631 Controls->Add(cltbPtr->GetTextBox());
632 }
633 for (;indexTextBox<26;indexTextBox++)//creation des controles dans le formulaire
634 {
635 int posX=400, j=indexTextBox-20;
636 int sizeText=70;
637 if (indexTextBox==20)sizeText=20;
638 pal->Add(new CLabelTextBox(nameLab_1[indexTextBox],posX,(25*j)+10,100,16,sizeText));
639 CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox);
640 Controls->Add(cltbPtr->GetLabel());
641 Controls->Add(cltbPtr->GetTextBox());
642 }
643 Setup_Group_Conditionning();
644 // Mode tt seul
645 pal->Add(new CLabelTextBox("MODE",20,100,50,16,75));
646 CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox++);
647 Controls->Add(cltbPtr->GetLabel());
648 Controls->Add(cltbPtr->GetTextBox());
649
650 //configure les 2 propriétés : AcceptButton contient la réf du bouton par défaut du formulaire..
651 //..on peut cliquer sur le bouton OK ou bien sur la touche Entrée du clavier..
652 //..referme aussi la boite car DialogResult renvoie OK
653 AcceptButton = OKBtn;
654 //CancelButton contient la réf du bouton associée à la touche Echap du clavier
655 // CancelButton = CancelBtn;
656
657 //gestionnnaire associé aux boutons
658 OKBtn->Click += new EventHandler(this, &MaDialogUser::OKMaDBtn_Clicked);
659 EcritureBtn->Click += new EventHandler(this, &MaDialogUser::EcritureBtn_Clicked);
660
661 Setup_Group();
662 }
663
664void MaDialogUser::EcritureBtn_Clicked(Object* pSender,EventArgs* pArgs)//gestionnaire d'evenement de la boite dialogue
665 {
666 //crée la boite de dialogue utilisateur
667 CDialogConfig* box = new CDialogConfig();
668 //affiche la boite de dialogue
669 if (box->ShowDialog() == DialogResult::OK)
670 {
671 //si la valeur OK est renvoyée, on affiche le nom
672 //MessageBox::Show(S"Ecriture");
673 }
674 }
675
676void MaDialogUser::OKMaDBtn_Clicked(Object* pSender,EventArgs* pArgs)//gestionnaire d'evenement de la boite dialogue
677 {
678 //fermer le formulaire lorsqu'on clique sur le bouton
679 Close();
680 }
681
682float MaDialogUser::PermutToReversed(uint16_t* tab_rp_registers,int index)//permute float32 en float32 Reverse
683 {
684 uint16_t wordPermuted[2];
685
686 *(wordPermuted+0)= tab_rp_registers[index+1];
687 *(wordPermuted+1)= tab_rp_registers[index+0];
688 return (modbus_get_float(wordPermuted+0));//float32 Reverse
689 }
690
691void MaDialogUser::ThreadProc()//gestionnaire d'evenement du thread de la boite dialogue
692 {
693 uint8_t tab_rp_bits[MODBUS_SIZE_READ_COILS];
694 uint16_t tab_rp_registers_low[MODBUS_SIZE_READ_HOLDINGS_LOW];
695 uint16_t tab_rp_registers_high[MODBUS_SIZE_READ_HOLDINGS_HIGH];
696 int rc, adress, size;
697 CLabelTextBox* cltbPtr;
698
699 for (;;)
700 {
701 Thread::Sleep(500);
702 Console::WriteLine(S"ThreadProc: read coils...");
[18]703 adress=MODBUS_BASEADR_COILS;//adresse coils=MODBUS_BASEADR_COILS
704 size=MODBUS_SIZE_READ_COILS;
705 rc = modbus_read_bits(ctx, adress, size, tab_rp_bits);////JCM : adresse coils=MODBUS_BASEADR_COILS
[16]706 if (rc != size)
707 Console::WriteLine(S"ThreadProc: read coils failed...");
708
709 Thread::Sleep(500);
710 Console::WriteLine(S"ThreadProc: read holdings...");
[18]711 adress=MODBUS_BASEADR_LOW_HOLDINGS;//adresse holding=MODBUS_BASEADR_LOW_HOLDINGS
[16]712 size=82;
713 rc = modbus_read_registers(ctx, adress, size, tab_rp_registers_low);
714 if (rc != size)
715 Console::WriteLine(S"ThreadProc: read holdings failed...");
716
717 int indexArrayList=0;
718 //dtp : ui16
719 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
720 cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[4]));
721 //dt : ui16
722 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
723 cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[5]));
724 //dP : float32
725 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
726 cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_low,6)));
727 //dPsecu : float32
728 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
729 cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_low,8)));
730
731 //NBal : ui16
732 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
733 cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[42]));
734 //P_cde : float32
735 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
736 cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_low,43)));
737 //Pp : float32
738 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
739 cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_low,45)));
740
741 //Nbal_max : ui16
742 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
743 cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[25]));
744 //Fr : ui16
745 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
746 cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[26]));
747 //N_cur : ui16
748 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
749 cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[27]));
750
751 //SVd : ui16
752 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
753 cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[0]));
754 //SVfin : ui16
755 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
756 cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[1]));
757 //SV1 : ui16
758 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
759 cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[2]));
760 //SV2 : ui16
761 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
762 cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[3]));
763
764 //V_cur : ui16
765 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
766 cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[37]));
767 //Pic : float32
768 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
769 cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_low,38)));
770 //Timer : uint32
771 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
772 cltbPtr->SetVal(Convert::ToString((tab_rp_registers_low[40]<<16)+(tab_rp_registers_low[41])));
773
774 //SVil : ui16
775 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
776 cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[20]));
777 //Sleil : float32
778 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
779 cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_low,21)));
780 //STc : float32
781 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
782 cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_low,23)));
783
784 //Eil : bool
785 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
786 cltbPtr->SetVal(Convert::ToString(tab_rp_bits[0]));
787 if(tab_rp_bits[0])//echec changer couleur
788 cltbPtr->SetColor(1);
789 else
790 cltbPtr->SetColor(0);
791 //Nil : ui16
792 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
793 cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[30]));
794 //Nil_stat : ui16
795 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
796 cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[31]));
797 //P_last : float32
798 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
799 cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_low,32)));
800 //N_last : ui16
801 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
802 cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[34]));
803 //DPil : float32
804 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
805 cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_low,35)));
806
807 //Num_C : tab ui16
808 for (int indexMbArray=50;(indexArrayList<34 && indexMbArray<58);indexMbArray++)
809 {
810 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
811 cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[indexMbArray]));
812 }
813
814 //Stat_C : tab bool
815 for (int indexMbArray=1;(indexArrayList<46 && indexMbArray<13);indexMbArray++)
816 {
817 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
818 cltbPtr->SetVal(Convert::ToString(tab_rp_bits[indexMbArray]));
819 if(!tab_rp_bits[indexMbArray])//echec changer couleur
820 cltbPtr->SetColor(1);
821 else
822 cltbPtr->SetColor(0);
823 }
824
825 //Temp_cond : tab ui16
826 for (int indexMbArray=58;(indexArrayList<58 && indexMbArray<71);indexMbArray++)
827 {
828 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
829 cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[indexMbArray]));
830 }
831
832 //status : ui16
833 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
834 if (tab_rp_registers_low[49] != 4)//on n'est pas ds le mode pulsing
835 {
836 cltbPtr->SetVal("ARRET");
837 btnStart->Enabled=false;//bouton start
838 btnStop->Enabled=false;//bouton stop
839 btnPause->Enabled=false;//bouton pause
840 btnReprise->Enabled=false;//bouton reprise
841 }
842 else
843 {//mode pulsing
844 switch (tab_rp_registers_low[28]){//RetMAPR
845 case 0://conditionnement arreté
846 cltbPtr->SetVal("ARRET");
847 btnStart->Enabled=true;//bouton start
848 btnStop->Enabled=false;//bouton stop
849 btnPause->Enabled=false;//bouton pause
850 btnReprise->Enabled=false;//bouton reprise
851 break;
852 case 2: case 3://conditionnement démarré ou repris
853 cltbPtr->SetVal("MARCHE");
854 btnStart->Enabled=false;//bouton start
855 btnStop->Enabled=true;//bouton stop
856 btnPause->Enabled=true;//bouton pause
857 btnReprise->Enabled=false;//bouton reprise
858 break;
859 case 1://conditionnement en pause
860 cltbPtr->SetVal("PAUSE");
861 btnStart->Enabled=false;//bouton start
862 btnStop->Enabled=true;//bouton stop
863 btnPause->Enabled=false;//bouton pause
864 btnReprise->Enabled=true;//bouton reprise
865 break;
866 }
867 if (tab_rp_registers_low[28] != tab_rp_registers_low[48])//message affiché
868 {
869 String* stra[] = {S"RetMAPR=",Convert::ToString(tab_rp_registers_low[28]),
870 S" not equal to MAPR=",Convert::ToString(tab_rp_registers_low[48])};
871 String* str=String::Concat(stra);
872 Console::WriteLine(str);
873 }
874 }//fin mode pulsing
875
876 //N_Seqcond : ui16
877 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
878 cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[47]));
879
880 Thread::Sleep(500);
881 Console::WriteLine(S"ThreadProc: read holdings...");
[18]882 adress=MODBUS_BASEADR_HIGH_HOLDINGS;//adresse holding=MODBUS_BASEADR_HIGH_HOLDINGS
883 size=MODBUS_SIZE_READ_HOLDINGS_HIGH;
[16]884 rc = modbus_read_registers(ctx, adress, size, tab_rp_registers_high);
885 if (rc != size)
886 Console::WriteLine(S"ThreadProc: read holdings failed...");
887
888 //DateD HeureD : tab ui16
889 String* str;
890 String* strDD[] = {
891 Convert::ToString(tab_rp_registers_high[84]),
892 "-",
893 Convert::ToString(tab_rp_registers_high[85]),
894 "-",
895 Convert::ToString(tab_rp_registers_high[86])};
896 str=String::Concat(strDD);
897 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
898 cltbPtr->SetVal(str);
899 String* strHD[] = {
900 Convert::ToString(tab_rp_registers_high[87]),
901 ":",
902 Convert::ToString(tab_rp_registers_high[88]),
903 ":",
904 Convert::ToString(tab_rp_registers_high[89])};
905 str=String::Concat(strHD);
906 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
907 cltbPtr->SetVal(str);
908
909 //DateF HeureF : tab ui16
910 String* strDF[] = {
911 Convert::ToString(tab_rp_registers_high[90]),
912 "-",
913 Convert::ToString(tab_rp_registers_high[91]),
914 "-",
915 Convert::ToString(tab_rp_registers_high[92])};
916 str=String::Concat(strDF);
917 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
918 cltbPtr->SetVal(str);
919 String* strHF[] = {
920 Convert::ToString(tab_rp_registers_high[93]),
921 ":",
922 Convert::ToString(tab_rp_registers_high[94]),
923 ":",
924 Convert::ToString(tab_rp_registers_high[95])};
925 str=String::Concat(strHF);
926 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
927 cltbPtr->SetVal(str);
928
929 //Vides : tab ui16
930 for (int indexMbArray=98;indexMbArray<110;indexMbArray++)
931 {
932 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
933 cltbPtr->SetVal(Convert::ToString(tab_rp_registers_high[indexMbArray]));
934 }
935
936 //Prc : tab float32
937 for (int indexMbArray=68;indexMbArray<76;indexMbArray+=2)
938 {
939 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
940 cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_high,indexMbArray)));
941 }
942
943 //Pic : tab float32
944 for (int indexMbArray=60;indexMbArray<68;indexMbArray+=2)
945 {
946 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
947 cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_high,indexMbArray)));
948 }
949
950 //Pch : tab float32
951 for (int indexMbArray=76;indexMbArray<84;indexMbArray+=2)
952 {
953 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
954 cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_high,indexMbArray)));
955 }
956
957 //Ie_cur : tab float32
958 for (int indexMbArray=10;indexMbArray<18;indexMbArray+=2)
959 {
960 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
961 cltbPtr->SetVal(Convert::ToString(PermutToReversed(tab_rp_registers_low,indexMbArray)));
962 }
963
964 //Num_P : tab ui16
965 for (int indexMbArray=70;indexMbArray<74;indexMbArray++)
966 {
967 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
968 cltbPtr->SetVal(Convert::ToString(tab_rp_registers_low[indexMbArray]));
969 }
970
971 //Mode : ui16
972 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList++);
973 switch (tab_rp_registers_low[49]){
974 case 0://station en mode init
975 cltbPtr->SetVal("INIT");
976 break;
977 case 1://station en mode off
978 cltbPtr->SetVal("OFF");
979 break;
980 case 2://station en mode heater
981 cltbPtr->SetVal("HEATER");
982 break;
983 case 3://station en mode standby
984 cltbPtr->SetVal("STANDBY");
985 break;
986 case 4://station en mode pulsing=conditionnement
987 cltbPtr->SetVal("PULSING");
988 break;
989 case 5://station en mode off
990 cltbPtr->SetVal("STOP");
991 break;
992 }
993//
994//
995 }
996 }
997
998void MaDialogUser::Setup_Group ()//creation et configuration d'un groupe d'options
999 {
1000 // Creation
1001 gbox = new GroupBox();
1002 gbox->Text = S"enable lecture";
1003 gbox->Size = System::Drawing::Size(200, 150);//taille du groupbox en pixels
1004 gbox->Location = Point(200, 90);
1005
1006 // Creation des boutons radio.
1007 rb1 = new RadioButton();
1008 rb1->Text = S"oui";
1009 rb1->Location = Point(10,25);
1010
1011 rb2 = new RadioButton();
1012 rb2->Text = S"non";
1013 rb2->Location = Point(10,55);
1014
1015 // ajout des controles dans le groupe
1016 gbox->Controls->Add(rb1);
1017 gbox->Controls->Add(rb2);
1018
1019 // ajout du groupe dans le formulaire.
1020 Controls->Add(gbox);
1021
1022 // associe le gestionnaire au groupe d'options
1023 rb1->Click += new EventHandler(this, &MaDialogUser::Radio_Clicked);
1024 rb2->Click += new EventHandler(this, &MaDialogUser::Radio_Clicked);
1025 }
1026
1027void MaDialogUser::Setup_Group_Conditionning()//creation et configuration d'un groupe d'options
1028 {
1029 // Creation
1030 GroupBox* gboxC = new GroupBox();
1031 gboxC->Text = S"CONDITIONNEMENT";
1032 gboxC->Size = System::Drawing::Size(800, 450);//taille du groupbox en pixels
1033 gboxC->Location = Point(40,300);
1034
1035 Setup_Buttons_Conditionning();//configure les boutons du formulaire
1036
1037 // Num_C label tt seul
1038 Label* num_C= new Label();
1039 num_C->Location = Point(50, 390);
1040 num_C->Size = System::Drawing::Size(50,16);
1041 num_C->Text = "Num_C";//zone de texte initialisée
1042 num_C->TextAlign = ContentAlignment::MiddleRight;
1043 Controls->Add(num_C);
1044 int j=60;//depart affichage
1045// for (int i=0;indexTextBox<34;indexTextBox++,i++,j+=80)//creation des controles dans le formulaire
1046 for (int i=0;i<NB_COUPLEURS;indexTextBox++,i++,j+=80)//creation des controles dans le formulaire
1047 {
1048 int posX=70;
1049 pal->Add(new CLabelTextBox(nameLab_2[i],posX+j,390,25,16,50));
1050 CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox);
1051 Controls->Add(cltbPtr->GetLabel());
1052 Controls->Add(cltbPtr->GetTextBox());
1053 }
1054
1055 // Stat_C label tt seul
1056 Label* stat_C= new Label();
1057 stat_C->Location = Point(50, 630);
1058 stat_C->Size = System::Drawing::Size(50,16);
1059 stat_C->Text = "Stat_C";//zone de texte initialisée
1060 stat_C->TextAlign = ContentAlignment::MiddleRight;
1061 Controls->Add(stat_C);
1062 j=20;//depart affichage
1063// for (int i=0;indexTextBox<46;indexTextBox++,i++,j+=60)//creation des controles dans le formulaire
1064 for (int i=0;i<NB_ETAPES;indexTextBox++,i++,j+=60)//creation des controles dans le formulaire
1065 {
1066 int posX=100;
1067 pal->Add(new CLabelTextBox(Convert::ToString(i+1),posX+j,630,25,16,20));
1068 CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox);
1069 Controls->Add(cltbPtr->GetLabel());
1070 Controls->Add(cltbPtr->GetTextBox());
1071 }
1072
1073 // Temp_cond label tt seul
1074 Label* temp_cond= new Label();
1075 temp_cond->Location = Point(50, 670);
1076 temp_cond->Size = System::Drawing::Size(70,16);
1077 temp_cond->Text = "Temp_cond";//zone de texte initialisée
1078 temp_cond->TextAlign = ContentAlignment::MiddleRight;
1079 Controls->Add(temp_cond);
1080 j=20;//depart affichage
1081// for (int i=0;indexTextBox<58;indexTextBox++,i++,j+=60)//creation des controles dans le formulaire
1082 for (int i=0;i<NB_ETAPES;indexTextBox++,i++,j+=60)//creation des controles dans le formulaire
1083 {
1084 int posX=90;
1085 pal->Add(new CLabelTextBox(Convert::ToString(i+1),posX+j,670,25,16,40));
1086 CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox);
1087 Controls->Add(cltbPtr->GetLabel());
1088 Controls->Add(cltbPtr->GetTextBox());
1089 }
1090
1091 // status, N_Seqcond, DateD et heureD , DateF et HeureF labels tt seul
1092 Label* status= new Label();
1093 status->Location = Point(370, 700);
1094 status->Size = System::Drawing::Size(65,16);
1095 status->Text = "status";//zone de texte initialisée
1096 status->TextAlign = ContentAlignment::MiddleRight;
1097 Controls->Add(status);
1098 Label* n_seqcond= new Label();
1099 n_seqcond->Location = Point(450, 700);
1100 n_seqcond->Size = System::Drawing::Size(65,16);
1101 n_seqcond->Text = "N_Seqcond";//zone de texte initialisée
1102 n_seqcond->TextAlign = ContentAlignment::MiddleRight;
1103 Controls->Add(n_seqcond);
1104 Label* dateD= new Label();
1105 dateD->Location = Point(510, 700);
1106 dateD->Size = System::Drawing::Size(65,16);
1107 dateD->Text = "DateD";//zone de texte initialisée
1108 dateD->TextAlign = ContentAlignment::MiddleRight;
1109 Controls->Add(dateD);
1110 Label* heureD= new Label();
1111 heureD->Location = Point(580, 700);
1112 heureD->Size = System::Drawing::Size(65,16);
1113 heureD->Text = "HeureD";//zone de texte initialisée
1114 heureD->TextAlign = ContentAlignment::MiddleRight;
1115 Controls->Add(heureD);
1116 Label* dateF= new Label();
1117 dateF->Location = Point(650, 700);
1118 dateF->Size = System::Drawing::Size(65,16);
1119 dateF->Text = "DateF";//zone de texte initialisée
1120 dateF->TextAlign = ContentAlignment::MiddleRight;
1121 Controls->Add(dateF);
1122 Label* heureF= new Label();
1123 heureF->Location = Point(720, 700);
1124 heureF->Size = System::Drawing::Size(65,16);
1125 heureF->Text = "HeureF";//zone de texte initialisée
1126 heureF->TextAlign = ContentAlignment::MiddleRight;
1127 Controls->Add(heureF);
1128 j=330;//depart affichage
1129// for (int i=0;indexTextBox<62;indexTextBox++,i++,j+=100)//creation des controles dans le formulaire
1130 for (int i=0;i<6;indexTextBox++,i++,j+=70)//creation des controles dans le formulaire
1131 {
1132 int posX=0;
1133 pal->Add(new CLabelTextBox("",posX+j,720,55,16,70));
1134 CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox);
1135 Controls->Add(cltbPtr->GetTextBox());
1136 }
1137
1138 // Vides label tt seul
1139 Label* vides = new Label();
1140 vides->Location = Point(50, 590);
1141 vides->Size = System::Drawing::Size(60,32);
1142 vides->Text = "Vides (10-9mbar)";//zone de texte initialisée
1143 vides->TextAlign = ContentAlignment::MiddleRight;
1144 Controls->Add(vides);
1145 j=40;//depart affichage
1146 for (int i=0;i<(NB_BANCS*3);indexTextBox++,i++,j+=60)//creation des controles dans le formulaire
1147 {
1148 int posX=70;
1149 pal->Add(new CLabelTextBox(nameLab_4[i],posX+j,590,10,16,50));
1150 CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox);
1151 Controls->Add(cltbPtr->GetLabel());
1152 Controls->Add(cltbPtr->GetTextBox());
1153 }
1154
1155 // Prc label tt seul
1156 Label* prc = new Label();
1157 prc->Location = Point(50, 430);
1158 prc->Size = System::Drawing::Size(50,32);
1159 prc->Text = "Prc (kW)";//zone de texte initialisée
1160 prc->TextAlign = ContentAlignment::MiddleRight;
1161 Controls->Add(prc);
1162 j=100;//depart affichage
1163 for (int i=0;i<NB_BANCS;indexTextBox++,i++,j+=180)//creation des controles dans le formulaire
1164 {
1165 int posX=70;
1166 pal->Add(new CLabelTextBox(nameLab_3[i],posX+j,430,10,16,50));
1167 CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox);
1168 Controls->Add(cltbPtr->GetLabel());
1169 Controls->Add(cltbPtr->GetTextBox());
1170 }
1171
1172 // Pic label tt seul
1173 Label* pic = new Label();
1174 pic->Location = Point(50, 470);
1175 pic->Size = System::Drawing::Size(50,32);
1176 pic->Text = "Pic (kW)";//zone de texte initialisée
1177 pic->TextAlign = ContentAlignment::MiddleRight;
1178 Controls->Add(pic);
1179 j=100;//depart affichage
1180 for (int i=0;i<NB_BANCS;indexTextBox++,i++,j+=180)//creation des controles dans le formulaire
1181 {
1182 int posX=70;
1183 pal->Add(new CLabelTextBox(nameLab_3[i],posX+j,470,10,16,50));
1184 CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox);
1185 Controls->Add(cltbPtr->GetLabel());
1186 Controls->Add(cltbPtr->GetTextBox());
1187 }
1188
1189 // Pch label tt seul
1190 Label* pch = new Label();
1191 pch->Location = Point(50, 510);
1192 pch->Size = System::Drawing::Size(50,32);
1193 pch->Text = "Pch (kW)";//zone de texte initialisée
1194 pch->TextAlign = ContentAlignment::MiddleRight;
1195 Controls->Add(pch);
1196 j=100;//depart affichage
1197 for (int i=0;i<NB_BANCS;indexTextBox++,i++,j+=180)//creation des controles dans le formulaire
1198 {
1199 int posX=70;
1200 pal->Add(new CLabelTextBox(nameLab_3[i],posX+j,510,10,16,50));
1201 CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox);
1202 Controls->Add(cltbPtr->GetLabel());
1203 Controls->Add(cltbPtr->GetTextBox());
1204 }
1205
1206 // Ie_cur label tt seul
1207 Label* ie_cur = new Label();
1208 ie_cur->Location = Point(50, 550);
1209 ie_cur->Size = System::Drawing::Size(50,32);
1210 ie_cur->Text = "Ie_cur (V)";//zone de texte initialisée
1211 ie_cur->TextAlign = ContentAlignment::MiddleRight;
1212 Controls->Add(ie_cur);
1213 j=100;//depart affichage
1214 for (int i=0;i<NB_BANCS;indexTextBox++,i++,j+=180)//creation des controles dans le formulaire
1215 {
1216 int posX=70;
1217 pal->Add(new CLabelTextBox(nameLab_3[i],posX+j,550,10,16,50));
1218 CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox);
1219 Controls->Add(cltbPtr->GetLabel());
1220 Controls->Add(cltbPtr->GetTextBox());
1221 }
1222
1223 // Num_P label tt seul
1224 Label* num_P = new Label();
1225 num_P->Location = Point(50, 350);
1226 num_P->Size = System::Drawing::Size(50,32);
1227 num_P->Text = "Num_P";//zone de texte initialisée
1228 num_P->TextAlign = ContentAlignment::MiddleRight;
1229 Controls->Add(num_P);
1230 j=100;//depart affichage
1231 for (int i=0;i<NB_BANCS;indexTextBox++,i++,j+=180)//creation des controles dans le formulaire
1232 {
1233 int posX=70;
1234 pal->Add(new CLabelTextBox(nameLab_3[i],posX+j,350,10,16,50));
1235 CLabelTextBox* cltbPtr = (CLabelTextBox *) pal->get_Item(indexTextBox);
1236 Controls->Add(cltbPtr->GetLabel());
1237 Controls->Add(cltbPtr->GetTextBox());
1238 }
1239
1240 // crée un objet graphique
1241 Graphics* pg = this->CreateGraphics();
1242 //crée un objet pen
1243 Pen* pen1 = new Pen(Color::Red);
1244 //trace une ligne
1245 pg->DrawLine(pen1,20,20,100,100);
1246 //dispose l'objet Graphics
1247 pg->Dispose();
1248
1249 // ajout du groupe dans le formulaire.
1250 Controls->Add(gboxC);
1251
1252/*
1253 // associe le gestionnaire au groupe d'options
1254 rb1->Click += new EventHandler(this, &MaDialogUser::Radio_Clicked);
1255 rb2->Click += new EventHandler(this, &MaDialogUser::Radio_Clicked);
1256 */ }
1257
1258void MaDialogUser::Setup_Buttons_Conditionning()//creation et definition des boutons
1259 {
1260 // ajoute bouton START
1261 btnStart = new Button();
1262 btnStart->Text = S"MARCHE";//se sert de sa propriété Text pour definir son titre
1263 btnStart->Size = System::Drawing::Size(70, 20);//taille du bouton en pixels
1264 btnStart->Location = Point(70, 720);//emplacement
1265 btnStart->Click += new EventHandler(this, &MaDialogUser::BtnStart_Clicked);//creation d'un objet EventHandler en..
1266 //..lui transmettant un ptr sur le bouotn et l'adresse de la fonction en charge de..
1267 //..l'evenement
1268 Controls->Add(btnStart);//pour avertir le formulaire de la présence du bouton, on ajoute le bouton..
1269 //.. dans la collection des controles du formulaire
1270
1271 // idem bouton STOP
1272 btnStop = new Button();
1273 btnStop->Text = S"ARRET";
1274 btnStop->Size = System::Drawing::Size(70, 20);
1275 btnStop->Location = Point(150, 720);
1276 btnStop->Click += new EventHandler(this, &MaDialogUser::BtnStop_Clicked);
1277 Controls->Add(btnStop);
1278
1279 // idem bouton PAUSE
1280 btnPause = new Button();
1281 btnPause->Text = S"PAUSE";
1282 btnPause->Size = System::Drawing::Size(70, 20);
1283 btnPause->Location = Point(230, 720);
1284 btnPause->Click += new EventHandler(this, &MaDialogUser::BtnPause_Clicked);
1285 Controls->Add(btnPause);
1286
1287 // idem bouton REPRISE
1288 btnReprise = new Button();
1289 btnReprise->Text = S"REPRISE";
1290 btnReprise->Size = System::Drawing::Size(70, 20);
1291 btnReprise->Location = Point(310, 720);
1292 btnReprise->Click += new EventHandler(this, &MaDialogUser::BtnReprise_Clicked);
1293 Controls->Add(btnReprise);
1294 }
1295
1296void MaDialogUser::Radio_Clicked(Object* pSender, EventArgs* pArgs)//remplit automatiquement la zone de texte
1297 {
1298 if (pSender == rb1)
1299 {
1300 Console::WriteLine(S"MaDialogUser::Radio_Clicked : lecture activée...");
1301 Console::WriteLine(S"Main thread: Start a second thread.");
1302 // Create the thread, passing a ThreadStart delegate that
1303 // represents the ThreadReadModbus::ThreadProc method.
1304 uThread = new Thread(new ThreadStart(0, &MaDialogUser::ThreadProc));
1305 // Start the thread.
1306 uThread->Start();
1307 }
1308 else if (pSender == rb2)
1309 {
1310 Console::WriteLine(S"MaDialogUser::Radio_Clicked : lecture désactivée...");
1311 if (uThread->IsAlive)
1312 {
1313 // Stop the thread.
1314 uThread->Suspend();
1315 }
1316 }
1317 }
1318
1319void MaDialogUser::BtnStart_Clicked(Object* pSender, EventArgs* pArgs)//gestionnaire d'evenements associés au bouton 1
1320 {
1321 // MessageBox::Show(S"ça marche!", S"bouton START...");//MessageBox fait partie de l'espace de noms Forms
1322 //unique methode Show surchargée acceptant differents parametres
1323 CLabelTextBox* cltbPtr;
1324 for (int indexArrayList=0;(indexArrayList<MAX_NB_LABEL_TEXTBOX);indexArrayList++)//on cherche le LabelBox "MODE"
1325 {
1326 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList);
1327 if(String::Compare(cltbPtr->GetName(),"MODE"))
1328 break;//on y est
1329 if(indexArrayList==(MAX_NB_LABEL_TEXTBOX-1))return;//il faut sortir si non trouvé
1330 }
1331 if(String::Compare(cltbPtr->GetVal(),"PULSING"))
1332 {
1333 uint16_t tab_rp_registers[1] = { 0x2 };
1334 Console::WriteLine(S"MaDialogUser::BtnStart_Clicked : write holding...");
1335 int rc = modbus_write_registers(ctx, 2048,1 , tab_rp_registers);
[18]1336 if (rc != 1)
[16]1337 Console::WriteLine(S"MaDialogUser::BtnStart_Clicked : write holding failed...");
1338 }
1339 }
1340
1341void MaDialogUser::BtnStop_Clicked(Object* pSender, EventArgs* pArgs)//gestionnaire d'evenements associés au bouton 1
1342 {
1343// MessageBox::Show(S"ça marche!", S"bouton STOP...");//MessageBox fait partie de l'espace de noms Forms
1344 //unique methode Show surchargée acceptant differents parametres
1345 CLabelTextBox* cltbPtr;
1346 for (int indexArrayList=0;(indexArrayList<MAX_NB_LABEL_TEXTBOX);indexArrayList++)//on cherche le LabelBox "MODE"
1347 {
1348 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList);
1349 if(String::Compare(cltbPtr->GetName(),"MODE"))
1350 break;//on y est
1351 if(indexArrayList==(MAX_NB_LABEL_TEXTBOX-1))return;//il faut sortir si non trouvé
1352 }
1353 if(String::Compare(cltbPtr->GetVal(),"PULSING"))
1354 {
1355 uint16_t tab_rp_registers[1] = { 0x0 };
1356 Console::WriteLine(S"MaDialogUser::BtnStart_Clicked : write holding...");
1357 int rc = modbus_write_registers(ctx, 2048,1 , tab_rp_registers);
[18]1358 if (rc != 1)
[16]1359 Console::WriteLine(S"MaDialogUser::BtnStart_Clicked : write holding failed...");
1360 }
1361 }
1362
1363void MaDialogUser::BtnPause_Clicked(Object* pSender, EventArgs* pArgs)//gestionnaire d'evenements associés au bouton 1
1364 {
1365// MessageBox::Show(S"ça marche!", S"bouton PAUSE...");//MessageBox fait partie de l'espace de noms Forms
1366 //unique methode Show surchargée acceptant differents parametres
1367 CLabelTextBox* cltbPtr;
1368 for (int indexArrayList=0;(indexArrayList<MAX_NB_LABEL_TEXTBOX);indexArrayList++)//on cherche le LabelBox "MODE"
1369 {
1370 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList);
1371 if(String::Compare(cltbPtr->GetName(),"MODE"))
1372 break;//on y est
1373 if(indexArrayList==(MAX_NB_LABEL_TEXTBOX-1))return;//il faut sortir si non trouvé
1374 }
1375 if(String::Compare(cltbPtr->GetVal(),"PULSING"))
1376 {
1377 uint16_t tab_rp_registers[1] = { 0x1 };
1378 Console::WriteLine(S"MaDialogUser::BtnStart_Clicked : write holding...");
1379 int rc = modbus_write_registers(ctx, 2048,1 , tab_rp_registers);
[18]1380 if (rc != 1)
[16]1381 Console::WriteLine(S"MaDialogUser::BtnStart_Clicked : write holding failed...");
1382 }
1383 }
1384
1385void MaDialogUser::BtnReprise_Clicked(Object* pSender, EventArgs* pArgs)//gestionnaire d'evenements associés au bouton 1
1386 {
1387// MessageBox::Show(S"ça marche!", S"bouton REPRISE...");//MessageBox fait partie de l'espace de noms Forms
1388 //unique methode Show surchargée acceptant differents parametres
1389 CLabelTextBox* cltbPtr;
1390 for (int indexArrayList=0;(indexArrayList<MAX_NB_LABEL_TEXTBOX);indexArrayList++)//on cherche le LabelBox "MODE"
1391 {
1392 cltbPtr = (CLabelTextBox *) pal->get_Item(indexArrayList);
1393 if(String::Compare(cltbPtr->GetName(),"MODE"))
1394 break;//on y est
1395 if(indexArrayList==(MAX_NB_LABEL_TEXTBOX-1))return;//il faut sortir si non trouvé
1396 }
1397 if(String::Compare(cltbPtr->GetVal(),"PULSING"))
1398 {
1399 uint16_t tab_rp_registers[1] = { 0x3 };
1400 Console::WriteLine(S"MaDialogUser::BtnStart_Clicked : write holding...");
1401 int rc = modbus_write_registers(ctx, 2048,1 , tab_rp_registers);
[18]1402 if (rc != 1)
[16]1403 Console::WriteLine(S"MaDialogUser::BtnStart_Clicked : write holding failed...");
1404 }
1405 }
1406
1407
1408void AboutBox::OKButton_Clicked(Object* pSender,EventArgs* pArgs)//gestionnaire d'evenement de la boite dialogue
1409 {
1410
1411 //se contente de fermer le formulaire lorsqu'on clique sur le bouton
1412 Close();
1413 }
1414
1415void MaDialog::OKMaDBtn_Clicked(Object* pSender,EventArgs* pArgs)//gestionnaire d'evenement de la boite dialogue
1416 {
1417 //fermer le formulaire lorsqu'on clique sur le bouton
1418 Close();
1419 }
1420
1421AboutBox::AboutBox()//constructeur
1422 {
1423 // qqs propriétés
1424 Text = S"A propos cxfel";
1425 FormBorderStyle = FormBorderStyle::Fixed3D;//impossible de modifier la taille
1426 Size = System::Drawing::Size(300,150);
1427
1428 // ajout de 2 labels au formulaire.
1429 Label* label1 = new Label();
1430 label1->Text = "Application client XFEL";
1431 label1->Size = System::Drawing::Size(label1->PreferredWidth,
1432 label1->PreferredHeight);
1433 label1->Location = Point(20, 30);
1434
1435 Label* label2 = new Label();
1436 label2->Text = "JC Marrucho, 2013";
1437 label2->Size = System::Drawing::Size(label1->PreferredWidth,
1438 label1->PreferredHeight);//sert à modifier auto la taille des labels..
1439 //..selon le texte
1440 label2->Location = Point(20, 30+label1->PreferredHeight+10);//sert à calculer la position du 2ème label
1441
1442 // Ajoute les controles dans le formulaire
1443 Controls->Add(label1);
1444 Controls->Add(label2);
1445
1446 // Ajout d'un bouton OK.
1447 OKButton = new Button();
1448 OKButton->Text = S"OK";
1449 OKButton->DialogResult = System::Windows::Forms::DialogResult::OK;//renvoi de la valeur OK..
1450 //.. plus besoin d'associer le gestionnaire à sa fonction.. voir plus bas
1451 OKButton->Size = System::Drawing::Size(40,25);
1452 OKButton->Location = Point(240,85);
1453
1454 //configure un gestionnaire : pas nécessaire si le formulaire renvoie une valeur.. voir + haut
1455 //OKButton->Click += new EventHandler(this,&AboutBox::OKButton_Clicked);
1456
1457 // Ajoute le bouton au formulaire.
1458 Controls->Add(OKButton);
1459 }
1460
1461
1462MaDialog::MaDialog()
1463 {
1464 // définit les paramètres du formulaire
1465 Text = S"détails serveur";
1466 FormBorderStyle = FormBorderStyle::Fixed3D;//impossible de modifier la taille
1467 Size = System::Drawing::Size(280,200);
1468
1469 // Creation de tous les controles : TextBox pour io/port et ComboBox pour timeout
1470 ipLabel = new Label();
1471 ipBox = new TextBox();
1472 portLabel = new Label();
1473 portBox = new TextBox();
1474 timeoutLabel = new Label();
1475 timeoutCombo = new ComboBox();
1476 OKBtn = new Button();
1477 CancelBtn = new Button();
1478
1479 // ipLabel et ipBox : label et zone de saisie sont placés l'un à côté de l'autre
1480 ipLabel->Location = Point(16, 24);
1481 ipLabel->Size = System::Drawing::Size(48, 16);
1482 ipLabel->Text = "n°IP:";//zone de texte initialisée vide
1483 ipLabel->TextAlign = ContentAlignment::MiddleRight;
1484 ipBox->Location = Point(72, 24);
1485 ipBox->Size = System::Drawing::Size(152, 20);
1486 ipBox->Text = "";//zone de texte initialisée vide
1487
1488 // portLabel et portBox
1489 portLabel->Location = Point(16, 56);
1490 portLabel->Size = System::Drawing::Size(48, 16);
1491 portLabel->Text = "n°port:";//zone de texte initialisée vide
1492 portLabel->TextAlign = ContentAlignment::MiddleRight;
1493 portBox->Location = Point(72, 56);
1494 portBox->Size = System::Drawing::Size(152, 20);
1495 portBox->Text = "";//zone de texte initialisée
1496
1497 // timeoutLabel et timeoutCombo : : liste déroulante spécifiant le tiemout et son label
1498 timeoutLabel->Location = Point(16, 88);
1499 timeoutLabel->Size = System::Drawing::Size(48, 16);
1500 timeoutLabel->Text = "Timeout(ms):";
1501 timeoutLabel->TextAlign = ContentAlignment::MiddleRight;
1502 timeoutCombo->DropDownWidth = 121;
1503 timeoutCombo->Location = Point(72, 88);
1504 timeoutCombo->Size = System::Drawing::Size(121, 21);
1505 //5 items, pas de valeur par défaut
1506 timeoutCombo->Items->Add(S"500");
1507 timeoutCombo->Items->Add(S"1000");
1508 timeoutCombo->Items->Add(S"1500");
1509 timeoutCombo->Items->Add(S"2000");
1510 timeoutCombo->Items->Add(S"3000");
1511
1512 // bouton OK
1513 OKBtn->Location = Point(104, 136);
1514 OKBtn->Name = "Bouton OK";
1515 OKBtn->Text = "OK";
1516 OKBtn->DialogResult = DialogResult::OK;
1517
1518 // bouton Cancel
1519 CancelBtn->Location = Point(192, 136);
1520 CancelBtn->Name = "Bouton Cancel";
1521 CancelBtn->Text = "Annuler";
1522 CancelBtn->DialogResult = DialogResult::Cancel;
1523
1524 // Ajoute les controles dans le formaulaire
1525 Controls->Add(ipBox);
1526 Controls->Add(portBox);
1527 Controls->Add(ipLabel);
1528 Controls->Add(portLabel);
1529 Controls->Add(timeoutLabel);
1530 Controls->Add(timeoutCombo);
1531 Controls->Add(OKBtn);
1532 Controls->Add(CancelBtn);
1533
1534 //configure les 2 propriétés : AcceptButton contient la réf du bouton par défaut du formulaire..
1535 //..on peut cliquer sur le bouton OK ou bien sur la touche Entrée du clavier..
1536 //..referme aussi la boite car DialogResult renvoie OK
1537 AcceptButton = OKBtn;
1538 //CancelButton contient la réf du bouton associée à la touche Echap du clavier
1539 CancelButton = CancelBtn;
1540
1541 //gestionnnaire associé au bouton OK
1542 OKBtn->Click += new EventHandler(this, &MaDialog::OKMaDBtn_Clicked);
1543 }
1544
1545void MaDialog::setIp(String* theIp)
1546{
1547 ipBox->Text = theIp;
1548}
1549
1550String* MaDialog::getIp()
1551{
1552 return ipBox->Text;
1553}
1554
1555void MaDialog::setPort(String* thePort)
1556{
1557 portBox->Text = thePort;
1558}
1559
1560String* MaDialog::getPort()
1561{
1562 return portBox->Text;
1563}
1564
1565void MaDialog::setTimeout(int theTimeout)
1566{
1567 timeoutCombo->SelectedIndex = theTimeout;
1568}
1569
1570int MaDialog::getTimeout()
1571{
1572 return timeoutCombo->SelectedIndex;
1573}
1574
1575
1576CppForm::CppForm()//constructeur
1577 {
1578 // définit la légende du formulaire
1579 //la propriété Text est héritée de Control
1580 Text = S"XSUC";
1581
1582 // définit le style des bords
1583 //la propriété FormBorder est membre de Form
1584 FormBorderStyle = FormBorderStyle::Fixed3D;
1585
1586 // Set up controls on the form.
1587 Setup_Menu();
1588 Setup_Context_Menu();
1589 Setup_Buttons();//configure les boutons du formulaire
1590 Setup_Label();
1591// Setup_Group();
1592// Setup_Combo();
1593 Setup_Text();
1594
1595 // pour agrandir la zone de saisie, on rajoute des pixels, par defaut 300x300
1596 // Size = System::Drawing::Size(450, 300);
1597 Size = System::Drawing::Size(650, 500);
1598
1599 }
1600
1601void CppForm::Btn1_Clicked(Object* pSender, EventArgs* pArgs)//gestionnaire d'evenements associés au bouton 1
1602 {
1603 MessageBox::Show(S"ça marche!", S"Message...");//MessageBox fait partie de l'espace de noms Forms
1604 //unique methode Show surchargée acceptant differents parametres
1605 }
1606
1607
1608void CppForm::Btn2_Clicked(Object* pSender, EventArgs* pArgs)//gestionnaire d'evenements associés au bouton 2
1609 {
1610 MessageBox::Show(S"ça marche aussi!", S"Message...");//MessageBox fait partie de l'espace de noms Forms
1611 //unique methode Show surchargée acceptant differents parametres
1612 }
1613
1614void CppForm::Btn3_Clicked(Object* pSender, EventArgs* pArgs)//gestionnaire d'evenements associés au bouton 3
1615 {
1616 MessageBox::Show(S"connexion et lecture serveur", S"Message...");//MessageBox fait partie de l'espace de noms Forms
1617 //unique methode Show surchargée acceptant differents parametres
1618 }
1619
1620void CppForm::Btn4_Clicked(Object* pSender, EventArgs* pArgs)//gestionnaire d'evenements associés au bouton 4
1621 {
[18]1622/* uint16_t tab_rp_registers_low[MODBUS_SIZE_READ_HOLDINGS_LOW];
1623 uint16_t tab_rp_registers_high[MODBUS_SIZE_READ_HOLDINGS_HIGH];
1624 int rc, adress, size;
1625 Console::WriteLine(S"ThreadProc: read holdings...");
1626 adress=MODBUS_BASE_LOW_HOLDINGS;//adresse holding=MODBUS_BASE_LOW_HOLDINGS
1627 size=82;
1628 rc = modbus_read_registers(ctx, adress, size, tab_rp_registers_low);
1629 if (rc != size)
1630 Console::WriteLine(S"ThreadProc: read holdings failed...");
1631 Thread::Sleep(500);
1632 Console::WriteLine(S"ThreadProc: read holdings...");
1633 adress=MODBUS_BASEADR_HIGH_HOLDINGS;//adresse holding=MODBUS_BASEADR_HIGH_HOLDINGS
1634 size=MODBUS_SIZE_READ_HOLDINGS_HIGH;
1635 rc = modbus_read_registers(ctx, adress, size, tab_rp_registers_high);
1636 if (rc != size)
1637 Console::WriteLine(S"ThreadProc: read holdings failed...");
1638*/
[16]1639 //crée la boite de dialogue utilisateur
1640 CDialogConfig* box = new CDialogConfig();
1641 //affiche la boite de dialogue
1642 if (box->ShowDialog() == DialogResult::OK)
1643 {
1644 //si la valeur OK est renvoyée, on affiche le nom
1645 //MessageBox::Show(S"Ecriture");
1646 }
1647 //unique methode Show surchargée acceptant differents parametres
1648 }
1649
1650void CppForm::Combo1_SelChanged(Object* pSender, EventArgs* pArgs)//gestionnaire d'evenement associé à la liste deroulante
1651 {
1652 if (pSender == combo1)
1653 {
1654// String* ps = String::Concat(S"New index is ",
1655// __box(combo1->SelectedIndex)->ToString());
1656// MessageBox::Show(ps, S"Index Change");
1657 String* ps = __box(combo1->SelectedIndex)->ToString();
1658 if(String::Compare(ps,"1")==0)
1659 {
1660 Console::WriteLine(S"Main thread: Start a second thread.");
1661 // Create the thread, passing a ThreadStart delegate that
1662 // represents the ThreadReadModbus::ThreadProc method.
1663 Thread *oThread = new Thread(new ThreadStart(0, &ThreadReadModbus::ThreadProc));
1664 // Start the thread.
1665 oThread->Start();
1666 }
1667 }
1668 }
1669
1670void CppForm::MenuItem_Clicked(Object* pSender, EventArgs* pArgs)//gestionnaire des elements de menu
1671 {
1672 if (pSender == item1)
1673 {
1674 //affiche la boite de dialogue modale qui doit etre fermée avant de pouvoir revenir à l'application
1675 MessageBox::Show(S"ITEM à propos", S"Menu");
1676 AboutBox* box = new AboutBox();
1677 box->ShowDialog();
1678 }
1679 else if (pSender == item2)
1680 {
1681 // Exit application.
1682 Application::Exit();
1683 }
1684 else if (pSender == item11)
1685 {
1686 //crée la boite de dialogue
1687 MaDialog* box = new MaDialog();
1688 //données initiales
1689/* String* path = new String("c:\\temp\\condip.txt.txt");
1690 if (!File::Exists(path))
1691 {
1692 Console::WriteLine("le fichier n'existe pas!");
1693 }
1694*/
1695 //lecture du n°IP dans le fichier condip
1696 try
1697 {
1698 FileStream* fs = new FileStream("..\\condip.txt",FileMode::Open);
1699 StreamReader* sr = new StreamReader(fs);
1700 String* line = sr->ReadLine();
1701 box->setIp(line);
1702 }
1703 catch (System::Exception* pe)
1704 {
1705 Console::WriteLine(pe->ToString());
1706 }
1707// box->setIp(S"134.158.91.254");
1708 box->setPort(S"502");
1709 box->setTimeout(1);
1710 //affiche la boite de dialogue
1711 if (box->ShowDialog() == DialogResult::OK)
1712 {
1713 //si la valeur OK est renvoyée, on affiche le nom
1714 MessageBox::Show(box->getIp(), S"le n° IP était...");
1715 }
1716
1717 }
1718 else if (pSender == anotherItem)
1719 {
1720 //crée la boite de dialogue utilisateur
1721 MaDialogUser* box = new MaDialogUser();
1722 //données initiales
1723 /* box->setIp(S"134.158.91.254");
1724 box->setPort(S"502");
1725 box->setTimeout(1);
1726 */ //affiche la boite de dialogue
1727 if (box->ShowDialog() == DialogResult::OK)
1728 {
1729 //si la valeur OK est renvoyée, on affiche le nom
1730 MessageBox::Show(S"Lecture");
1731 }
1732 }
1733 else if (pSender == item1_1 || pSender == item1_2)
1734 {
1735// modbus_t *ctx;
1736 if(pSender == item1_1)
1737 {
1738// ctx = (modbus_t *) malloc(sizeof(modbus_t));
1739// Ex20cSquareRoot(4);
1740 // char* ptr = GetHeure(1);
1741 /* String* psone = String::Concat(S"il est ", GetHeure(1));
1742 MessageBox::Show(psone, S"heure");
1743 int* monInt = allou();
1744 int taille=sizeof(monInt);
1745 Console::WriteLine(taille);
1746 libere(monInt);
1747*/
1748 //lecture du n°IP dans le fichier condip
1749 String* lineIp;
1750 try
1751 {
1752 FileStream* fs = new FileStream("..\\condip.txt",FileMode::Open);
1753 StreamReader* sr = new StreamReader(fs);
1754 lineIp = sr->ReadLine();
1755 }
1756 catch (System::Exception* pe)
1757 {
1758 Console::WriteLine(pe->ToString());
1759 }
1760
1761 Console::WriteLine(S"CppForm::MenuItem_Clicked : modbus_new_tcp...");
1762// ctx = modbus_new_tcp("134.158.91.254", 502);//JCM
1763 char* chaineChar = static_cast<char *>(System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(lineIp).ToPointer());
1764 ctx = modbus_new_tcp(chaineChar,502);//JCM
1765 modbus_set_debug(ctx, 1);
1766// modbus_set_error_recovery(ctx,
1767// MODBUS_ERROR_RECOVERY_LINK |
1768// MODBUS_ERROR_RECOVERY_PROTOCOL);
1769 modbus_set_slave(ctx,1);//JCM: avec le serveur python slave=1
1770 if (modbus_connect(ctx) == -1) {
1771 Console::WriteLine(modbus_strerror(errno));
1772 modbus_free(ctx);
1773 }
1774 }
1775 else
1776 {
1777 modbus_free(ctx);
1778 }
1779 }
1780 else if (pSender == fontDlgItem)
1781 {
1782 FontDialog* fd = new FontDialog();
1783 fd->Font = labelFont;
1784
1785 if (fd->ShowDialog() == DialogResult::OK)//la police du label est modifiée selon le choix d el'uitlisateur
1786 {
1787 MessageBox::Show(fd->Font->Name, S"la police était...");
1788 labelFont = fd->Font;
1789 theLabel->Font = labelFont;
1790 }
1791 }
1792 else
1793 MessageBox::Show(S"AUTRE ITEM", S"Menu");
1794 }
1795
1796void CppForm::Radio_Clicked(Object* pSender, EventArgs* pArgs)//remplit automatiquement la zone de texte
1797 {
1798 if (pSender == rb1)
1799 {
1800 text1->Text = "Read Coils choisi : \r\n\r\n"
1801 "FC01";
1802 uint8_t tab_rp_bits[1];
[18]1803 int rc = modbus_read_bits(ctx, MODBUS_BASEADR_COILS, 1, tab_rp_bits);////JCM : adresse coils=MODBUS_BASEADR_COILS
[16]1804 Console::WriteLine(S"CppForm::Radio_Clicked : read one coil...");
1805 if (rc != 1)
1806 Console::WriteLine(S"CppForm::Radio_Clicked : read one coil failed...");
1807 }
1808 else if (pSender == rb2)
1809 {
1810 text1->Text = "Write Coils choisi : \r\n\r\n"
1811 "FC15";
1812 uint8_t tab_value[77];//JCM
1813 modbus_set_bits_from_bytes(tab_value, 0, 77, UT_BITS_TAB);
1814 printf("tab[0]=%d,tab[1]=%d,tab[2]=%d\n", tab_value[0], tab_value[1], tab_value[2]);
[18]1815 int rc = modbus_write_bits(ctx, MODBUS_BASEADR_COILS,//JCM : adresse coils=MODBUS_BASEADR_COILS
[16]1816 77, tab_value);
1817 if (rc != 77)
1818 Console::WriteLine(S"CppForm::Radio_Clicked : write coil failed...");
1819 }
1820 else if (pSender == rb3)
1821 {
1822 text1->Text = "Read Holdings choisi : \r\n\r\n"
1823 "FC03";
1824 uint16_t tab_rp_registers[UT_REGISTERS_NB];
[18]1825 int rc = modbus_read_registers(ctx, MODBUS_BASEADR_LOW_HOLDINGS,//JCM : adresse holding=MODBUS_BASEADR_LOW_HOLDINGS
[16]1826 UT_REGISTERS_NB, tab_rp_registers);
1827 Console::WriteLine(S"CppForm::Radio_Clicked : read holding...");
1828 if (rc != UT_REGISTERS_NB)
1829 Console::WriteLine(S"CppForm::Radio_Clicked : read holding failed...");
1830 }
1831 else if (pSender == rb4)
1832 {
1833 text1->Text = "Write Holdings choisi :\r\n\r\n"
1834 "FC16";
1835 Random* myRnd = new Random();
1836 float realToWrite, real = myRnd->NextDouble();
1837 printf("random = %f\n", real<0.5 ? realToWrite=-1000*real:realToWrite=1000*real);
1838
1839 uint16_t tab_rp_registers[48];
1840 Console::WriteLine(S"CppForm::Radio_Clicked : write holding...");
1841 modbus_set_float(realToWrite, tab_rp_registers);//Pi_min
1842 int rc = modbus_write_registers(ctx, 2118,48 , tab_rp_registers);
1843 if (rc != 48)
1844 Console::WriteLine(S"CppForm::Radio_Clicked : write holding failed...");
1845 }
1846 }
1847
1848void CppForm::Setup_Buttons()//creation et definition du bouton
1849 {
1850 // ajoute un bouton
1851 btn1 = new Button();
1852 btn1->Text = S"OK";//se sert de sa propriété Text pour definir son titre
1853
1854 btn1->Size = System::Drawing::Size(70, 25);//taille du bouton en pixels
1855 btn1->Location = Point(230, 400);//emplacement
1856// btn1->Font = new System::Drawing::Font(S"Verdana", 16, FontStyle::Bold);;//l'objet Font est sauvegardé dans l'objet LabelFont grâce au pointeur
1857// btn1->ForeColor = Color::Brown;
1858
1859 btn1->Click += new EventHandler(this, &CppForm::Btn1_Clicked);//creation d'un objet EventHandler en..
1860 //..lui transmettant un ptr sur le bouotn et l'adresse de la fonction en charge de..
1861 //..l'evenement
1862
1863 Controls->Add(btn1);//pour avertir le formulaire de la présence du bouton, on ajoute le bouton..
1864 //.. dans la collection des controles du formulaire
1865
1866 // idem pour 2eme bouton
1867 btn2 = new Button();
1868 btn2->Text = S"Annuler";//..
1869
1870 btn2->Size = System::Drawing::Size(70, 25);//..
1871 btn2->Location = Point(310, 400);//..
1872 btn2->Click += new EventHandler(this, &CppForm::Btn2_Clicked);
1873 Controls->Add(btn2);//..
1874 //..
1875
1876 // idem pour 3eme bouton
1877 btn3 = new Button();
1878 btn3->Text = S"Connexion";//..
1879
1880 btn3->Size = System::Drawing::Size(120, 25);//..
1881 btn3->Location = Point(50, 220);//..
1882 btn3->Font = new System::Drawing::Font(S"Verdana", 12, FontStyle::Bold);;//l'objet Font est sauvegardé dans l'objet LabelFont grâce au pointeur
1883 btn3->ForeColor = Color::Brown;
1884
1885 btn3->Click += new EventHandler(this, &CppForm::Btn3_Clicked);
1886 Controls->Add(btn3);//..
1887 //..
1888 // idem pour 4eme bouton
1889 btn4 = new Button();
1890 btn4->Text = S"Ecriture";//..
1891
1892 btn4->Size = System::Drawing::Size(120, 25);//..
1893 btn4->Location = Point(475, 220);//..
1894 btn4->Font = new System::Drawing::Font(S"Verdana", 12, FontStyle::Bold);;//l'objet Font est sauvegardé dans l'objet LabelFont grâce au pointeur
1895 btn4->ForeColor = Color::Brown;
1896
1897 btn4->Click += new EventHandler(this, &CppForm::Btn4_Clicked);
1898 Controls->Add(btn4);//..
1899 //..
1900
1901 }
1902
1903void CppForm::Setup_Combo ()//configuration de la liste deroulmnte
1904 {
1905 // creation
1906 combo1 = new ComboBox();
1907 combo1->DropDownStyle = ComboBoxStyle::DropDownList;
1908// combo1->Location = Point(20,180);
1909 combo1->Location = Point(20,280);
1910
1911 // pour ajuster la taille en fonction de la plus longue chaine
1912 // la valeur 20 correspond à la taille du bouton situé à droite du bouton d'édition
1913 Label* l1 = new Label();
1914 l1->Text = S"Automatique";
1915 combo1->Width = l1->PreferredWidth + 20;
1916
1917 // ajout de qqs chaines et association avec tous les controles du formulaire
1918 combo1->Items->Add(S"Manuel");
1919 combo1->Items->Add(S"Automatique");
1920 combo1->Items->Add(S"...");
1921 combo1->SelectedIndex = 0;//affiche la 1ere chaine par defaut
1922
1923 // ajout du groupe dans le formulaire
1924 Controls->Add(combo1);
1925
1926 // associe le gestionnaire à liste deroulante.
1927 combo1->SelectedIndexChanged += new EventHandler(this, &CppForm::Combo1_SelChanged);
1928 }
1929
1930void CppForm::Setup_Context_Menu ()//menu contextuel
1931 {
1932 // Creation
1933 popupMenu = new System::Windows::Forms::ContextMenu();
1934
1935 // Creation des items.
1936 item_p1 = new MenuItem("UN");
1937 popupMenu->MenuItems->Add(item_p1);
1938 item_p2 = new MenuItem("DEUX");
1939 popupMenu->MenuItems->Add(item_p2);
1940 item_p3 = new MenuItem("TROIS");
1941 popupMenu->MenuItems->Add(item_p3);
1942
1943 //associe le menu contextuel au formulaire
1944 ContextMenu = popupMenu;
1945 }
1946
1947void CppForm::Setup_Group ()//creation et configuration d'un groupe d'options
1948 {
1949 // Creation
1950 gbox = new GroupBox();
1951 gbox->Text = S"Fonction Code";
1952 gbox->Size = System::Drawing::Size(200, 150);//taille du groupbox en pixels
1953 gbox->Location = Point(20, 90);
1954
1955 // Creation des boutons radio.
1956 rb1 = new RadioButton();
1957 rb1->Text = S"Read Coils";
1958 rb1->Location = Point(10,25);
1959
1960 rb2 = new RadioButton();
1961 rb2->Text = S"Write Coils";
1962 rb2->Location = Point(10,55);
1963
1964 rb3 = new RadioButton();
1965 rb3->Text = S"Read Holdings";
1966 rb3->Location = Point(10,85);
1967// rb3->Checked = true;//c'est la valeur par defaut
1968
1969 rb4 = new RadioButton();
1970 rb4->Text = S"Write Holdings";
1971 rb4->Location = Point(10,115);
1972 rb4->Checked = true;//c'est la valeur par defaut
1973
1974 // ajout des controles dans le groupe
1975 gbox->Controls->Add(rb1);
1976 gbox->Controls->Add(rb2);
1977 gbox->Controls->Add(rb3);
1978 gbox->Controls->Add(rb4);
1979
1980 // ajout du groupe dans le formulaire.
1981 Controls->Add(gbox);
1982
1983 // associe le gestionnaire au groupe d'options
1984 rb1->Click += new EventHandler(this, &CppForm::Radio_Clicked);
1985 rb2->Click += new EventHandler(this, &CppForm::Radio_Clicked);
1986 rb3->Click += new EventHandler(this, &CppForm::Radio_Clicked);
1987 rb4->Click += new EventHandler(this, &CppForm::Radio_Clicked);
1988 }
1989
1990void CppForm::Setup_Label()//description textuelle dans le formulaire
1991 {
1992 theLabel = new Label();
1993 theLabel->AutoSize = true;
1994
1995 theLabel->Text = S" XFEL Supervision Client";//les espaces sont prévus pour inserer uen image
1996
1997 // definition de la police
1998 // labelFont = new System::Drawing::Font(S"Verdana", 20, FontStyle::Italic);
1999 labelFont = new System::Drawing::Font(S"Arial", 20, FontStyle::Italic);
2000 theLabel->Font = labelFont;//l'objet Font est sauvegardé dans l'objet LabelFont grâce au pointeur
2001 theLabel->ForeColor = Color::Black;
2002
2003 // taille et emplacement
2004// theLabel->Location = Point(300,20);
2005 theLabel->Location = Point(125,40);
2006 theLabel->Size = System::Drawing::Size(theLabel->PreferredWidth,
2007 theLabel->PreferredHeight);
2008
2009 // ajout de l'image
2010 // Bitmap* theImage = new Bitmap("SAVE.BMP");
2011 Bitmap* theImage = new Bitmap("..//image1.BMP");
2012 theLabel->Image = theImage;
2013 theLabel->ImageAlign = ContentAlignment::MiddleLeft;
2014
2015 // ajout du label dans la collection des controles du formulaire
2016 Controls->Add(theLabel);
2017 }
2018
2019void CppForm::Setup_Menu()//barre de menu
2020 {
2021 // Creation de la barre de menu principal
2022 menuBar = new MainMenu();
2023
2024 // Cree le menu fichier.
2025 fileMenu = new MenuItem("&Fichier");
2026 menuBar->MenuItems->Add(fileMenu);
2027
2028 // Cree les elements du menu et les affiche.
2029 item1 = new MenuItem("&A propos...");
2030 item11 = new MenuItem("&MaDialogBox...");
2031 fontDlgItem = new MenuItem("&Choisir la police...");
2032 item2 = new MenuItem("S&ortie");
2033 fileMenu->MenuItems->Add(item1);
2034 fileMenu->MenuItems->Add(item11);
2035 fileMenu->MenuItems->Add(fontDlgItem);
2036 fileMenu->MenuItems->Add(item2);
2037
2038 // associe le gestionnaire ayx elements du menu.
2039 item1->Click += new EventHandler(this, &CppForm::MenuItem_Clicked);
2040 item11->Click += new EventHandler(this, &CppForm::MenuItem_Clicked);
2041 fontDlgItem->Click += new EventHandler(this, &CppForm::MenuItem_Clicked);
2042 item2->Click += new EventHandler(this, &CppForm::MenuItem_Clicked);
2043
2044 // ajoute le menu principal dans le formulaire
2045 Menu = menuBar;
2046
2047 //,menu déroulant ajouté à la barre de menu, puis 2 éléments
2048 actionMenu =new MenuItem("Action");
2049 menuBar->MenuItems->Add(actionMenu);
2050 subMenu1=new MenuItem("Faire");
2051 actionMenu->MenuItems->Add(subMenu1);
2052 //barre de séparation, le ptr n'est pas sauvegardé car le sépérateur ne peut être sélectionné
2053 actionMenu->MenuItems->Add(new MenuItem("-"));
2054 anotherItem=new MenuItem("lecture serveur");
2055 actionMenu->MenuItems->Add(anotherItem);
2056 //crée les 2 élements du menu et les ajoute
2057 item1_1 =new MenuItem("connexion serveur...");
2058 item1_2 = new MenuItem("deconnexion serveur...");
2059 subMenu1->MenuItems->Add(item1_1);
2060 subMenu1->MenuItems->Add(item1_2);
2061 //on pourrait aussi utiliser des propriétés pour afficher un syumbole..
2062 //..disant élémen tselectionné (Checked) et griser des éléments du menu (Enabled)
2063
2064 // associe le gestionnaire aux elements du menu.
2065 anotherItem->Click += new EventHandler(this, &CppForm::MenuItem_Clicked);
2066 item1_1->Click += new EventHandler(this, &CppForm::MenuItem_Clicked);
2067 item1_2->Click += new EventHandler(this, &CppForm::MenuItem_Clicked);
2068 }
2069
2070void CppForm::Setup_Text()//controle d'edition
2071 {
2072 text1 = new TextBox();
2073 text1->Location = Point(200,110);
2074 text1->Size = System::Drawing::Size(250,250);
2075 text1->Multiline = true;
2076
2077 text1->ReadOnly = true;
2078 text1->Text = "Pour se connecter au Serveur : cliquer sur le bouton Connexion \r\n\r\n"
2079 "Pour configurer des paramètres : cliquer sur le bouton Ecriture \r\n\r\n";
2080
2081
2082 Controls->Add(text1);
2083 }
Note: See TracBrowser for help on using the repository browser.