Uart0, uart1, uart2 in imp005 configure() method is not working with printer

Here is my code

inputString = "";
uart = hardware.uart0;
uart.configure(115200, 8, PARITY_NONE, 1, 0, readback); 

function readback() {
  local byte = uart.read();
  server.log(byte);
    
  // Ignore initial input / no data signal
  if (byte == -1) return;
    
  if (byte == 13) {
    // Carriage return received? Output the string and clear it for the next input
    server.log("Sent string: " + inputString);
    inputString = "";
   } else {
    // Add the input character to the buffer
    inputString = inputString + chr(byte);
 }
}

I am using imp005 Breakout Board and attaching a printer Datamax printer via USB Hub. But I am not getting any result .

My aim is to print logo via Datamax Printer using thermalprinter code. Here is the github link which I am using to print - https://github.com/electricimp/examples/tree/master/thermalprinter

Please help!

First, you’re using UART in your code, yet you say the printer is connected by USB.

If the printer connects by serial (UART), you’ll need to get the printer’s datasheet and see if there’s an API through which you can send it print jobs. I checked the Datamax website and there are lots of models – which one do you have? You’ll need the Datamax Programming Language (DPL) (manual here) to determine which commands you need to send to the printer to get it to do what you need. You can probably adapt the thermal printer driver you mention, so that it sends Datamax-specific commands rather than codes for the thermal printer.

If it’s the latter, you will need to write a USB driver for the printer. You’ll need our USB driver framework to get you started.

Here is my code for printing Image:

function printImage(data) { // data is of type blob and this data if directly converted using Hex Code of an image

_buffer.writestring("\x1B\x2A\x72\x30\x46"); // Raster Graphics Presentation _buffer.writestring("\x1B\x2A\x74\x37\x35\x52"); // Raster Graphics Resolution @ 75 dots
_buffer.writestring("\x1B\x2A\x72\x40\x54") // Raster height for 6 inch height of label
_buffer.writestring("\x1B\x2A\x72\x80\x54") // Raster width for 4 inch width of label
_buffer.writestring("\x1B\x2A\x72\x30\x41") // Start Raster Graphics Command

  /* Help needed for the logic of transferring data row by row. Below writing some hex commands for setting Y-Offset, Compression Mode and sending data */

_buffer.writestring("\x1B\x2A\x62") // Set Y Offset
_buffer.writen(width, 'b');
_buffer.writestring("\x59");

_buffer.writestring("\x1B\x2A\x62\x32\x4D"); // Tagged Imaged File Format

_buffer.writestring("\x1B\x2A\x62");
_buffer.writeblob(data or logic needed here);
_buffer.writestring("\x57");

_buffer.writestring("\x1B\x2A\x72\x43"); // End Raster Graphics
_buffer.writestring(PAGE_FEED);
}

Need help in loop for transferring data row by row in chunks. I have successfully printed Text using different hex codes and also communication is done.

My printer supports PCL5 commands and here is the link to PCL5 datasheets: PCL5 datasheets and also the PCL5 Hex Conversion datasheet: Hex Codes for PCL5

Any help would be appreciated.

I’d first generate a small image (smaller than 4x6!) and put the hex right in your code - this will check the reset of the setup is correct.

Then you’d likely need to pull the image down by HTTPS with the agent, cut it into chunks, send each one down, and write them to usb. Note that you don’t need to write them all to the same blob - every printer I’ve ever used is just fine with getting the data in many packets.

Hi Hugo,
Can you send me a sample squirrel code for image printing so that I would be able to compare between your sample code and my code.
It would be really helpful if you can send a sample code.

I’m afraid I don’t have any code for that, sorry. Transferring image data is no different from transferring any other binary data from the agent though, so maybe look at some example code which downloads big binaries via HTTPS and sends them to the device in chunks?

In every reference and printer datasheet, I am seeing that it is written to send data to printer row by row when printing image data. Can you please help me with any reference for it?

Any reference where image data is pulled and send it to printer row by row till column/height of image?

By the look of your earlier code, the printer supports TIFF image data natively (you send it a TIFF format indicator), so you may be able simply to send the TIFF image data as a blob.

If the printer doesn’t handle TIFFs natively, you may need to manually decode the TIFF data into a blob bitmap image, which you can then access row by row, and send each row to the printer. This is how our QR code printer sample works, for instance, though that’s for a different printer than yours.

This may help:

Yes, data is formatted row by row, but it’s just a stream of bytes - ie you send it like any other stream of bytes.

Can’t help you with reference code, but like I said you don’t need it. Try for yourself.

I have few questions:

  1. The image data pulled via HTTPS is what type of data? Is it a HEX Code or the raster data? Should that data be passed directly to the printer as it is or should we need to convert it into something before passing it to the printer?

  2. I successfully printed an example of raster data, but the thing is row by row data to be printed was already given. Now, how do we find the width and height or rows and column of data fetched above in point 1?

Please help in these two context.

Image data pulled from HTTPS will be a block of bytes. How those bytes encode the ‘raw’ image will depend what image type it is. PNG encodes differently from TIFF encodes differently from JPEG… etc, etc.

Unless, of course, your pulling down a raw image bitmap, but even here you need to know in advance the height, width and pixel bit depth to extract the data row by row. Compressed data formats will encode the height, width and depth differently – again, you’ll have to read up on the format of the images you expect to be downloading.

Check out the QR Code printing example, which shows how to decode PNG files to a bitmap that is ready to be sent row by row to a printer. It’s a different printer, of course, but the basic principle remains the same.