Por ahora el código funciona así una parte pero no me carga los controles pictureBox.
#pragma once
namespace Entrada_Arduino_CPP_CLR_3 {
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; // Do not forget.
using namespace System::Text;
/// <summary>
/// Resumen de Form_Principal
/// </summary>
public ref class Form_Principal : public Form
{
public:
// Use a string as a receive buffer.
String^ Recibidos;
Form_Principal(void)
{
InitializeComponent();
if (!serialPort1->IsOpen)
{
try
{
serialPort1->Open();
}
catch (Exception^ ex)
{
MessageBox::Show(ex->ToString());
}
serialPort1->DataReceived += gcnew SerialDataReceivedEventHandler(this, &Form_Principal::Recepcion);
}
}
// When receiving data.
private: Void Recepcion(Object^ sender, SerialDataReceivedEventArgs^ e)
{
// Accumulate characters received our 'buffer' (string).
Recibidos += serialPort1->ReadExisting();
// Invoke or call the process frames.
Invoke(gcnew EventHandler(this, &Form_Principal::Actualizar));
}
// Processing the received data in the buffer and extract complete frames.
private: Void Actualizar(Object^ sender, EventArgs^ e)
{
// Assign the value of the frame to the RichTextBox.
richTextBox1->Text += Recibidos;
// Select the final position to read incoming messages.
richTextBox1->SelectionStart = richTextBox1->Text->Length;
// Keeps the scroll at the entrance of each message.
richTextBox1->ScrollToCaret();
//array<Char>^ Delimitador = {(Char)" ", (Char)"\r", (Char)"\n" };
array<wchar_t, 1>^ Delimitador = { ' ','\r','\n' };
array<String^>^ Palabras = Recibidos->Split(Delimitador);
for each (String^ Comandos in Palabras)
{
if (Comandos == "1=ON")
pictureBox1->Load("Led\Led_rojo_encendido.png");
else if (Comandos == "1=OFF")
pictureBox1->Load("Led\Led_rojo_apagado.png");
else if (Comandos == "2=ON")
pictureBox2->Load("Led\\Led_rojo_encendido.png");
else if (Comandos == "2=OFF")
pictureBox2->Load("Led\\Led_rojo_apagado.png");
else if (Comandos == "3=ON")
pictureBox3->Load("Led\\Led_rojo_encendido.png");
else if (Comandos == "3=OFF")
pictureBox3->Load("Led_rojo_apagado.png");
else if (Comandos == "4=ON")
pictureBox4->Load("Led_rojo_encendido.png");
else if (Comandos == "4=OFF")
pictureBox4->Load("Led_rojo_apagado.png");
Recibidos = "";
}
richTextBox1->Text += " " + DateTime::Now.ToString() + "\r";
}
Saludos.
http://electronica-pic.blogspot.com