1

I need to send a sequence of control codes (decimal 27, 112, 0, 25 and 250) to a USB printer "Epson TM printer" using Powershell.

I would like to put the control codes in decimal in a plain text file. e.g. keys.txt.

Content of keys.txt

27
112
0
25
250

What is the easiest way to send the control codes to the USB printer? I am thinking whether I need to create a "Generic / Text only" printer pointing to the same USB port, and then use Out-Printer "Generic / Text only" to send the control codes to it.

I tried

gc keys.txt | out-printer "Generic / Text only"

but the result was not what I wanted. Any help is much appreciated.

Thanks

Barry Chum
  • 829
  • 3
  • 14
  • 23

2 Answers2

0

You should be able to open a stream to the printer port and write your commands

Something like this you can achieve in C#. Just call or convert this in powershell as explained here - http://msdn.microsoft.com/en-us/gg981616

System.IO.StreamWriter sr = new System.IO.StreamWriter(@"\\.\LPT1");
sr.Write(0x1b); 
sr.Write('k'); 
sr.Write('1'); 
sr.Write("Hello"); // print in Sans Serif
sr.WriteLine();
sr.Flush();
sr.Close();
Community
  • 1
  • 1
Angshuman Agarwal
  • 4,796
  • 7
  • 41
  • 89
0
$s = [char]0x1B +[char]0x70 + [char]0x00 + [char]0x19 + [char]0xFA
Out-Printer -Name <yourprinter> $s
David Brabant
  • 41,623
  • 16
  • 83
  • 111
  • Thanks David. I found that if I read the codes from a file, I need to mask them with [char][byte]. However, I just found another problem. If I send the control codes to the printer using Out-Printer command, there are some extra characters (0a, 20, 30, 33, etc) sent with my own codes to the printer too. I thought there may be something configurable in the printer driver but I couldn't find any. The Generic / Text only driver was so simple.... I don't know what went wrong. – Barry Chum Jun 17 '12 at 22:57
  • I just found a passthrough printer driver that solved the issue!! The Windows Generic / Text Only driver is not very good at passing thru.... – Barry Chum Jun 18 '12 at 09:36