Printing Error: Failed to write to device: Unable to establish connection to ZD421-203dpi ZPL (D8J231506086)

// Expert user has replied.
S Stuart Lythgoe 2 months 1 week ago
210 8 0

Hi

We are running an Imac with MacO Ventura 13.6.3 using Chrome and Browser Print to print to ZEBRA ZD421.

We are constantly having problems with intermittent connections to the printer and getting this message:

Printing Error: Failed to write to device: Unable to establish connection to ZD421-203dpi ZPL (D8J231506086)

Inorder to get connection I usually open up Package contents and run the sample Index.html file and send a test an sometime this engages the printer othertimes i restart the printer etc.

Can someone advise / please help?

Best regards

Stuart

Please register or login to post a reply

8 Replies

S Steven Si

Is the ZD421 connected via USB or network? Make sure the Browser Print client app on the iMac is the latest and the  Browser Print JavaScript library is the latest.

Could you do a quick test with our Browser Print demo site to see if you get the same connection errors? It's https://cagdemo.com/. This demo site uses the latest version of the Browser Print JavaScript library.

S Stuart Lythgoe

Hi the ZD421 is connected via USB, the Browser Print client app has been deleted fully and installed multiple times this year, we are using  Browser Print v1.3.2.489, and we have the latest JavaScript library.

I tried the test on the demo site and was asked to add caddemo.com as an accepted site which I did so it shows up as an accepted host, but I still got similar error messages when trying to print:

An error occurred while printing. Please try again.Failed to write to device: Unable to establish connection to ZD421-203dpi ZPL (D8J231506086) 'Button showing" Try Again

S Steven Si

It looks like an issue with the USB connection on macOS. I am seeing the same USB connection failure on the MacBook Sonoma 14.1 with the Browser Print v1.3.2.489. It worked for the first print, but failed for the subsequent prints on the USB. The issue has been forwarded to the engineering team to investigate further. Meanwhile, would you be able to connect the printer to the network and do the Browser Print over the network connection? I have verified that the Browser Print has no issues on macOS with network connected printers.

S Steven Si

Hi Stuart,

Our engineering team investigated the issue and concluded that the issue is not related to the Browser Print. The reason that we were able to reproduce the issue from the cagdemo.com site is because the code on this site is a bit outdated. If you use the demo that comes with the Browser Printer JavaScript Library, you won't see the issue with the USB connection at all. Here is a screenshot of the Browser Print JavaScript Library package and where the demo resides. Try the "Send ZPL Label" button on the demo to print over the USB connected printer, which works for me without issues. You can then follow the example code to call the proper API in your app.

Location of the demo

S Stuart Lythgoe

Hi,

I did say in my original post that I open up Package contents and run the sample Index.html file and  us the "Send ZPL Label" and I do get a Test label. But Im still getting the problem, sometimes it helps other times it doesn't

One thing I am noticing is there always seems to be two Selected devices showing up in the Sample page see (attached)

So currently I can send a test print, but still can't print from my website or https://cagdemo.com/


Regards

 

 

S Stuart Lythgoe

Hi,

I dont understand what you mean by this:

You can then follow the example code to call the proper API in your app.

Can you please explain in more detail?

Regards

S Steven Si

When testing out the Browser Print sample from the package, please run the sample from a webserver rather than opening the sample/index.html in a browser from the file system directly. As indicated in the screenshot in my response post, I have a local webserver and index.html is opened through the URL of http://localhost:8080/zebra-browser-print-js-v31250/sample/index.html. Testing the Browser Print from a file system may run into different unexpected issues.

Inside the index.html file, we can find the "Send ZPL Label" button calls the writeToSelectedPrinter() function, which calls the selected_device.send(). Below is the content of the index.html that comes with the Browser Print release package.

