Listen to port LPT1 C #

4

I have managed to capture the message that is sent from TCP / IP, with the class Listener , however I have been asked to listen especially to the LPT1 port, since the printers of the company are connected via Ethernet, and send them to the LPT1 port of the printer. I'm looking for information and I can not find anything, the only thing I can think of is installing a printer emulator, but I can not find one.

Printers are Intermec .

The reason for this is an application (I do not have the source code) it sends an image file and with this, a Label is printed (Quantity, Part Number, etc.), I want to receive that information to be able to use it in an app that I'm developing.

This is the code to receive the TCP message:

   class TCPIP
{

    TcpClient Client;
    TcpListener listener = new TcpListener(9100);

    public void IniciarEspiar()
    {
        listener.Start();
    }


    public void Mandar()
    {

        Client = new TcpClient("127.0.0.1", 9100);
        StreamWriter writer = new StreamWriter(Client.GetStream());
        writer.Write("Prueba para TCP/IP");
        writer.Flush();
    }

    public string Espiar()
    {

        try
        {
            string Data="";
            if ((listener.Pending() == true))
            {
                Client = listener.AcceptTcpClient();
                StreamReader Reader = new StreamReader(Client.GetStream());
                while ((Reader.Peek() > -1))
                {
                    Data += Convert.ToChar(Reader.Read()).ToString();
                }

                if (!string.IsNullOrEmpty(Data))
                {
                    Attach.Escribir(Data);
                    return Data;

                }
            }
        }
        catch (Exception ex)
        { return ex.ToString(); }

        return "";

    }
}
    
asked by CarlosR93 11.07.2017 в 18:37
source

1 answer

2

In principle there is nothing "built-in" in .Net to read directly from the parallel port. I remember doing it years ago to handle LCD panels, and I needed the use of a library called inpout32.dll that generates a kind of virtual driver that allows you to access the ports at a low level.

In that url you have a link to download the driver for both 32 and 64bits, and in the download you have sample codes, I hope they serve you.

    
answered by 12.07.2017 в 09:46