Buen día a todos... tengo el siguiente código en consola, pero quiero (necesito) pasarlo a aplicación de escritorio y que el resultado se muestre en un textbox... lo he intentado con hilos y me vuelvo loco y quedo perdido... la parte que mas se me dificulta es SABER en que parte de la aplicación de escritorio debo poner lo que aquí está en el "static void Main(string[] args)", supongo que en el Load, pero después me sale un error sibre el "object sender e" que no lo encuentra... y la verdad me vuevo a perder... agradecería mucho su ayuda...
using System.IO;
using System.IO.Ports;
using System.Text;
using System;
class Program
{
static SerialPort ComPort;
static ASCIIEncoding ASCIIEncoder = new ASCIIEncoding();
public static void OnSerialDataReceived(object sender, serialDataReceivedEventArgs args)
{
//SE ALMACENA EL EVENTO ACTUAL DEL PUERTO EN LA VARIABLE DATA
string data = ComPort.ReadExisting();
string numero = "";
//SACAMOS LOS DATOS DEL NUMERO TELEFONICO
if (data.Length >= 30)
{
numero = data.Substring(29,10);
//ESTE DATO ES EL QUE NECESITO QUE SE MUESTRE EN TEXTBOX
System.Console.Write("El numero es: " + numero);
}
}
static void Main(string[] args)
{
string port = "COM3";
int baud = 9600;
if (args.Length >= 1)
{
port = args[0];
}
if (args.Length >= 2)
{
baud = int.Parse(args[1]);
}
InitializeComPort(port, baud);
string text;
//ACTIVAR IDENTIFICADOR DE LLAMADAS...
//ESTO SE DEBE PASAR, PODRIA SER, A UN TEXTBOX MULTILINEA
String ComandoATID;
ComandoATID = "AT+VCID=1";
ComPort.Write(ComandoATID + '\r');
do
{
//CAPTURAMOS EL TEXTO ESCRITO EN LA CONSOLA
text = System.Console.ReadLine();
//ESCRIBIMOS EN LA CONSOLA EL TEXTO CAPTURADO
ComPort.Write(text + '\r');
}
while (text.ToLower() != "q");
}
private static void InitializeComPort(string port, int baud)
{
ComPort = new SerialPort(port, baud);
// ComPort.PortName = port;
// ComPort.BaudRate = baud;
ComPort.Parity = Parity.None;
ComPort.StopBits = StopBits.One;
ComPort.DataBits = 8;
ComPort.Handshake = Handshake.None;
ComPort.DataReceived += OnSerialDataReceived;
ComPort.Open();
}
}
DEBO aclarar que el código NO es de mi propiedad y que SI FUNCIONA en consola...