如何通过打印机访问并行端口以在C#中打印RFID条形码?

时间:2013-09-09 07:10:52

标签: c# printing printers parallel-port

我在网上找到了两种使用C#的方法:

  1. 使用win32 api中的CreateFile和WriteFile:

    [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
      );
    iHandle = CreateFile("lpt1 ", 0x40000000, 0, 0, 3, 0, 0);
    byte[] mybyte = System.Text.Encoding.Default.GetBytes(Mystring);
    bool b = WriteFile(iHandle, mybyte, mybyte.Length, ref   i, ref   x);
    

    它可以很好地传输条形码命令和打印条形码,但它无法从并行端口读取状态。

  2. 使用Inpout32.dll: 有两个主要功能:

    • short Inp32(short PortAddress)
    • void Out32(short PortAddress, short data)
  3. 但参数的类型是short;我怎样才能一次传输打印命令字符串?

0 个答案:

没有答案