Opening the Serial Port Used by the Printer

I am sending ESC / P codes ( http://webpages.charter.net/dperr/links/esc_p83.htm ) to an Epson LX-300 printer that is connected to COM1 and the computer already has the correct driver installed because someone is need to.

So I wrote this:

using System.IO.Ports;

public class EpsonPrint {

    private char esc = (char)27;
    private char ff = (char)12;

    public static void Main (string[] args) {
        new EpsonPrint();
    }

    public EpsonPrint() {
        SerialPort port = new SerialPort("COM1", 19200, Parity.None, 8,  StopBits.One);
        port.Open();
        port.Write(esc+"@hola mundo!"+ff);
        port.Close();
    }
}

      

and it works, but only with an Epson driver pointing to a different port or whatever, because if I allow it to use COM1, the code above throws:

"The given port name does not start with COM / com or does not allow a valid serial port.

and for writing it is not a "port already open" error.

+1


a source to share


2 answers


COM1 is being held by the printer driver. This will prevent your application from opening the port. Try to switch the printer port in the printer driver properties to something other than COM1. After that, your application will be free to use COM1.



0


a source


I think you need to send it to the Driver, not the port. Check out this article:



http://support.microsoft.com/kb/138594/EN-US/

0


a source







All Articles