This question already has an answer here:
As in DOS we can do:
ECHO MESSAGE>LPT1
How can we achieve same thing in C# .NET?
Sending information to COM1 seems to be easy using C# .NET.
What about LPT1 ports?
I want to send Escape commands to the thermal printer.
In C# 4.0 and later its possible, first you need to connect to that port using the
CreateFile
method then open a filestream to that port to finally write to it. Here is a sample class that writes two lines to the printer onLPT1
.Assuming your printer is connected on the
LPT1
port, if not you will need to adjust theCreateFile
method to match the port you are using.you can call the method anywhere in your program with the following line
I think this is the shortest and most efficient solution to your problem.
You should get some help from this article from microsoft: How to send raw data to a printer by using Visual C# .NET
You could always try this code example.
Br Anders