C#端口连接热敏打印机发送指令
2021-05-28 04:01
标签:vat access extern 收银 get html 字体 int buffer 转 : https://www.cnblogs.com/rinack/p/4837993.html C#端口连接热敏打印机发送指令 标签:vat access extern 收银 get html 字体 int buffer 原文地址:https://www.cnblogs.com/fps2tao/p/14756026.htmlclass LptControl
{
private string LptStr = "lpt1";
public LptControl(string l_LPT_Str)
{
LptStr = l_LPT_Str;
}
[StructLayout(LayoutKind.Sequential)]
private struct OVERLAPPED
{
int Internal;
int InternalHigh;
int Offset;
int OffSetHigh;
int hEvent;
}
//调用DLL.
[DllImport("kernel32.dll")]
private static extern int CreateFile(string lpFileName, uint dwDesiredAccess, int dwShareMode, int lpSecurityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes, int hTemplateFile);
[DllImport("kernel32.dll")]
private static extern bool WriteFile(int hFile, byte[] lpBuffer, int nNumberOfBytesToWrite, ref int lpNumberOfBytesWritten, ref OVERLAPPED lpOverlapped);
[DllImport("kernel32.dll")]
private static extern bool CloseHandle(int hObject);
private int iHandle;
///
Byte[] data1 = new byte[] { 0x1D, 0x56, 0x30 };//切纸指令
Byte[] data2 = new byte[] { 0x1B, 0x70, 0x00, 0x3C, 0xFF };//弹钱箱指令(什么鬼收银机中可以弹钱箱,我也不知道)
Byte[] data3 = new byte[] { 0x1D, 0x21, 0x24, 0x24 };//字体大小36
Byte[] data4 = new byte[] { 0x1D, 0x21, 0x0C, 0x0C };//字体大小12
Byte[] data5 = new byte[] { 0x1B, 0x45, 0x01 };//字体加粗开始
Byte[] data6 = new byte[] { 0x1B, 0x45, 0x00 };//字体加粗结束
LptControl lc = new LptControl("lpt1");//端口
lc.Open();
lc.Write(data3);//打印指令byte数组
lc.Write("文字文字");//打印文字
lc.Write("\n\n\n\n");
lc.Close();
上一篇:关于emwin的多边形旋转函数