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