有做过ZPL编程的吗?向斑马打印机发送~HM后,打印机会返回一个内存的状态的数据.但我读不到这个返回的数据。
如ZPL说明书所述:当内存状态命令~HM送到斑马打印机后,一行数据包括三个数字送回主机。这信息内容描述如下。
内存状态行1024, 0780,1025, 0780
我写的例子如下:
lptwriter 是一个并串口操作的一个类
byte[] memorystate=new byte[1024];
string readedstate;
lptwriter lw=new lptwriter();
lw.open();
lw.write("^XA~HM^XZ");
memorystate=lw.read(1204);
string readedstate=text.coding.ascii.getstring(memorystate);readedstate返回为空。
是lptwriter大概内容如下:
[DllImport("kernel32.dll")]
private static extern bool ReadFile(
int hFile, // handle to file
byte[] lpBuffer, // data buffer
int nNumberOfBytesToRead, // number of bytes to read
ref int lpNumberOfBytesRead, // number of bytes read
ref OVERLAPPED lpOverlapped // overlapped buffer
);public byte[] Read(int NumBytes)
{
byte[] BufBytes;
byte[] OutBytes;
BufBytes = new byte[NumBytes];
if (hComm!=INVALID_HANDLE_VALUE)
{
OVERLAPPED ovlCommPort = new OVERLAPPED();
int BytesRead=0;
ReadFile(hComm,BufBytes,NumBytes,ref BytesRead,ref ovlCommPort);
OutBytes = new byte[BytesRead];
Array.Copy(BufBytes,OutBytes,BytesRead);
}
else
{
throw(new ApplicationException("Comm Port Not Open"));
}
return OutBytes;
}
请高手指教。
如ZPL说明书所述:当内存状态命令~HM送到斑马打印机后,一行数据包括三个数字送回主机。这信息内容描述如下。
内存状态行1024, 0780,1025, 0780
我写的例子如下:
lptwriter 是一个并串口操作的一个类
byte[] memorystate=new byte[1024];
string readedstate;
lptwriter lw=new lptwriter();
lw.open();
lw.write("^XA~HM^XZ");
memorystate=lw.read(1204);
string readedstate=text.coding.ascii.getstring(memorystate);readedstate返回为空。
是lptwriter大概内容如下:
[DllImport("kernel32.dll")]
private static extern bool ReadFile(
int hFile, // handle to file
byte[] lpBuffer, // data buffer
int nNumberOfBytesToRead, // number of bytes to read
ref int lpNumberOfBytesRead, // number of bytes read
ref OVERLAPPED lpOverlapped // overlapped buffer
);public byte[] Read(int NumBytes)
{
byte[] BufBytes;
byte[] OutBytes;
BufBytes = new byte[NumBytes];
if (hComm!=INVALID_HANDLE_VALUE)
{
OVERLAPPED ovlCommPort = new OVERLAPPED();
int BytesRead=0;
ReadFile(hComm,BufBytes,NumBytes,ref BytesRead,ref ovlCommPort);
OutBytes = new byte[BytesRead];
Array.Copy(BufBytes,OutBytes,BytesRead);
}
else
{
throw(new ApplicationException("Comm Port Not Open"));
}
return OutBytes;
}
请高手指教。
用这个类看看
System.IO.Ports.SerialPort