Visual C++ .NET - Traducir código C# 2013 a C++ 2013

 
Vista:
sin imagen de perfil
Val: 4
Ha disminuido su posición en 7 puestos en Visual C++ .NET (en relación al último mes)
Gráfica de Visual C++ .NET

Traducir código C# 2013 a C++ 2013

Publicado por Meta (7 intervenciones) el 25/02/2015 13:56:14
Hola:

Tengo este código de C# 2013 que no soy capaz de traducirlo del todo bien a Visual C++ 2013.
Les dejo el código Visual C# 2013 justo abajo.
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
using System.IO.Ports; // No olvidar.
 
namespace InterDuinoCS
{
    public partial class Form_Principal : Form
    {
        // Utilizremos un string como buffer de recepción.
        string Recibidos;
 
        public Form_Principal()
        {
            InitializeComponent();
 
            // Abrir puerto mientras se ejecute la aplicación.
            if(!serialPort1.IsOpen)
                {
                    try
                {
                    serialPort1.Open();
                }
                    catch (System.Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                    // Ejecutar la función Recepcion por disparo del Evento 'DataReived'.
                    serialPort1.DataReceived += new SerialDataReceivedEventHandler(Recepcion); // ERROR AQUÍ.
                }
        }
 
        // Al recibir datos.
        private void Recepcion(object sender, SerialDataReceivedEventArgs e)
        {
            // Acumula los caracteres recibidos a nuestro 'buffer' (string).
            Recibidos += serialPort1.ReadExisting();
 
            // Invocar o llamar al proceso de tramas.
            Invoke(new EventHandler(Actualizar)); // ERROR AQUÍ.
        }
 
        // Procesar los datos recibidos en el bufer y extraer tramas completas.
        private void Actualizar(object sender, EventArgs e)
        {
            // Asignar el valor de la trama al richTextBox.
            richTextBox_Mensajes.Text = Recibidos;
 
            // Selecciona la posición final para leer los mensajes entrantes.
            richTextBox_Mensajes.SelectionStart = richTextBox_Mensajes.Text.Length;
 
            // Mantiene el scroll en la entrada de cada mensaje.
            richTextBox_Mensajes.ScrollToCaret();
        }
 
        private void button_Led_ON_8_Click(object sender, EventArgs e)
        {
            byte[] mBuffer = Encoding.ASCII.GetBytes("Led_8_ON");
            serialPort1.Write(mBuffer, 0, mBuffer.Length);
        }
 
        private void button_Led_OFF_8_Click(object sender, EventArgs e)
        {
            byte[] mBuffer = Encoding.ASCII.GetBytes("Led_8_OFF");
            serialPort1.Write(mBuffer, 0, mBuffer.Length);
        }
 
        private void button_Led_ON_13_Click(object sender, EventArgs e)
        {
            // Enviar tramas de bytes.
            byte[] miBuffer = new byte[9]; // Led_13_ON son 9 byte máximo.
            miBuffer[0] = 0x4C; // ASCII letra "L".
            miBuffer[1] = 0x65; // ASCII letra "e".
            miBuffer[2] = 0x64; // ASCII letra "d".
            miBuffer[3] = 0x5F; // ASCII letra "_".
            miBuffer[4] = 0x31; // ASCII letra "1".
            miBuffer[5] = 0x33; // ASCII letra "3".
            miBuffer[6] = 0x5F; // ASCII letra "_".
            miBuffer[7] = 0x4F; // ASCII letra "O".
            miBuffer[8] = 0x4E; // ASCII letra "N".
            serialPort1.Write(miBuffer, 0, miBuffer.Length); // Envia las tramas de bytes.
        }
 
        private void button_Led_OFF_13_Click(object sender, EventArgs e)
        {
            // Enviar tramas de bytes.
            byte[] miBuffer = new byte[10]; // Led_13_ON son 10 byte máximo.
            miBuffer[0] = 0x4C; // ASCII letra "L".
            miBuffer[1] = 0x65; // ASCII letra "e".
            miBuffer[2] = 0x64; // ASCII letra "d".
            miBuffer[3] = 0x5F; // ASCII letra "_".
            miBuffer[4] = 0x31; // ASCII letra "1".
            miBuffer[5] = 0x33; // ASCII letra "3".
            miBuffer[6] = 0x5F; // ASCII letra "_".
            miBuffer[7] = 0x4F; // ASCII letra "O".
            miBuffer[8] = 0x46; // ASCII letra "F".
            miBuffer[9] = 0x46; // ASCII letra "F".
            serialPort1.Write(miBuffer, 0, miBuffer.Length); // Envia las tramas de bytes.
        }
    }
}

Lo que he hecho hasta ahora en Visual C++ 2013.
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#pragma once
 
namespace Project1 {
 
	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
 
