jldubz / jzebra

Automatically exported from code.google.com/p/jzebra
0 stars 0 forks source link

Problem sending ESCP commands with \x00 values #61

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Send Command any command which has '\x00':
applet.append("\x1B\x21\x00"); 
applet.append("\x1B\x40");
applet.append("\x1B\x21\x08");
applet.append("Print Testing \r\n");

What is the expected output? What do you see instead?
Expects to see the 'Print Testing' to appear on printer, but nothing appears. 
After sending any commands with '\x00', subsequent commands will not be 
processed by the printer. 

What version of the product are you using? On what operating system?
jZebra 1.3.5 on Windows 7 32bit.

Please provide any additional information below.
I am using a Samsumg Bixolon SRP-350P printer which supports ESCP commands. 
Sending of all other commands (bold, cut paper, feed paper) works, but only 
have problem with those which containts '\x00'.

Original issue reported on code.google.com by zellhw...@gmail.com on 23 May 2012 at 6:25

GoogleCodeExporter commented 9 years ago
Good find.

This may be a limitation to the character set used natively on Windows, as x00 
or null on windows seems to break other things as well such as log files (after 
searching google).

Can you try to force jzebra into using Unicode/UTF? Alternately you can try 
printing from an OS such as Mac OSX or Linux that uses this encoding by default.

      // Force special DOS/Win characters on UNIX/Linux
       document.jzebra.setEncoding("cp866");       // or
       document.jzebra.setEncoding("cp1252");

       // Force UTF8 characters on Windows
       document.jzebra.setEncoding("UTF-8");

Original comment by tres.fin...@gmail.com on 23 May 2012 at 3:18

GoogleCodeExporter commented 9 years ago
Hi, Thanks for the reply. I have tried forcing the encoding to UTF8, but still 
had problem with \x00 values. Using c#, we will send a byte array 
(commands+text) to the printer. I was wondering how we can pass byte array / 
binary data to jzebra (from server side to client size). Maybe I should try 
converting the data to base64 ?

Original comment by zellhw...@gmail.com on 5 Jun 2012 at 2:08

GoogleCodeExporter commented 9 years ago
Thanks again for the excellent feedback.

We can discuss in email if you need this done immediately.  I'm not sure how to 
fix this and it may be a limitation of the Java framework, but some further 
investigation would have to be done to know for sure.

Original comment by tres.fin...@gmail.com on 6 Jun 2012 at 1:53

GoogleCodeExporter commented 9 years ago
I may have found it (requires code change):
http://www.velocityreviews.com/forums/t668757-reading-null-terminated-strings-in
-java.html

They talk about socket I/O but more specifically how java's written treats 
nulls.

Original comment by tres.fin...@gmail.com on 6 Jun 2012 at 2:06

GoogleCodeExporter commented 9 years ago
Hi, Thanks for the reply.

I have resolved the issue by converting the data I wanted to print to Base64 
and using the append64() command to read in the data. This will enable the \x00 
data to be processed correctly. :)

Original comment by zellhw...@gmail.com on 11 Jun 2012 at 4:32

GoogleCodeExporter commented 9 years ago
Would that suggest it is a JavaScript problem?  I'm baffled!

I'll leave this as open in hopes someone can shed light on this.

Original comment by tres.fin...@gmail.com on 11 Jun 2012 at 1:22

GoogleCodeExporter commented 9 years ago
Hi,

I'm using Epson LX-300 and I'm having problem with the British pound sign £.
Tried different methods. So far forcing UTF-8 and sending \x9C I do get T£ 
where T is not a "T" but a table border character \xC2. 
Does it need to be Base64 encoded to get it right?

Original comment by sjzu...@gmail.com on 16 Jun 2012 at 11:46

GoogleCodeExporter commented 9 years ago
OK, I've cracked it!

It's simple but uses different method. 
What you need to do is change code page to UK:
"\x1B\x52\x03"
Then just use # where you want your £. 
£ replaces # in UK code page.

I hope it helps, as I've spent few hours chasing UTF-8 and Base64, where a 
solution is much simpler.

-Simon.

Original comment by sjzu...@gmail.com on 16 Jun 2012 at 4:29

