您好,登錄后才能下訂單哦!
這篇文章主要介紹C#中Lpt端口打印類怎么用,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
C#LPT端口打印類的操作是什么呢?首先讓我們看看什么是LPT端口(打印機(jī)專用)?LPT端口是一種增強(qiáng)了的雙向并行傳輸接口,在USB接口出現(xiàn)以前是掃描儀,打印機(jī)最常用的接口。***傳輸速度為1.5Mbps,設(shè)備容易安裝及使用,但是速度比較慢,下面是C#LPT端口打印類的操作具體實(shí)例:
using System; using System.Runtime.InteropServices; using System.IO; namespace printBarcode { /// <summary> /// LPTControl 的摘要說明,C#LPT端口打印類的操作 /// </summary> public class LPTControl { public LPTControl() {} [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端口打印類的操作 private int iHandle; public bool Open() { iHandle=CreateFile("lpt1",0x40000000,0,0,3,0,0); if(iHandle !=-1) { return true; } else { return false; } } public bool Write(String Mystring) { if(iHandle !=-1) { int i=0; OVERLAPPED x=new OVERLAPPED(); byte[]mybyte= System.Text.Encoding.Default.GetBytes(Mystring); return WriteFile( iHandle,mybyte,mybyte.Length,ref i,ref x); } else { throw new Exception("端口未打開!"); } } public bool Close() { return CloseHandle(iHandle); } }//C#LPT端口打印類的操作 }
以上是“C#中Lpt端口打印類怎么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。