	using namespace System::IO::Ports; // No olvidar.
	using namespace System::Text;
 
	/// <summary>
	/// Resumen de MyForm
	/// </summary>
	public ref class MyForm : public System::Windows::Forms::Form
	{
		// Utilizaremos un string como buffer de recepción.
		String^ Recibidos;
 
	public:
		MyForm(void)
		{
			InitializeComponent();
			//
			//TODO: agregar código de constructor aquí
			//
			if (!serialPort1->IsOpen)
			{
				try
				{
					serialPort1->Open();
				}
				catch (Exception^ex)
				{
					MessageBox::Show(ex->ToString());
				}
				// Ejecutar la función Recepcion por disparo del Evento 'DataReived'.
				serialPort1->DataReceived += gcnew SerialDataReceivedEventHandler(Recepcion);
			}
		}
 
		// Al recibir datos.
	private: void Recepcion(Object^ sender, SerialDataReceivedEventArgs^ e)
		{
			// Acumula los caracteres recibidos a nuestro 'buffer' (sting).
			Recibidos += serialPort1->ReadExisting();
 
			// Invocar o llamar al proceso de tramas.
			Invoke(gcnew EventHandler(Actualizar));
		}
 
		// Procesar los datos recibidos en el buffer y estraer tramas completas.
	private: void Actualizar(Object^ sender, EventArgs^ e)
		{
			// Asignar el valor de la trama al richTextBox.
			richTextBox_Mensajes->Text = Recibidos;
 
			// Selecciona la posición final para leer los mensajes entrantes.
			richTextBox_Mensajes->SelectionStart = richTextBox_Mensajes->Text->Length;
 
			// Mantiene el scroll en la entrada de cada mensaje.
			richTextBox_Mensajes->ScrollToCaret();
		}
 
	protected:
		/// <summary>
		/// Limpiar los recursos que se estén utilizando.
		/// </summary>
		~MyForm()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  button_Led_8_ON;
	protected:
	private: System::Windows::Forms::Button^  button_Led_8_OFF;
	private: System::IO::Ports::SerialPort^  serialPort1;
	private: System::Windows::Forms::RichTextBox^  richTextBox_Mensajes;
	private: System::ComponentModel::IContainer^  components;
 
	protected:
 
	private:
		/// <summary>
		/// Variable del diseñador requerida.
		/// </summary>
 
 
#pragma region Windows Form Designer generated code
		/// <summary>
		/// Método necesario para admitir el Diseñador. No se puede modificar
		/// el contenido del método con el editor de código.
		/// </summary>
		void InitializeComponent(void)
		{
			this->components = (gcnew System::ComponentModel::Container());
			this->button_Led_8_ON = (gcnew System::Windows::Forms::Button());
			this->button_Led_8_OFF = (gcnew System::Windows::Forms::Button());
			this->serialPort1 = (gcnew System::IO::Ports::SerialPort(this->components));
			this->richTextBox_Mensajes = (gcnew System::Windows::Forms::RichTextBox());
			this->SuspendLayout();
			// 
			// button_Led_8_ON
			// 
			this->button_Led_8_ON->Location = System::Drawing::Point(33, 39);
			this->button_Led_8_ON->Name = L"button_Led_8_ON";
			this->button_Led_8_ON->Size = System::Drawing::Size(75, 23);
			this->button_Led_8_ON->TabIndex = 0;
			this->button_Led_8_ON->Text = L"ON";
			this->button_Led_8_ON->UseVisualStyleBackColor = true;
			this->button_Led_8_ON->Click += gcnew System::EventHandler(this, &MyForm::button_Led_8_ON_Click);
			// 
			// button_Led_8_OFF
			// 
			this->button_Led_8_OFF->Location = System::Drawing::Point(33, 81);
			this->button_Led_8_OFF->Name = L"button_Led_8_OFF";
			this->button_Led_8_OFF->Size = System::Drawing::Size(75, 23);
			this->button_Led_8_OFF->TabIndex = 1;
			this->button_Led_8_OFF->Text = L"OFF";
			this->button_Led_8_OFF->UseVisualStyleBackColor = true;
			this->button_Led_8_OFF->Click += gcnew System::EventHandler(this, &MyForm::button_Led_8_OFF_Click);
			// 
			// serialPort1
			// 
			this->serialPort1->BaudRate = 115200;
			this->serialPort1->PortName = L"COM4";
			// 
			// richTextBox_Mensajes
			// 
			this->richTextBox_Mensajes->Dock = System::Windows::Forms::DockStyle::Bottom;
			this->richTextBox_Mensajes->Location = System::Drawing::Point(0, 137);
			this->richTextBox_Mensajes->Name = L"richTextBox_Mensajes";
			this->richTextBox_Mensajes->Size = System::Drawing::Size(284, 125);
			this->richTextBox_Mensajes->TabIndex = 2;
			this->richTextBox_Mensajes->Text = L"";
			// 
			// MyForm
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(284, 262);
			this->Controls->Add(this->richTextBox_Mensajes);
			this->Controls->Add(this->button_Led_8_OFF);
			this->Controls->Add(this->button_Led_8_ON);
			this->Name = L"MyForm";
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
			this->Text = L"MyForm";
			this->ResumeLayout(false);
 
		}
#pragma endregion
	private: System::Void button_Led_8_ON_Click(System::Object^  sender, System::EventArgs^  e) {
		cli::array<unsigned char> ^miBuffer = gcnew cli::array<unsigned char>(9);
		miBuffer[0] = 0x4C; // ASCII letra "L".
		miBuffer[1] = 0x65; // ASCII letra "e".
		miBuffer[2] = 0x64; // ASCII letra "d".
		miBuffer[3] = 0x5F; // ASCII letra "_".
		miBuffer[4] = 0x31; // ASCII letra "1".
		miBuffer[5] = 0x33; // ASCII letra "3".
		miBuffer[6] = 0x5F; // ASCII letra "_".
		miBuffer[7] = 0x4F; // ASCII letra "O".
		miBuffer[8] = 0x4E; // ASCII letra "N".
		serialPort1->Write(miBuffer, 0, miBuffer->Length);
	}
	private: System::Void button_Led_8_OFF_Click(System::Object^  sender, System::EventArgs^  e) {
		array<Byte> ^miBuffer = Encoding::ASCII->GetBytes("Led_13_OFF");
		serialPort1->Write(miBuffer, 0, miBuffer->Length);
	}
};
}

Los errores que me muestran son dos.
1 IntelliSense: inicializador de delegado no válido: la función no coincide con el tipo delegado c:\Users\Meta\Documents\Visual Studio 2013\Projects\Project1\Project1\MyForm.h 41 71 Project1


Y otro más.
2 IntelliSense: inicializador de delegado no válido: la función no coincide con el tipo delegado c:\Users\Meta\Documents\Visual Studio 2013\Projects\Project1\Project1\MyForm.h 52 30 Project1
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 4
Ha disminuido su posición en 7 puestos en Visual C++ .NET (en relación al último mes)
Gráfica de Visual C++ .NET

Traducir código C# 2013 a C++ 2013

Publicado por Meta (7 intervenciones) el 26/02/2015 11:38:47
Hola:

Ya funciona, les dejo el código aquí por si alguien le hace falta o les pueda ayudar.

http://electronica-pic.blogspot.com.es

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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#pragma once
 
namespace InterDuinoCPP {
 
	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
 
