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://www.mcbbbk.com/newsview454711.html
上一篇: 成都购买宠物猫狗的正规平台?这性 |
下一篇: C/C++ static 用法总 |
推荐分享

- 1我的狗老公李淑敏33——如何 5096
- 2南京宠物粮食薄荷饼宠物食品包 4363
- 3家养水獭多少钱一只正常 3825
- 4豆柴犬为什么不建议养?可爱的 3668
- 5自制狗狗辅食:棉花面纱犬的美 3615
- 6狗交配为什么会锁住?从狗狗生 3601
- 7广州哪里卖宠物猫狗的选择性多 3535
- 8湖南隆飞尔动物药业有限公司宠 3477
- 9黄金蟒的价格 3396
- 10益和 MATCHWELL 狗 3352