I want to pass a small program that I have created in Console which takes the string that a USB device sends and sends it via TCP to an IP and a specific port.
Right now I pass the received chain to a string
and treat it a posteriori but ...
What function / method do I have to use to capture what I receive via USB?
It is not clear to me what would be the best way to do it ... I have the following ...
private void btnConectar_Click(object sender, EventArgs e)
{
ActualizarStatus();
try
{
envio.Connect(IPAddress.Parse(tbIP.Text), tbPuerto));
ActualizarStatus();
btnConectar.Enabled = false;
while (true)
{
Enviar(cadena);
}
catch (Exception error)
{
ActualizarStatus(error.Message);
}
public void Enviar(string cadena)
{
ActualizarStatus();
/////////////////////////////////////
byte[] mensaje = Encoding.Default.GetBytes(cadena);
try
{
int bytesSent = envio.Send(mensaje);
ActualizarStatus();
}
catch (Exception error)
{
ActualizarStatus(error.Message);
}
}
If you notice, being inside the method Enviar()
I need to stay waiting on the line where I have the ////////////////// to the USB buffer is filled, Once you have as you say the car return, I would continue with the following line, which prepares me the string cadena
to send it right after.
The problem I have is that I do not know how to do it in a way that is not a fudge.
The truth is that in console with a simple Console.ReadLine () solved everything ...
P.D: I have omitted part of the code because it is irrelevant so that it is not heavy.
Thanks