我在网上找到了两种使用C#的方法:
使用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);
它可以很好地传输条形码命令和打印条形码,但它无法从并行端口读取状态。
使用Inpout32.dll: 有两个主要功能:
short Inp32(short PortAddress)
void Out32(short PortAddress, short data)
但参数的类型是short
;我怎样才能一次传输打印命令字符串?