How can I access Parallel Port through a printer to print RFID barcode in C#?

545 views Asked by At

There are two ways using C# that I found on the net:

  1. Using CreateFile and WriteFile from win32 api:

    [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);
    

    It can transport barcode command and print barcode well, but it can not read the status from the parallel port.

  2. Using Inpout32.dll: There are two main functions:

    • short Inp32(short PortAddress)
    • void Out32(short PortAddress, short data)

But the parameter's type is short; how can I transfer print command String at a time?

0

There are 0 answers