private void button1_Click(object sender, EventArgs e) { LoadPOSDll PosPrint = new LoadPOSDll(); //POS_COM_DTR_DSR 0x00 流控制为DTR/DST //POS_COM_RTS_CTS 0x01 流控制为RTS/CTS //POS_COM_XON_XOFF 0x02 流控制为XON/OFF //POS_COM_NO_HANDSHAKE 0x03 无握手 //POS_OPEN_PARALLEL_PORT 0x12 打开并口通讯端口 //POS_OPEN_BYUSB_PORT 0x13 打开USB通讯端口 //POS_OPEN_PRINTNAME 0X14 打开打印机驱动程序 //POS_OPEN_NETPORT 0x15 打开网络接口 if (PosPrint.OpenNetPort("192.168.0.123"))//当参数nParam的值为POS_OPEN_NETPORT时,表示打开指定的网络接口,如“192.168.10.251”表示网络接口IP地址,打印时参考 { Gp_IntPtr = PosPrint.POS_IntPtr; } if (LoadPOSDll.POS_StartDoc()) { byte[] by_SendData = System.Text.Encoding.Default.GetBytes("test print\r\n"); LoadPOSDll.POS_WriteFile(PosPrint.POS_IntPtr, by_SendData, (uint)by_SendData.Length); LoadPOSDll.POS_WriteFile(PosPrint.POS_IntPtr, new byte[] { 0x0a }, 1); LoadPOSDll.POS_EndDoc(); } }
public static void NetworkPrinter(Printer p, string[] contents) { Console.WriteLine("网口测试"); LoadPOSDll PosPrint = new LoadPOSDll(); //POS_COM_DTR_DSR 0x00 流控制为DTR/DST //POS_COM_RTS_CTS 0x01 流控制为RTS/CTS //POS_COM_XON_XOFF 0x02 流控制为XON/OFF //POS_COM_NO_HANDSHAKE 0x03 无握手 //POS_OPEN_PARALLEL_PORT 0x12 打开并口通讯端口 //POS_OPEN_BYUSB_PORT 0x13 打开USB通讯端口 //POS_OPEN_PRINTNAME 0X14 打开打印机驱动程序 //POS_OPEN_NETPORT 0x15 打开网络接口 if (PosPrint.OpenNetPort("192.168.1.124"))//当参数nParam的值为POS_OPEN_NETPORT时,表示打开指定的网络接口,如“192.168.10.251”表示网络接口IP地址,打印时参考 { //驱动打印句柄 IntPtr Gp_IntPtr = PosPrint.POS_IntPtr; } if (LoadPOSDll.POS_StartDoc()) { string strs = ""; for (int i = 0; i < contents.Length; i++) { strs = strs + contents[i] + "\n"; } byte[] by_SendData = System.Text.Encoding.Default.GetBytes(strs); LoadPOSDll.POS_WriteFile(PosPrint.POS_IntPtr, by_SendData, (uint)by_SendData.Length); LoadPOSDll.POS_WriteFile(PosPrint.POS_IntPtr, new byte[] { 0x0a }, 1); LoadPOSDll.POS_CutPaper(1, 1); LoadPOSDll.POS_EndDoc(); } }
private void btCutMarkBack_Click(object sender, EventArgs e) { bool printpoint = false; // 切/撕纸位置 bool front = false; int resultLength = int.Parse(tbCutMarkBack.Text); if (serialPort1 == null) { serialPort1 = new SerialPort(); serialPort1.RtsEnable = true; } if (serialPort1.IsOpen) { serialPort1.Close(); } serialPort1.PortName = "COM1"; serialPort1.BaudRate = 9600; serialPort1.Parity = (Parity)Enum.Parse(typeof(Parity), "None"); serialPort1.DataBits = 8; serialPort1.StopBits = (StopBits)Enum.Parse(typeof(StopBits), "One"); serialPort1.ReadBufferSize = 100; serialPort1.WriteBufferSize = 2048; serialPort1.ReadTimeout = 100; serialPort1.WriteTimeout = 10000; LoadPOSDll PosPrint = new LoadPOSDll(); if (PosPrint.OpenComPort(ref serialPort1)) { byte[] cmddata1 = { 0X1D, 0X54 }; byte[] cmddata2 = { 0X1D, 0X28, 0x46, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00 }; if (printpoint == true) { cmddata2[5] = 0x01; } else { cmddata2[5] = 0x02; } if (front == true) { cmddata2[6] = 0x00; } else { cmddata2[6] = 0x01; } cmddata2[7] = (byte)Math.Round((resultLength / 0.176) % 256); cmddata2[8] = (byte)((resultLength / 0.176) / 256); LoadPOSDll.POS_WriteFile(PosPrint.POS_IntPtr, cmddata2, (uint)cmddata2.Length); PosPrint.ClosePrinterPort(); } }
private void btPrintGoNextCut_Click(object sender, EventArgs e) { if (serialPort1 == null) { serialPort1 = new SerialPort(); serialPort1.RtsEnable = true; } if (serialPort1.IsOpen) { serialPort1.Close(); } serialPort1.PortName = "COM1"; serialPort1.BaudRate = 9600; serialPort1.Parity = (Parity)Enum.Parse(typeof(Parity), "None"); serialPort1.DataBits = 8; serialPort1.StopBits = (StopBits)Enum.Parse(typeof(StopBits), "One"); serialPort1.ReadBufferSize = 100; serialPort1.WriteBufferSize = 2048; serialPort1.ReadTimeout = 100; serialPort1.WriteTimeout = 10000; LoadPOSDll PosPrint = new LoadPOSDll(); if (PosPrint.OpenComPort(ref serialPort1)) { LoadPOSDll.POS_Reset(); byte[] data1 = System.Text.Encoding.Default.GetBytes("开始打印"); byte[] data2 = System.Text.Encoding.Default.GetBytes("然后走纸到下一个/撕纸位置"); LoadPOSDll.POS_WriteFile(PosPrint.POS_IntPtr, data1, (uint)data1.Length); LoadPOSDll.POS_WriteFile(PosPrint.POS_IntPtr, new byte[] { 0x0a }, 1); LoadPOSDll.POS_WriteFile(PosPrint.POS_IntPtr, data2, (uint)data2.Length); LoadPOSDll.POS_WriteFile(PosPrint.POS_IntPtr, new byte[] { 0x1B, 0x64, 0x05, 0x0A }, 4); //打印并进纸 n 行(0x05行) LoadPOSDll.POS_WriteFile(PosPrint.POS_IntPtr, new byte[] { 0x1D, 0x54, 0x1D, 0x56, 0x30 }, 5); //一种切纸模式并切纸(1D 56)30 31 LoadPOSDll.POS_WriteFile(PosPrint.POS_IntPtr, new byte[] { 0x0D }, 1); //把打印起始位置设置为该行的开始 PosPrint.ClosePrinterPort(); } }