Reputation: 155
I'm currently working on a new program to print receipts which contain arabic text. The printer can handle these characters, but uses a special code table to print them. Therefore all information sent to the printer must be in hex. Information sent to the printer can have a mix of both arabic and non arabic characters.
The code table is here(page 133 http://support.epostraders.co.uk/support-files/documents/3/dwY-TM-T88V_TechRefGuide.pdf)
For example, ق = E7, ك = E8
With a standard hex conversion (below) the first 128 latin alphanumeric characters work just fine, but arabic are displayed as question marks.
byte[] ba = Encoding.Default.GetBytes(textBox1.Text);
var hexstring = BitConverter.ToString(ba);
Does anyone have any suggestions for the best way to convert to the correct hex?
Upvotes: 2
Views: 1105
Reputation: 155
Answering this myself in case anyone else has a similar issue.
So the scenario was trying to send Arabic characters to a TM-T88iV Epson printer. Firstly, You need the TM-T88V or later to support Arabic.
Secondly, characters must be sent to the printer as Bytes using a Write command rather than as a String in a WriteLine. The Write command needs to terminate with a CRLF in order for the printer to print. The printer has no Right-to-Left funtion, so the Bytes sent to the printer need to be inverted first: Array.Reverse(byte[])
In order to get visual studio to convert arabic characters to the correct hex values, you need to change the windows code table. This is usually done in Control panel > region & language > administrative > language for non-unicode. Windows default for UK was 850. Arabic (U.A.E) is 720. You can double check by running cmd and typing chcp. As it turns out, Arabic U.A.E 720 is NOT correct, you need 1256. I couldn't find the matching language in control panel, so I changed it manually in cmd using the command 'chcp 1256'
Finally, you need to change the internal code table of the printer. To do this, I used the TM-T88V utility (https://download.epson-biz.com/modules/pos/index.php?page=single_soft&cid=4100&pcat=3&scat=42). I believe you can do this via direct commands sent via serial too, but it proved too fiddly.
Fingers crossed this should all work now. Happy printing.
Upvotes: 2