我需要使用C#通过WLAN将.cpf(字体类型)文件发送到QLN 320 zebra打印机。 请有人帮忙。
由于 Midhun
答案 0 :(得分:1)
试试这个:
string sFileName; //file name in DOS format (8.3)
byte[] baBody; //byte array of font file
string PacketHeader = "! CISDF\r\n{0}\r\n{1}\r\n{2}\r\n";
//************************
int CheckSum = 0;
foreach (byte b in baBody)
CheckSum += b;
PacketHeader = String.Format(PacketHeader, sFileName, Convert.ToString(baBody.Length, 16).PadLeft(8, '0').ToUpper(), Convert.ToString(65536 - (CheckSum % 65536), 16).PadLeft(4, '0').ToUpper());
List<byte> list = new List<byte>();
list.AddRange(Encoding.Default.GetBytes(PacketHeader.ToCharArray()));
list.AddRange(baBody);
list.AddRange(new byte[] { 0x1B, 0x68, 0x1B, 0x68, 0x1B, 0x68, 0x1B, 0x70, 0x00 });
int PacketSize = list.Count;
byte[] tmp;
int sourceIndex = 0;
while (PacketSize / 512 >= 1)
{
tmp = list.GetRange(sourceIndex, 512).ToArray();
int BytesSent = bt.WriteBytesToSerialPort(tmp);
tmp = null;
sourceIndex += BytesSent;
PacketSize -= BytesSent;
Sleep(100);
}
if (PacketSize > 0)
{
tmp = list.GetRange(sourceIndex, list.Count - sourceIndex).ToArray();
PacketSize -= bt.WriteBytesToSerialPort(tmp);
tmp = null;
}
list.Clear();
list = null;
答案 1 :(得分:0)
如果您已经创建了.CPF文件,您只需将文件内容发送到打印机即可正确保存字体。
只需打开一个套接字并write
所有字节输出