Show all posts.
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
namespace ConsoleApplication1
{
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
public class ConsoleApplication1
{
protected const int PJL_PORT = 9100;
protected static string message = "Ready";
public static int Main(string{} args)
{
if (!ParseArgs(args))
{
return -1;
}
IPEndPoint ipEndPoint;
ipEndPoint = new IPEndPoint(Dns.Resolve(args{0}).AddressList{0}, PJL_PORT);
Socket socket;
socket = new Socket(
AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp
);
socket.Connect(ipEndPoint);
byte{} sendData;
string sendString;
sendString = String.Format(
"\x1B%-12345X@PJL RDYMSG DISPLAY = \"{0}\"\r\n\x1B%-12345X\r\n",
message
);
sendData = Encoding.ASCII.GetBytes(sendString);
socket.Send(sendData, sendData.Length, 0);
socket.Close();
return 0;
}
protected static bool ParseArgs(string{} args)
{
if (args.Length != 2)
{
Console.WriteLine("set printername and message");
return false;
}
if (args{1}.Length > 16)
{
Console.WriteLine("Message must be <= 16 characters");
return false;
}
message = args{1};
return true;
}
}
}
|
Forrás: http://vortexhunter.blogspot.com/2008/06/c-hp-laserjet-fun-fun-fun.html
|