0

我知道这可能/稍微偏离主题,但它与编程点阵打印机有关。

我正在尝试在 OKI Microline 5520 上生成一个新字符,并尝试为此使用命令行。

我试图发送到打印机的命令是:

CHR$(27);%a;@;CHR$(28);CHR$(34);CHR$(65);CHR$(0);CHR$(65);CHR$(0);CHR$(28);
CHR$(34);CHR$(73);CHR$(0);CHR$(73);

应该创建一个CE符号而不是 @ 字符。

+-+-+-+-+-+-+-+-+-+-+-+
     X   X       X   X
+-+-+-+-+-+-+-+-+-+-+-+
   X           X
+-+-+-+-+-+-+-+-+-+-+-+
 X           X       
+-+-+-+-+-+-+-+-+-+-+-+
 X           X   X   X
+-+-+-+-+-+-+-+-+-+-+-+
 X           X
+-+-+-+-+-+-+-+-+-+-+-+
   X          X
+-+-+-+-+-+-+-+-+-+-+-+
     X   X       X   X
+-+-+-+-+-+-+-+-+-+-+-+
28| 65| 65| 28| 73| 73|
  |34 |0  |0  |34 |0

但是,我似乎无法以它可以理解的方式将此命令添加/发送到打印机。

我在命令提示符下尝试命令:

net use Lpt1 \\ComputerName\\datFileName

但这似乎不起作用。

有人对我如何将此命令发送到此点阵打印机有任何建议吗?

4

2 回答 2

1

事实证明,这些打印机有几种模式,因此,它需要传递一个特定的十六进制字符串。

根据是 9 针还是 24 针,还有不同的命令,因此,为了找出要发送的命令,需要与文档进行大量斗争。

我最终使用了与这些类似的命令来将命令写入内存。

该程序看起来与类似,十六进制数据被发送到打印机

 [DllImport("winspool.Drv", EntryPoint="OpenPrinterA", SetLastError=true, CharSet=CharSet.Ansi, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
    public static extern bool OpenPrinter([MarshalAs(UnmanagedType.LPStr)] string szPrinter, out IntPtr hPrinter, IntPtr pd);

    [DllImport("winspool.Drv", EntryPoint="ClosePrinter", SetLastError=true, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
    public static extern bool ClosePrinter(IntPtr hPrinter);

    [DllImport("winspool.Drv", EntryPoint="StartDocPrinterA", SetLastError=true, CharSet=CharSet.Ansi, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
    public static extern bool StartDocPrinter( IntPtr hPrinter, Int32 level,  [In, MarshalAs(UnmanagedType.LPStruct)] DOCINFOA di);

    [DllImport("winspool.Drv", EntryPoint="EndDocPrinter", SetLastError=true, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
    public static extern bool EndDocPrinter(IntPtr hPrinter);

    [DllImport("winspool.Drv", EntryPoint="StartPagePrinter", SetLastError=true, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
    public static extern bool StartPagePrinter(IntPtr hPrinter);

    [DllImport("winspool.Drv", EntryPoint="EndPagePrinter", SetLastError=true, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
    public static extern bool EndPagePrinter(IntPtr hPrinter);

    [DllImport("winspool.Drv", EntryPoint="WritePrinter", SetLastError=true, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
    public static extern bool WritePrinter(IntPtr hPrinter, IntPtr pBytes, Int32 dwCount, out Int32 dwWritten );

    // SendBytesToPrinter()
    // When the function is given a printer name and an unmanaged array
    // of bytes, the function sends those bytes to the print queue.
    // Returns true on success, false on failure.
    public static bool SendBytesToPrinter( string szPrinterName, IntPtr pBytes, Int32 dwCount)
    {
        Int32    dwError = 0, dwWritten = 0;
        IntPtr    hPrinter = new IntPtr(0);
        DOCINFOA    di = new DOCINFOA();
        bool    bSuccess = false; // Assume failure unless you specifically succeed.

        di.pDocName = "My C#.NET RAW Document";
        di.pDataType = "RAW";

        // Open the printer.
        if( OpenPrinter( szPrinterName.Normalize(), out hPrinter, IntPtr.Zero ) )
        {
            // Start a document.
            if( StartDocPrinter(hPrinter, 1, di) )
            {
                // Start a page.
                if( StartPagePrinter(hPrinter) )
                {
                    // Write your bytes.
                    bSuccess = WritePrinter(hPrinter, pBytes, dwCount, out dwWritten);
                    EndPagePrinter(hPrinter);
                }
                EndDocPrinter(hPrinter);
            }
            ClosePrinter(hPrinter);
        }
        // If you did not succeed, GetLastError may give more information
        // about why not.
        if( bSuccess == false )
        {
                dwError = Marshal.GetLastWin32Error();
        }
        return bSuccess;
于 2014-12-03T11:23:40.793 回答
0

此命令可以帮助:copy /B afile.bin LPT1:,其中afile.bin应包含您的打印机命令字符串。在十六进制编辑器中查看(×ascii 中显示任何不可打印的字符):

hexa  1B2561401C22410041001C22490049
ascii  × % a @ × " A × A × × " I × I

copy /B afile.bin LPT1:从命令行执行,不会带来任何麻烦。

但在将文件发送到打印机之前,许多文字处理器会向打印机发送“初始化字符串”或I-Prime信号。您的打印机用户指南应提供忽略重置代码并消除您的文字处理器I-Prime可能产生的信号问题的程序。

于 2014-12-01T13:22:14.670 回答