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