GoogleCodeExporter commented 9 years ago
There's a CPCL scenario where I'd like to leverage the \x00 null characters.  I 
found someone having problems with Internet Explorer with AJAX requests.  What 
browser are you using?

http://stackoverflow.com/questions/8854353/ie-ajax-responses-trim-all-data-after
-null-0x00-characters

Original comment by tres.fin...@gmail.com on 26 Jul 2012 at 7:32

GoogleCodeExporter commented 9 years ago
Ok, I found an answer finally... 

"NULLs are not possible because the Javascript core engine handles strings as 
NULL terminated character array. So every NULL byte in a character array is 
automatically the end of the string. IDM can't change this and of course in 
text files NULL bytes should be never used or present."

http://www.ultraedit.com/forums/viewtopic.php?f=52&t=6935

So, I'll leave this bug open and I'll add specific support for this character 
in a future release.

-Tres

Original comment by tres.fin...@gmail.com on 26 Jul 2012 at 8:51

GoogleCodeExporter commented 9 years ago
Using printFile method I never had this \x00 problem. 

This is an example of how I've done it in PHP.
First you have to build single string:

          $j =("\x1B\x40"); // reset printer
          $j.=("\x1B\x33\x34"); // set line spacing MUST BE x35
          // set printing area
          $j.=("\x1B\x6C\x04"); // left margin x09
          $j.=("\x1B\x44\x03\x14\x37\x3D\x3E\x00"); // set tabs
          //              1   2   3   4   5
          $j.=("\x1B\x52\x03"); // select font UK (for pound sighn #)
          $j.=("\x1B\x6B\x01"); // select typeface - 00 serif - 01 sans serif
          $j.=("\x1B\x74\x01"); // select character table (0-italic, 1-normal)
          $j.=("\x0F"); // select condensed
          //$j.=("\x1B\x77\x01"); // set double height
          $j.=("\x1B\x78\x01"); // 01 set NLQ
          // ########### the PAGE starts here ############
That's it for initialise printer.
Then add some text or whatever you need sending to your page.

Finally end page with:
          $j.=("\f"); // FF next page
          $j.=("\x1B\x40"); // reset printer

And save it to "page.data" file
          $fp = fopen("page.data", "wb+");
          fwrite($fp, $j);
          fclose($fp);

Then use the printFile method pushing file straight to printer.
Never had any problems with \x00 (see where I set tabs). It's working fine on 
both win XP and 7. Browsers: Chrome and Firefox.

-Simon.

Original comment by sjzu...@gmail.com on 27 Jul 2012 at 10:57

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I'm facing the null character issue with EPL2. I can't use multple 
document.jzebra.append() statements nor can I have a \00 character in the 
arguments to append(). 

I believe this is because strings are null terminated and so it counts \00 as 
the end of the string, and so prematurely ending the EPL commands. When ever it 
encounters \00 in the append() arguments I receive a console message saying 
that the current character encoding set is such and such a thing. I think the 
character encoding scheme may interfere with printer commands that have binary 
data in them.

Original comment by triplock...@gmail.com on 7 Nov 2012 at 10:11

GoogleCodeExporter commented 9 years ago
You are correct, JavaScript does not allow this appendNull() was added to fix 
this, but success has been limited.  The best fix so far has been to use (i.e. 
php) the server to generate these commands in base64, which won't be messed up 
by JavaScript.

jZebra supports base64 encoded commands, so this should fix this problem.

-Tres

Original comment by tres.fin...@gmail.com on 7 Nov 2012 at 12:59

GoogleCodeExporter commented 9 years ago
Can anyone please give me the code how to start the printer, i have never used 
it before and i don't now how to start, how to get him inputs.

Original comment by martina....@gmail.com on 8 Jan 2013 at 1:48

GoogleCodeExporter commented 9 years ago
Just download the application 
http://code.google.com/p/jzebra/downloads/detail?name=jZebra%201.4.5.zip and 
everything you need you will find inside. Try examples to see how it's made. 
Good luck.

-Simon.

Original comment by sjzu...@gmail.com on 8 Jan 2013 at 2:00

GoogleCodeExporter commented 9 years ago
Thanks! This helped me a lot!

I encountered this when I was printing NV graphics using ESC/P, where in the 
middle of the command, a '\x00' comes in.

