Search code examples
c#bluetoothzebra-printers

How to send Font via Bluetooth to Zebra printer


I must send a Font file to my printer Zebra RW420 via bluetooth. Im using Zebra Windows Mobile SDK, but can't find any way to send and store it on printer. I could do it manually by Label Vista but It must be done in 200+ printers.

Anyone have any suggestion or know what method from the SDK I could use?

Thanks in advance.


Solution

  • CISDF is the correct answer, it's probably the checksum value that you are computing that is incorrect. I put a port sniffer on my RW420 attached to a USB port and found this to work. I actually sent some PCX images to the printer, then used them in a label later on.

    ! CISDF
    <filename>
    <size>
    <cksum>
    <data>
    

    There is a CRLF at the end of the 1st four lines. Using 0000 as the checksum causes the printer to ignore any checksum verification (I found some really obscure references to this in some ZPL manuals, tried it and it worked). <filename> is the 8.3 name of the file as it will be stored in the file system on the printer and <size> is the size of the file, 8 characters long and formatted as a hexadecimal number. <cksum> is the two's complement of the sum of the data bytes as the checksum. <data> is, of course, the contents of the file to be stored on the printer.

    Here is the actual C# code that I used to send my sample images to the printer:

    // calculate the checksum for the file
    
    // get the sum of all the bytes in the data stream
    UInt16 sum = 0;
    for (int i = 0; i < Properties.Resources.cmlogo.Length; i++)
    {
      sum += Convert.ToUInt16(Properties.Resources.cmlogo[ i]);
    }
    
    // compute the two's complement of the checksum
    sum = (Uint16)~sum;
    sum += 1;
    
    // create a new printer
    MP2Bluetooth bt = new MP2Bluetooth();
    
    // connect to the printer
    bt.ConnectPrinter("<MAC ADDRESS>", "<PIN>");
    
    // write the header and data to the printer
    bt.Write("! CISDF\r\n");
    bt.Write("cmlogo.pcx\r\n");
    bt.Write(String.Format("{0:X8}\r\n", Properties.Resources.cmlogo.Length));
    bt.Write(String.Format("{0:X4}\r\n", sum));  // checksum, 0000 => ignore checksum
    bt.Write(Properties.Resources.cmlogo);
    
    // gracefully close our connection and disconnect
    bt.Close();
    bt.DisconnectPrinter();
    

    MP2Bluetooth is a class we use internally to abstract BT connections and communications - you have your own as well, I'm sure!