Bonjour,

Je cherche à afficher plusieurs valeurs dans différentes textbox que je récupère sur mon bus USB , pour l'instant j'arrive à afficher une valeur dans une textbox, comme ça

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 
private: System::Void serialPort1_DataReceived(System::Object^  sender, System::IO::Ports::SerialDataReceivedEventArgs^  e) 
		{
 
			try
			{
 
 
 
				//Un tableau managé de quatre bytes
				array<System::Byte>^ buf = gcnew array<System::Byte>(4);
 
				//On lit les quatre bytes
				serialPort1->Read(buf, 0, 4);
 
 
				valeur = IntFromBytesLittleEndian(buf, 0);
				//Et on affiche en hexadécimal
				SetText(valeur.ToString("X8"));
 
 
 
			}
			catch(...)
			{
			}
		}
avec

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
		private: void SetText(String^ text)
		{
 
 
			if (this->txtDataReceived->InvokeRequired)
 
			{
 
 
				SetTextCallback^ d = gcnew SetTextCallback(this,&VCCDC::Form1::SetText);	
				this->Invoke(d, gcnew String(text));
 
			}
			else
			{
 
				textBox6->Clear();
				textBox6->AppendText(text);
 
 
			}
		}
Mais maintenant je souhaite afficher plusieurs valeurs, donc pour ça je fait un "switch case" comme ça

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
 
private: System::Void serialPort1_DataReceived(System::Object^  sender, System::IO::Ports::SerialDataReceivedEventArgs^  e) 
		{
 
			try
			{
 
 
 
				//serialPort1->Read(data[4], 0, 4);
 
				//textBox6->AppendText();
				//nbr_octet=Read(data[4], 0, 4);
				//val=IntFromBytesLittleEndian(data,4);
				//SetText(serialPort1->ReadExisting());
 
 
				//Un tableau managé de quatre bytes
				array<System::Byte>^ buf = gcnew array<System::Byte>(4);
 
				//On lit les quatre bytes
				serialPort1->Read(buf, 0, 4);
 
				switch (buf[3])
				{
				case 01 :	buf[3] = 0;
							//On les convertit en int
							valeur1 = IntFromBytesLittleEndian(buf, 0);
							//Et on affiche en hexadécimal
							SetText(valeur1.ToString("X8"));
							//Et on affiche en décimal
							//SetText(valeur1.ToString());
 
							break;
				case 02:	buf[3] = 0;
							//On les convertit en int
							valeur2 = IntFromBytesLittleEndian(buf, 0);
							//Et on affiche en hexadécimal
							SetText(valeur2.ToString("X8"));
							//Et on affiche en décimal
							//SetText(valeur.ToString());
							break;
				case 03:	buf[3] = 0;
							//On les convertit en int
							valeur3 = IntFromBytesLittleEndian(buf, 0);
							//Et on affiche en hexadécimal
							SetText(valeur3.ToString("X8"));
							//Et on affiche en décimal
							//SetText(valeur.ToString());
							break;
				case 04:	buf[3] = 0;
							//On les convertit en int
							valeur4 = IntFromBytesLittleEndian(buf, 0);
							//Et on affiche en hexadécimal
							SetText(valeur4.ToString("X8"));
							//Et on affiche en décimal
							//SetText(valeur.ToString());
							break;
 
 
 
				default:
					//valeur = IntFromBytesLittleEndian(buf, 0);
					//Et on affiche en hexadécimal
					//SetText(valeur.ToString("X8"));
					break;
				}
 
 
 
 
			}
			catch(...)
			{
			}
		}

est-il possible d'afficher directement dans les case : exemple

case 01

faire quelques chose comme textbox6.Text = valeur1.ToString("X8"); Pour le moment pour afficher ma valeur je dois faire comme ça SetText(valeur1.ToString("X8"));

avec dans la fonction

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
		private: void SetText(String^ text)
 
		{
 
			if (this->txtDataReceived->InvokeRequired)
 
			{
 
				SetTextCallback^ d = gcnew SetTextCallback(this,&VCCDC::Form1::SetText);
 
				this->Invoke(d, gcnew String(text));
 
			}
			else
			{
 
				textBox6->Clear();
				textBox6->AppendText(text);
 
 
 
 
			}
		}
Je suis obligé de passer par cette fonction pour afficher quelque chose dans une textbox ?
un appendtext directement dans mon case ne fonctionne pas