-
Code Pages
Hello! How can I send to printer, by use SerialPort, string with
different code pages?
For example:
SerialPort1.WriteLine("textOne") - I need send it in 1250 CodePages,
SerialPort1.WriteLine("textTwo") - I need send it in 1253 CodePages,
SerialPort1.WriteLine("textThree") - I need send it in 1254 CodePages.
If I send it from DOS windows (cmd) by "copy file.txt com1" all is ok,
but if I send it from VB.NET2005 - is problem :(
File "file.txt" contain sequence to print string on a printer.
Could you help me?
Regards, Jacek
-
Re: Code Pages
What is the error that you get?
-
Re: Code Pages
Hi,
I send following string:
SerialPort1.WriteLine("ślimak z łąki") and I see on a label printer after
send from VB:
"?limak z ??ki". :cry:
After send from DOS window (cmd) I see correct string:
"ślimak z łąki" :)
Code page in my country is 1250.
Jacek
-
Re: Code Pages
JacekP,
The problem is that the default encoding for strings sent through the serial port in VB.NET is ASCIIEncoding, which is only ASCII text. Anything it can't convert to ASCII comes through as ? as you see on your label.
Convert to UTF or Unicode and you should be in good shape.
Try this before sending any data through the serial port:
Code:
SerialPort1.Encoding = System.Text.Encoding.UTF8
That should do it. If it doesn't work correctly, try one of these alternative supported encodings.
Code:
SerialPort1.Encoding = System.Text.Encoding.Unicode
SerialPort1.Encoding = System.Text.Encoding.UTF32
-
Re: Code Pages
Thank you :wave:
"ąćżźśłรณ" - is correct :thumb:
I wrote: SerialPort1.Encoding = System.Text.Encoding.GetEncoding(1250)
Regards, Jacek