Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: Meta en 10 Febrero 2016, 17:27 pm



Título: Enviar tramas de bytes en C++/CLR
Publicado por: Meta en 10 Febrero 2016, 17:27 pm
Hola:

En C# para enviar un byte al puerto serie uso esto.

Código:
private void button_t_Click(object sender, EventArgs e)
{
    byte[] mBuffer = new byte[1];
    mBuffer[0] = 0x74; //ASCII letter "t".
    serialPort1.Write(mBuffer, 0, mBuffer.Length);
}

En C++/CLR su código es este.
(https://social.msdn.microsoft.com/Forums/getfile/800439)

Para enviar de forma de cadena en C# se hace así:
Código:
private void button_b_Click(object sender, EventArgs e)
{
    byte[] mBuffer = Encoding.ASCII.GetBytes("Hello World");
    serialPort1.Write(mBuffer, 0, mBuffer.Length);
}

¿Cómo se hace en C++/CLR?

Saludos.


Título: Re: Enviar tramas de bytes en C++/CLR
Publicado por: Meta en 15 Febrero 2016, 22:47 pm
Resuelto, me respondo a mi mismo.

En Visual C++ CLR se hace así:
Código
  1. array<Byte>^mBuffer = Encoding::ASCII->GetBytes("ACTUALIZAR"); // Envía comando ACTUALIZAR por el puerto.
  2. serialPort1->Write(mBuffer, 0, mBuffer->Length);
Saludos.