<html>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<head>
<script type="text/javascript" src="../BrowserPrint-3.1.250.min.js"></script>
<script type="text/javascript">
var selected_device;
var devices = [];
function setup()
{
	//Get the default device from the application as a first step. Discovery takes longer to complete.
	BrowserPrint.getDefaultDevice("printer", function(device)
			{
		
				//Add device to list of devices and to html select element
				selected_device = device;
				devices.push(device);
				var html_select = document.getElementById("selected_device");
				var option = document.createElement("option");
				option.text = device.name;
				html_select.add(option);
				
				//Discover any other devices available to the application
				BrowserPrint.getLocalDevices(function(device_list){
					for(var i = 0; i < device_list.length; i++)
					{
						//Add device to list of devices and to html select element
						var device = device_list[i];
						if(!selected_device || device.uid != selected_device.uid)
						{
							devices.push(device);
							var option = document.createElement("option");
							option.text = device.name;
							option.value = device.uid;
							html_select.add(option);
						}
					}
					
				}, function(){alert("Error getting local devices")},"printer");
				
			}, function(error){
				alert(error);
			})
}
function getConfig(){
	BrowserPrint.getApplicationConfiguration(function(config){
		alert(JSON.stringify(config))
	}, function(error){
		alert(JSON.stringify(new BrowserPrint.ApplicationConfiguration()));
	})
}
function writeToSelectedPrinter(dataToWrite)
{
	selected_device.send(dataToWrite, undefined, errorCallback);
}
var readCallback = function(readData) {
	if(readData === undefined || readData === null || readData === "")
	{
		alert("No Response from Device");
	}
	else
	{
		alert(readData);
	}
	
}
var errorCallback = function(errorMessage){
	alert("Error: " + errorMessage);	
}
function readFromSelectedPrinter()
{

	selected_device.read(readCallback, errorCallback);
	
}
function getDeviceCallback(deviceList)
{
	alert("Devices: \n" + JSON.stringify(deviceList, null, 4))
}

function sendImage(imageUrl)
{
	url = window.location.href.substring(0, window.location.href.lastIndexOf("/"));
	url = url + "/" + imageUrl;
	selected_device.convertAndSendFile(url, undefined, errorCallback)
}
function sendFile(fileUrl){
    url = window.location.href.substring(0, window.location.href.lastIndexOf("/"));
    url = url + "/" + fileUrl;
    selected_device.sendFile(url, undefined, errorCallback)
}
function onDeviceSelected(selected)
{
	for(var i = 0; i < devices.length; ++i){
		if(selected.value == devices[i].uid)
		{
			selected_device = devices[i];
			return;
		}
	}
}
window.onload = setup;
</script>
</head>
<body>

<span style="padding-right:50px; font-size:200%">Zebra Browser Print Test Page</span><br/>
<span style="font-size:75%">This page must be loaded from a web server to function properly.</span><br><br>
Selected Device: <select id="selected_device" onchange=onDeviceSelected(this);></select> <!--  <input type="button" value="Change" onclick="changeDevice();">--> <br/><br/> 
<input type="button" value="Get Application Configuration" onclick="getConfig()"><br/><br/>
<input type="button" value="Send Config Label" onclick="writeToSelectedPrinter('~wc')"><br/><br/>
<input type="button" value="Send ZPL Label" onclick="writeToSelectedPrinter('^XA^FO200,200^A0N36,36^FDTest Label^FS^XZ')"><br/><br/>
<input type="button" value="Get Status" onclick="writeToSelectedPrinter('~hs'); readFromSelectedPrinter()"><br/><br/>
<input type="button" value="Get Local Devices" onclick="BrowserPrint.getLocalDevices(getDeviceCallback, errorCallback);"><br/><br/>
<input type="text" name="write_text" id="write_text"><input type="button" value="Write" onclick="writeToSelectedPrinter(document.getElementById('write_text').value)"><br/><br/>
<input type="button" value="Read" onclick="readFromSelectedPrinter()"><br/><br/>
<input type="button" value="Send BMP" onclick="sendImage('Zebra_logobox.bmp');"><br/><br/>
<input type="button" value="Send JPG" onclick="sendImage('ZebraGray.jpg');"><br/><br/>
<input type="button" value="Send File" onclick="sendFile('wc.zpl');"><br/><br/>
</body>
</html>
S Stuart Lythgoe

Hi,
We've run the sample from our webserver and still getting the same problems.
We can print a Test page from the Browser Print Sample/

We are still getting two selected devices showing up in drop down menu, and we still can print from our website or https://cagdemo.com/. 

Same 'Cant establish a connection' message on both!

Regards
 

CONTACT
Can’t find what you’re looking for?