I used http://tomeko.net/online_tools/hex_to_base64.php this site to convert my 
hex string, "\x1D\x28\x4C\x06\x00\x30\x45\x30\x30\x01\x01" into base64, 
"HShMBgAwRTAwAQE=". And then used append64() instead of append(). It worked.

I'm writing here because I wasted so much time searching for a solution through 
various examples and manuals. Hopefully somebody else might find my answer 
useful in the future, and it will save some time and effort for them.

Original comment by rajith.v...@gmail.com on 10 Apr 2013 at 7:15

GoogleCodeExporter commented 9 years ago
A new feature with 1.4.8 allows "\\x00" so that the NUL character doesn't break 
JavaScript.

If someone can, please test this new feature.

i.e.

"\x1D\x28\x4C\x06\x00\x30\x45\x30\x30\x01\x01"

would be

"\x1D\x28\x4C\x06\\x00\x30\x45\x30\x30\x01\x01"

(notice the extra backslash before x00)

-Tres

Original comment by tres.fin...@gmail.com on 25 Apr 2013 at 2:16

GoogleCodeExporter commented 9 years ago
Hi Tres,

thanks for your very good work. I am using zjebra on my webpage to print to an 
Epson TM-T88V. I also encountered the problem when appending a command with 
'\x00' to the applet. For example I set the mode to emphasize ON (with 
'\x1B\x45\x01') and after printing the header I wanted to set it back to 
emphasize OFF (with '\x1B\x45\x00'). But the printer did not set emphasize off 
and printed all the text in bold characters.

I also tried your suggestion to send '\x1B\x45\\x00' (with the extra backslash) 
but it didn't work for me.

But then I read in the ESC/P manual and found that the command for switch 
emphasize OFF only needs to have the LSB set to 0 to switch off the mode. So 
for now I use to send '\x1B\x45\x02' for setting emphasize OFF as a workaround 
and this works fine for me.

Sample code:

applet.append("\x1B\x40");  // Initialize printer
applet.append("\x1B\x45\x01");  // Emphasize on
applet.append("Line is printed with EMPHASIZE ON.\n");
applet.append("\x1B\x45\x02");  // Emphasize off
applet.append("Line is printed with EMPHASIZE OFF.\n");
applet.print();

-Tom

Original comment by thompson...@gmail.com on 16 May 2013 at 2:29

GoogleCodeExporter commented 9 years ago
Hi Guys,

To get the '\x00' working simply write your ESC/P to a file and pass this file 
to jzebra to print from file. Works without fail.

-Simon.

Original comment by sjzu...@gmail.com on 16 May 2013 at 10:22

GoogleCodeExporter commented 9 years ago
Changes 1.5.4:
- Fix for appendHex() now allows "x1B" instead of "\x1B", fixing the "\x00" 
bug.  Just use "x00".

Please test and let me know if it's working.  Use appendHex instead of append.

Original comment by tres.fin...@gmail.com on 3 Aug 2013 at 7:14

GoogleCodeExporter commented 9 years ago
Issue 118 has been merged into this issue.

Original comment by tres.fin...@gmail.com on 3 Aug 2013 at 7:22

GoogleCodeExporter commented 9 years ago
Closing, marking as fixed.  If you feel this bug was closed in error, please 
reopen.

-Tres

Original comment by tres.fin...@gmail.com on 22 Sep 2013 at 7:37

GoogleCodeExporter commented 9 years ago
Hello there.
I've a problem with Absolute Horizontal Print Position,in any Epson printer 
dont work
            qz.append("\x1B\x28\x55\x01\x00\x0A");  
            qz.append("\x1B\x24\x0A\x0A");
            qz.append("Hello\n");   
also tried:
            qz.append64("\x1B\x28\x55\x01\x00\x0A");    
            qz.append64("\x1B\x24\x0A\x0A");
            qz.append64("Hello\n");
an tried appendHex too.
what im doing wrong, I'll apreciate ur help.

Original comment by aespinoz...@gmail.com on 25 Sep 2014 at 6:05

GoogleCodeExporter commented 9 years ago
Please use appendHex('x00') instead.

Original comment by tres.fin...@gmail.com on 25 Sep 2014 at 11:07