我明白这可能是可能/稍微主题,但它与编程点阵打印机有关。
我正在尝试为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
但这似乎不起作用。
对于如何将此命令发送到此点阵打印机,有人会有任何建议吗?
答案 0 :(得分:0)
此命令可以提供帮助:copy /B afile.bin LPT1:
,其中afile.bin
应包含您的打印机命令字符串。在十六进制编辑器中查看( ascii display中显示<{1}} 用于任何非打印字符):
×
从命令行执行的hexa 1B2561401C22410041001C22490049
ascii × % a @ × " A × A × × " I × I
没有任何结果。
但在将文件发送到打印机之前,许多字处理器都会发送
打印机的“初始化字符串”或copy /B afile.bin LPT1:
信号。您的打印机用户指南应该给出一个忽略重置代码的过程,并消除从字处理器派生的I-Prime
信号问题。
答案 1 :(得分:0)
事实证明,这些打印机有几种模式,因此需要传递特定十六进制字符串。
根据它是9针还是24针还有不同的命令,因此,为了找出要发送的命令,需要与documentation进行大量的争论。
我最终使用类似these的命令将命令写入内存。
该程序看起来与this类似,十六进制数据被发送到打印机
[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;