简体   繁体   中英

Sending a font file (.cpf) to zebra Qln320 printer over WLAN

I need to send a .cpf (font type) file to a QLN 320 zebra printer over WLAN using C#. Could anybody please help.

Thanks Midhun

Try this:

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;

If you have already created the .CPF file you can just send the contents of the file down to the printer and it will save the font properly.

Just open up a socket and write all the bytes out

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM