ESC/POS Termal printer UTF-8 charset set up - android

I am trying to print some currency with Citaq v8 (it has a termal printer), but it prints ?, because of the printer character set.
I have byte array (UTF-8) data to print. But the printer has default some character set. How can I change the default character set programatically(like using byte array)? I need to change printer charset settings.
Device: Citaq v8 (the device has a termal printer)
PS: I could not find any developer docs.

Perhaps UTF-8 is not supported as a character set/code table.
Even EPSON is supported only on some models.
FS ( C <Function 48>
Select character encode system
ASCII FS ( C pL pH fn m
Hex 1C 28 43 02 00 30 m
Decimal 28 40 67 2 0 48 m
TM-P20
1, 49 ASCII (ISCII) ISCII: Indian Script Code for Information Interchange
2, 50 UTF-8 Unicode encoding system
TM-m30II, TM-m30II-H, TM-m30II-NT
1, 49 1-byte character encoding Non-Unicode encoding method (ASCII [extended], Shift JIS, Big5, GB2312, GB18030, KS C, etc.)
2, 50 UTF-8 Unicode encoding system
You need to set the printer code page using the following two ESC/POS commands, and the character string to be requested for printing must be encoded and converted according to the code page before sending.
ESC t
Select character code table
ASCII ESC t n
Hex 1B 74 n
Decimal 27 116 n
ESC R
Select an international character set
ASCII ESC R n
Hex 1B 52 n
Decimal 27 82 n
Alternatively, you can create all the page contents to be printed with a Bitmap image and print it with one of the ESC/POS commands related to image printing.
However, it will be slow.

Related

Print strings on Apex3 using printer command language

How to print strings on Apex3 using printer command language or SDK?
I created a library for android application to print Bitmap images on mobile thermal printers:
Apex3, 3nStar, PR3, Bixolon, Sewoo LK P30 using appropriate SDKs.
It works fine but pretty slow, every ticket of 30 cm length takes 20-40 secs to print (it depends on type of printer).
For 3nStar and Apex3 I started to do improvements to speed up a printing.
For 3nStar I developed a class which prints a header logo and formatted text with spanish characters.
(different alignments and different fonts for different parts of a ticket)
so, the ticket looks very similar as Bitmap image but a printing time is only 6 secs.
Now I have to do the same but with Apex3. And here I got stuck.
How I do it on 3nStar for strings:
I send in outputStream bytes which are commands for printer what to do.
outputStream.write(some_bytes)
First command always is
{0x1b, 0x74, 40} //Esc t ( -- [ISO8859-15 (Latin9)]
to print spanish characters.
Then, in a loop, for n strings:
I choose a font
{0x1B, 0x21, 0x00}//Esc ! 0 -- 0 is normal, 8 is bold etc.
where changing last byte I print different fonts: normal, bold, two height, two width and combined fonts.
Next I choose an alignment
{0x1b, 0x61, 48} //Esc a 48 for left, 49 for center, 50 for right
Then I convert a string in bytes using ISO_8859_1 to print spanish characters and also write in outputStream.
outputStream.write(messageString.getBytes(StandardCharsets.ISO_8859_1))
And last byte to send is
{0x0a} // Move on next line
And the above approach doesn't work with Apex3, also I failed using
http://www.old.adtech.pl/upload/Extech_Printer_Command_Language%20Rev_H_05062009.pdf
even though on page 1 of that book is written that is fit for Apex3.
I think I miss something, I start to see how to do it using some SDK feature of Android_SDK_ESC_V1.01.17.01PRO.jar
but I would prefer to do that using direct writing of bytes.
Answers I found from this
manual
Shortly differences with the approach that I described for 3nStar are:
1)Before printing set a char set
ESC F 1 //Esc t - for 3nStar
2)Set a font for text, for example
ESC K 1 3 CR //ESC F 1 - for 3nStar
3)Send a line of text with alignment
For 3nStar I can use an alignment command before sending a text, like
ESC 1 49 //Centering
But for Apex3 I have to know a line length which depends on type of font, also a length of printing string,
then I get
freeSpace = (lineLength - printingString)
and set spaces at the begining of a line (right alignment),
at the end (left alignment) or devide them (centering).
So, for both types of printers I use the same logic which differs only in 3 places.
It is simplified explanation as a real code includes several classes with hundreds lines of code.

Reading a NFC Mifare card raw data in android

I'm trying to read the content of a Mifare Ultralight card using the NFC contactless reader ACR122U Android SDK.
I am able to get following hex values
01 03 A0 0C 44 03 15 D1 01 11 54 02 65 6E 33 34
But I am unable to get my actual data. Please guide me how to extract byte array from above hex values.
So it seems that you read 4 pages starting at page 4 from this MIFARE Ultralight tag. Moreover, the tag seems to be formatted according to the NFC Forum Type 2 Tag Operation specification (available from the NFC Forum website).
A Type 2 Tag contains a series of tag-length-value (TLV) structures:
01 (Tag: Lock Control TLV)
03 (Length: 3 bytes)
A0 0C 44 (Value: Information on position and function of lock bytes)
03 (Tag: NDEF Message TLV)
15 (Length: 21 bytes)
D101115402656E3334... (Value: NDEF message)
You would have to issue a read command for the next 4 pages to obtain the remaining data of the NDEF message.
For now, we know, that the tag contains an NDEF message starting with
D101115402656E3334
This translates to
D1 (Header byte of record 1)
- Message begin is set (= first record of an NDEF message)
- Message end is set (= last record of an NDEF message)
- Short record flag is set (= Payload length field consists of 1 byte only)
- Type Name Format = 0x1 (= Type field contains an NFC Forum well-known type)
01 (Type length: 1 byte)
11 (Payload length: 17 bytes)
54 (Type: "T")
02656E3334... (Payload field)
The payload field of an NFC Forum Text record decodes like this:
02 (Status byte: Text is UTF-8 encoded, Language code has a length of 2 bytes)
656E (Language code: "en")
3334... (Text: "34"...)

How to send ATR command to reset nfc secure element using android?

i am building android application which connect to nfc secure element and get data to the android device.for building secure element i used java card API.In the jcop tools send ATR command to reset the java card.This is the sending commands.
/card -a a000000003000000 -c com.ibm.jc.CardManager
resetCard with timeout: 0 (ms)
--Waiting for card...
ATR=3B F8 18 00 FF 81 31 FE 45 4A 43 4F 50 76 32 34 ;.....1.EJCOPv24
31 43 1C
ATR: T=1, FI=1/DI=8 (31clk/etu), N=-1, IFSC=254, BWI=4/CWI=5, Hist="JCOPv241"
=> 00 A4 04 00 08 A0 00 00 00 03 00 00 00 00
i am using jcop tools for that.Secure element part is complete.but my android application need to send more request to secure element at one second.I used create a tag and send data this way.
byte[] GET_STRING = {
(byte) 0x80, // CLA Class
0x04, // INS Instruction
0x00, // P1 Parameter 1
0x00, // P2 Parameter 2
0x10 // LE maximal number of bytes expected in result
};
result = tag.transceive(GET_STRING);
int len = result.length;
if (!(result[len-2]==(byte)0x90&&result[len-1]==(byte) 0x00))
throw new RuntimeException("could not retrieve msisdn");
byte[] data = new byte[len-2];
System.arraycopy(result, 0, data, 0, len-2);
String str = new String(data).trim();
tag.close()
But I need to know how to send ATR command using android isoDep connection. if it is not possible how to reset the java card after getting data.
Thanks
Sajith
Regarding your terminology:
On the contactless interface, you card does not have a reset sequence that produces an ATR. However, there is two comparable events on the contactless interface. One is turning the HF field off ann on. This causes a power-loss and consequently a hard reset of the card. The second one is to put the contactless card in HALT state and re-activate the card through the activation & selection procedure as specified in ISO/IEC 14443-3. This would typically also cause a card to reset its internal state.
Regarding your question of how to reset a contactless card that is connected through Android's IsoDep:
Hard reset: That's only possible through bringing the card out of the NFC device's read range and then scanning it again.
"Soft reset": On most devices this should be possible through closing and re-opening the connection using the IsoDep instance:
IsoDep isoDepTag = IsoDep.get(tag);
[...]
isoDepTag.close();
isoDepTag.connect();
[...]
However, you should be avare that some device (e.g. the Galaxy S4 in combination with certain Android versions) will not properly perform a soft reset (HALT + reactivation/selection) and, instead, just continue the previous connection.

Zebra RW420 CPCL font issue

I've designed a label with Label Vista (free Zebra software) and I went watching at the generated CPCL code, I noticed:
_TTF -23 0 0 400 0 0 0 0 2 34 [Arial] 117 16 Test TTF string
T Ari06pt.cpf 0 118 45 Test Uploaded font string
I've uploaded to the printer the Ari06pt.cpf generated font.
Then I've tried to print from Label Vista and all went OK! IT WORKS!
After that I've passed the code to my android application (JAVA with Zebra SDK) and I've tried to print, but in this case only the
"T Ari06pt.cpf 0 118 45 Test Uploaded font string\r\n"
works right.... the first line (_TTF) is NOT WORKING anymore (white line was printed)...
Some solution?
According to CPCL manual:
_TTF -23 0 0 400 0 0 0 0 2 34 [Arial] 117 16 Test TTF string
is not a CPCL command. However, LabelVista creates for some reason (??) this command using resident TrueType fonts of your desktop OS and converts it silently in printing time to a CPCL "T" command like that:
T Ari06pt.cpf 0 117 16 Test TTF string
So I think that you should check LabelVista output if it contains commands other than CPCL. You can also try ZebraDesigner editor.
I have worked with Zebra MZ320 and QL420+ and they accept only prescaled fonts (*.cpf files) in their memory. So try to convert a TrueType font to a prescaled font. You can convert it using LabelVista or Zebra Font Downloader and then upload it to your printer. You can follow this Zebra font convertion guide.

How to store and display both ISO-8859-1 and UTF8 characters using perl

I am quite new to this, and this might be very easy to most people, but I have been struggling with this for days.
I'm writing a web crawler using perl, and the web crawler will extract certain information using LWP and some simple regular expression.
These information are saved in a mySQL database, which will be used on an android device.
However, when I tested the web crawler, I realized some information are in Chinese (典華) using HTML numeric coding (&# 20856 ; &# 33775 ;), and some information are using iso-8859-1 encoding (Zhífú).
I solved the Chinese part using the PERL HTML::Entities library, which can be displayed when I set my console to utf8. However, the other letters (Zhífú) can only be displayed in iso-8859-1. If I try to display it in utf8, it will become Zh�f�. My question is:
How could I determine which kind of encoding it use, and how can I display it differently?
Would I be able to store it in mySQL directly, or I should process the information first (correct me if I am wrong, but my understanding is that mySQL use utf8 as the default language).
Would this cause some kind of problem when I display it on an android device?
Thank you very much.
(Zhífú) can only be displayed in iso-8859-1. If I try to display it in utf8, it will become Zh�f�.
That's completely false. You can display "Zhífú" in both iso-8859-1 and UTF-8 terminals/applications/whatever. In fact, the fact that you see "Zhífú" is proof that it can be displayed in UTF-8, since this is a UTF-8 web page. If you're getting "Zh�f�", it's because you didn't encode the string using UTF-8 before giving it to the terminal/application/whatever that wants UTF-8.
Anyway, on to the question. I'm assuming that you're storing text, not HTML.
Decode every input! Encode every output! Then no problem.
From the web
5a 68 c3 ad 66 c3 ba
|
decode Done for you by ->decoded_content (LWP::UA)
| or by ->content (WWW::Mech)
v
Decoded text Manipulate as desired
Zhífú
|
encode Done for you by DBI
|
v
Database
5a 68 c3 83 c2 ad 66 c3 83 c2 ba
In fact, the decoding should already be done for you by ->decoded_content, and the encoding should already be done for you by DBI, so I don't see why you're having trouble with this.
Same thing when you read from the database and output to the screen/whatever.
5a 68 c3 83 c2 ad 66 c3 83 c2 ba
Database
|
decode Done for you by DBI if you use
| the ..._utf8 flag for your driver
v
Decoded text Manipulate as desired
Zhífú
|
encode use open ':std', ':locale';
|
v
Screen
5a 68 c3 83 c2 ad 66 c3 83 c2 ba

Categories

Resources