首页 > 分享 > POS打印机系列之 => 并口

POS打印机系列之 => 并口

并口是什么

并行接口:一次传输多个bit。常见25针接口。

并口通信

/// <summary> /// 并口通信 /// </summary> public interface IParallelContact : IPortContact { ActionResult Open(string port); } public class ParallelContact : IParallelContact { public bool Opened { get; set; } private string _port = string.Empty; public const short INVALID_HANDLE_VALUE = -1; public const uint GENERIC_READ = 0x80000000; public const uint GENERIC_WRITE = 0x40000000; public const int OPEN_EXISTING = 3; private int m_lpt = INVALID_HANDLE_VALUE; [StructLayout(LayoutKind.Sequential)] private struct OVERLAPPED { int Internal; int InternalHigh; int Offset; int OffSetHigh; int hEvent; } [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); //C#LPT端口打印类的操作 /// <summary> /// Closes this instance.关闭端口句柄 /// </summary> public void Close() { if (m_lpt != INVALID_HANDLE_VALUE) { CloseHandle(m_lpt); m_lpt = INVALID_HANDLE_VALUE; Opened = false; } } /// <summary> /// Writes the specified data.写入文本数据给打印机输出 /// </summary> /// <param name="data">The data.</param> /// <returns></returns> public int Write(string data) { if (Opened) { byte[] byteData = System.Text.Encoding.Default.GetBytes(data); return this.Write(byteData); } return 0; } /// <summary> /// Writes the specified data.写入控制指令或文本给打印机输出 /// </summary> /// <param name="data">The data.</param> /// <returns></returns> public int Write(byte[] data) { int BytesWritten = 0; if (data.Length == 0) return BytesWritten; if (Opened) { OVERLAPPED overlap = new OVERLAPPED(); Thread.Sleep(40); if (WriteFile(m_lpt, data, data.Length, ref BytesWritten, ref overlap)) { Thread.Sleep(40); } } return BytesWritten; } /// <summary> /// Opens the specified port.打开指定的并口 /// </summary> /// <param name="port">The port.</param> /// <returns></returns> public ActionResult Open(string port) { _port = port; m_lpt = CreateFile(port, GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); //GENERIC_READ | GENERIC_WRITE if (m_lpt == INVALID_HANDLE_VALUE) return new ActionResult(false, "打开端口[" + port + "]失败!"); Opened = true; return new ActionResult(true); } }

View Code

并口打印
并口打印仿照串口打印的实现方式,只需传入命令

本人原创,欢迎转载,声明原载

相关知识

pos触摸机敏健
PHMS宠物医院管理系统
居家一月孩子作业全靠家庭打印机救急 美团闪购打印机销量环比涨超3倍
动物尿液分析仪 U
澳大利亚罪犯利用3D打印机制造冲锋枪等武器
宠物迷之操作系列1?!?!
UV打印机皮带传动时Y轴只能前进不能后退是什么原因?
阴阳师鸟之羽系列任务说明 鸟之羽故事线
汉思宠物医院管理系统
美萍宠物店管理系统(宠物店业务管理软件,宠物店库存管理系统,宠物店收银系统),美萍软件官方网站

网址: POS打印机系列之 => 并口 https://m.mcbbbk.com/newsview454711.html

所属分类:萌宠日常
上一篇: 成都购买宠物猫狗的正规平台?这性
下一篇: C/C++ static 用法总