	using namespace System::IO::Ports; // No olvidar.
	using namespace System::Text;
 
	/// <summary>
	/// Resumen de Form_Principal
	/// </summary>
	public ref class Form_Principal : public System::Windows::Forms::Form
	{
	public:
		Form_Principal(void)
		{
			InitializeComponent();
			//
			//TODO: agregar código de constructor aquí
			//
 
			// Abrir puerto miestras se ejecuta la aplicación.
			if (!serialPort1->IsOpen)
			{
				try
				{
					serialPort1->Open();
				}
				catch (Exception^ex)
				{
					MessageBox::Show(ex->ToString());
				}
			}
		}
 
	protected:
		/// <summary>
		/// Limpiar los recursos que se estén utilizando.
		/// </summary>
		~Form_Principal()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  button_Led_8_ON;
	private: System::Windows::Forms::Button^  button_Led_8_OFF;
	protected:
 
	protected:
 
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Button^  button_Led_13_ON;
	private: System::Windows::Forms::Button^  button_Led_13_OFF;
 
 
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::RichTextBox^  richTextBox_Mensajes;
 
	private: System::Windows::Forms::Label^  label3;
	private: System::IO::Ports::SerialPort^  serialPort1;
	private: System::ComponentModel::IContainer^  components;
 
	private:
		/// <summary>
		/// Variable del diseñador requerida.
		/// </summary>
 
 
#pragma region Windows Form Designer generated code
		/// <summary>
		/// Método necesario para admitir el Diseñador. No se puede modificar
		/// el contenido del método con el editor de código.
		/// </summary>
		void InitializeComponent(void)
		{
			this->components = (gcnew System::ComponentModel::Container());
			this->button_Led_8_ON = (gcnew System::Windows::Forms::Button());
			this->button_Led_8_OFF = (gcnew System::Windows::Forms::Button());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->button_Led_13_ON = (gcnew System::Windows::Forms::Button());
			this->button_Led_13_OFF = (gcnew System::Windows::Forms::Button());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->richTextBox_Mensajes = (gcnew System::Windows::Forms::RichTextBox());
			this->label3 = (gcnew System::Windows::Forms::Label());
			this->serialPort1 = (gcnew System::IO::Ports::SerialPort(this->components));
			this->SuspendLayout();
			// 
			// button_Led_8_ON
			// 
			this->button_Led_8_ON->Location = System::Drawing::Point(43, 37);
			this->button_Led_8_ON->Name = L"button_Led_8_ON";
			this->button_Led_8_ON->Size = System::Drawing::Size(75, 23);
			this->button_Led_8_ON->TabIndex = 0;
			this->button_Led_8_ON->Text = L"ON";
			this->button_Led_8_ON->UseVisualStyleBackColor = true;
			this->button_Led_8_ON->Click += gcnew System::EventHandler(this, &Form_Principal::button_Led_8_ON_Click);
			// 
			// button_Led_8_OFF
			// 
			this->button_Led_8_OFF->Location = System::Drawing::Point(43, 77);
			this->button_Led_8_OFF->Name = L"button_Led_8_OFF";
			this->button_Led_8_OFF->Size = System::Drawing::Size(75, 23);
			this->button_Led_8_OFF->TabIndex = 1;
			this->button_Led_8_OFF->Text = L"OFF";
			this->button_Led_8_OFF->UseVisualStyleBackColor = true;
			this->button_Led_8_OFF->Click += gcnew System::EventHandler(this, &Form_Principal::button_Led_8_OFF_Click);
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(62, 21);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(34, 13);
			this->label1->TabIndex = 2;
			this->label1->Text = L"Led 8";
			// 
			// button_Led_13_ON
			// 
			this->button_Led_13_ON->Location = System::Drawing::Point(166, 37);
			this->button_Led_13_ON->Name = L"button_Led_13_ON";
			this->button_Led_13_ON->Size = System::Drawing::Size(75, 23);
			this->button_Led_13_ON->TabIndex = 3;
			this->button_Led_13_ON->Text = L"ON";
			this->button_Led_13_ON->UseVisualStyleBackColor = true;
			this->button_Led_13_ON->Click += gcnew System::EventHandler(this, &Form_Principal::button_Led_13_ON_Click);
			// 
			// button_Led_13_OFF
			// 
			this->button_Led_13_OFF->Location = System::Drawing::Point(166, 77);
			this->button_Led_13_OFF->Name = L"button_Led_13_OFF";
			this->button_Led_13_OFF->Size = System::Drawing::Size(75, 23);
			this->button_Led_13_OFF->TabIndex = 4;
			this->button_Led_13_OFF->Text = L"OFF";
			this->button_Led_13_OFF->UseVisualStyleBackColor = true;
			this->button_Led_13_OFF->Click += gcnew System::EventHandler(this, &Form_Principal::button_Led_13_OFF_Click);
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(186, 21);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(40, 13);
			this->label2->TabIndex = 5;
			this->label2->Text = L"Led 13";
			// 
			// richTextBox_Mensajes
			// 
			this->richTextBox_Mensajes->Dock = System::Windows::Forms::DockStyle::Bottom;
			this->richTextBox_Mensajes->Location = System::Drawing::Point(0, 129);
			this->richTextBox_Mensajes->Name = L"richTextBox_Mensajes";
			this->richTextBox_Mensajes->Size = System::Drawing::Size(284, 133);
			this->richTextBox_Mensajes->TabIndex = 6;
			this->richTextBox_Mensajes->Text = L"";
			// 
			// label3
			// 
			this->label3->AutoSize = true;
			this->label3->Location = System::Drawing::Point(12, 113);
			this->label3->Name = L"label3";
			this->label3->Size = System::Drawing::Size(121, 13);
			this->label3->TabIndex = 7;
			this->label3->Text = L"Mensaje desde Arduino:";
			// 
			// serialPort1
			// 
			this->serialPort1->BaudRate = 115200;
			this->serialPort1->PortName = L"COM4";
			this->serialPort1->DataReceived += gcnew System::IO::Ports::SerialDataReceivedEventHandler(this, &Form_Principal::serialPort1_DataReceived);
			// 
			// Form_Principal
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(284, 262);
			this->Controls->Add(this->label3);
			this->Controls->Add(this->richTextBox_Mensajes);
			this->Controls->Add(this->label2);
			this->Controls->Add(this->button_Led_13_OFF);
			this->Controls->Add(this->button_Led_13_ON);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->button_Led_8_OFF);
			this->Controls->Add(this->button_Led_8_ON);
			this->Name = L"Form_Principal";
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
			this->Text = L"Mini Interfaz C++";
			this->ResumeLayout(false);
			this->PerformLayout();
 
		}
#pragma endregion
	private: System::Void button_Led_8_ON_Click(System::Object^  sender, System::EventArgs^  e) {
		array<Byte> ^miBuffer = Encoding::ASCII->GetBytes("Led_8_ON");
		serialPort1->Write(miBuffer, 0, miBuffer->Length);
	}
private: System::Void button_Led_8_OFF_Click(System::Object^  sender, System::EventArgs^  e) {
	array<Byte> ^miBuffer = Encoding::ASCII->GetBytes("Led_8_OFF");
	serialPort1->Write(miBuffer, 0, miBuffer->Length);
}
 
private: System::Void button_Led_13_ON_Click(System::Object^  sender, System::EventArgs^  e) {
	cli::array<unsigned char> ^miBuffer = gcnew cli::array<unsigned char>(9);
	miBuffer[0] = 0x4C; // ASCII letra "L".
	miBuffer[1] = 0x65; // ASCII letra "e".
	miBuffer[2] = 0x64; // ASCII letra "d".
	miBuffer[3] = 0x5F; // ASCII letra "_".
	miBuffer[4] = 0x31; // ASCII letra "1".
	miBuffer[5] = 0x33; // ASCII letra "3".
	miBuffer[6] = 0x5F; // ASCII letra "_".
	miBuffer[7] = 0x4F; // ASCII letra "O".
	miBuffer[8] = 0x4E; // ASCII letra "N".
	serialPort1->Write(miBuffer, 0, miBuffer->Length);
}
 
private: System::Void button_Led_13_OFF_Click(System::Object^  sender, System::EventArgs^  e) {
	cli::array<unsigned char> ^miBuffer = gcnew cli::array<unsigned char>(10);
	miBuffer[0] = 0x4C; // ASCII letra "L".
	miBuffer[1] = 0x65; // ASCII letra "e".
	miBuffer[2] = 0x64; // ASCII letra "d".
	miBuffer[3] = 0x5F; // ASCII letra "_".
	miBuffer[4] = 0x31; // ASCII letra "1".
	miBuffer[5] = 0x33; // ASCII letra "3".
	miBuffer[6] = 0x5F; // ASCII letra "_".
	miBuffer[7] = 0x4F; // ASCII letra "O".
	miBuffer[8] = 0x46; // ASCII letra "F".
	miBuffer[9] = 0x46; // ASCII letra "F".
	serialPort1->Write(miBuffer, 0, miBuffer->Length);
}
 
		 // Declaramos un delegado.
		 delegate void Delegado(String ^ Recibidos);
 
private: Void serialPort1_DataReceived(Object^  sender, SerialDataReceivedEventArgs^  e) {
	// Utilizremos un string como buffer de recepción.
	String ^ Recibidos;
 
	if (serialPort1->BytesToRead > 0){ // Si hay carácter que leer...
 
		Recibidos = serialPort1->ReadExisting(); // Acumula los carácteres recibido.
 
		// Invocamos y cargamos los bytes en rictTextBox_Mensajes.
		Delegado ^ Actualizar = gcnew Delegado(this, &Form_Principal::ByteRecibidos);
 
		this->Invoke(Actualizar, Recibidos);
	}
}
 
		 void ByteRecibidos(String ^ Data){
			 // Los carácteres almacenado en 'Data' se depositan en richTextBox_Mensaje.
			 richTextBox_Mensajes->Text += Data;
 
			 // Selecciona la posición final para leer los mensajes entrantes.
			 richTextBox_Mensajes->SelectionStart = richTextBox_Mensajes->Text->Length;
 
			 // Mantiene el scroll en la entrada de cada mensaje.
			 richTextBox_Mensajes->ScrollToCaret();
		 }
 
};
}


Saludos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar