Bonjour,
�tant un l�ger habitu� de delphi, la source de programmation qui fonctionne pour r�cup�rer une valeur sur mon port USB que j'ai pu trouv� est compil� sous Visual C++ et afin de l'utiliser j'essai de comprendre comment il fonctionne globalement.
J'ai pu rep�rer a quel moment la valeur est r�cup�rer et afficher dans une textbox, seulement mon probl�me est qu'il m'affiche ma valeur en ASCII et non comme je le souhaiterai en decimal.
Si je ne trompe pas la fonction qui r�cup�re ma donn�e est celle-ci
Puis je l'affiche ici :
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: System::Void serialPort1_DataReceived(System::Object^ sender, System::IO::Ports::SerialDataReceivedEventArgs^ e) { //The ReadExisting() function will read all of the data that // is currently available in the COM port buffer. In this // example we are sending all of the available COM port data // to the SetText() function. // // NOTE: the <SerialPort>_DataReceived() function is launched // in a seperate thread from the rest of the application. A // delegate function is required in order to properly access // any managed objects inside of the other thread. Since we // will be writing to a textBox (a managed object) the delegate // function is required. Please see the SetText() function for // more information about delegate functions and how to use them. try { SetText(serialPort1->ReadExisting()); } catch(...) { } }
s'il vous plait d�tes moi comment ou avec quelle fonction je peux afficher ma valeur en d�cimal ?
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 private: void SetText(String^ text) { //InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread. // If these threads are different, it returns true. We can // use this attribute to determine if we can append text // directly to the textbox or if we must launch an a delegate // function instance to write to the textbox. //if (this->txtDataReceived->InvokeRequired) if (this->txtDataReceived1->InvokeRequired) //Laurent { //InvokeRequired returned TRUE meaning that this function // was called from a thread different than the current // thread. We must launch a deleage function. //Create an instance of the SetTextCallback delegate and // assign the delegate function to be this function. This // effectively causes this same SetText() function to be // called within the main thread instead of the second // thread. SetTextCallback^ d = gcnew SetTextCallback(this,&VCCDC::Form1::SetText); //Invoke the new delegate sending the same text to the // delegate that was passed into this function from the // other thread. this->Invoke(d,gcnew String(text)); } else { //If this function was called from the same thread that // holds the required objects then just add the text. txtDataReceived1->AppendText(text); // laurent //txtDataReceived->AppendText(text); } }
Merci
Partager