溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

C#中Lpt端口打印類怎么用

發(fā)布時(shí)間:2021-12-03 10:09:48 來源:億速云 閱讀:223 作者:小新 欄目:編程語言

這篇文章主要介紹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è)資訊頻道!

向AI問一下細(xì)節(jié)

免責(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)容。

AI