问题描述
string command =^ XA ^ FO10,10,^ AO,30,20 ^ FDFDTesting ^ FS ^ FO10,30 ^ BY3 ^ BCN,100,Y,N,N ^ FDTesting ^ FS ^ XZ;
//使用命令创建一个缓冲区
Byte [] buffer = new byte [command.Length];
buffer = System.Text.Encoding.ASCII.GetBytes(command);
//使用CreateFile外部函数连接到LPT1端口
SafeFileHandle printer = CreateFile( LPT1:,FileAccess.ReadWrite,0,IntPtr.Zero,FileMode.Open,0,IntPtr.Zero);
// Aqui verifico se aimpressoraéválida
if(printer.IsInvalid == true)
{
return;
}
///打开文件流到lpt1端口并发送命令
FileStream lpt1 = new FileStream(printer,FileAccess.ReadWrite);
lpt1.Write (buffer,0,buffer.Length);
//关闭FileStream co nnection
此代码使用但我在创建外部函数时出错..
- 错误:方法没有实现
static extern SafeFileHandle CreateFile(字符串lpFileName,FileAccess dwDesiredAccess,uint dwShareMode,IntPtr lpSecurityAttributes,FileMode dwCreationDisposition,uint dwFlagsAndAttributes,IntPtr hTemplateFile);
string command = "^XA^FO10,10,^AO,30,20^FDFDTesting^FS^FO10,30^BY3^BCN,100,Y,N,N^FDTesting^FS^XZ";
// Create a buffer with the command
Byte[] buffer = new byte[command.Length];
buffer = System.Text.Encoding.ASCII.GetBytes(command);
// Use the CreateFile external func to connect to the LPT1 port
SafeFileHandle printer = CreateFile("LPT1:", FileAccess.ReadWrite, 0, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);
// Aqui verifico se a impressora é válida
if (printer.IsInvalid == true)
{
return;
}
/// Open the filestream to the lpt1 port and send the command
FileStream lpt1 = new FileStream(printer, FileAccess.ReadWrite);
lpt1.Write(buffer, 0, buffer.Length);
// Close the FileStream connection
this code use but i have given error in create external function..
--Error: Method has no implementation
static extern SafeFileHandle CreateFile(string lpFileName, FileAccess dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, FileMode dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);
推荐答案
这篇关于条码打印asp.net c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!