Results 1 to 5 of 5

Thread: Code Pages

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    8

    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

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Code Pages

    What is the error that you get?

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    8

    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".

    After send from DOS window (cmd) I see correct string:
    "ślimak z łąki"

    Code page in my country is 1250.

    Jacek
    Last edited by JacekP; Aug 28th, 2007 at 02:11 PM.

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    8

    Re: Code Pages

    Thank you
    "ąćżźśłó" - is correct
    I wrote: SerialPort1.Encoding = System.Text.Encoding.GetEncoding(1250)
    Regards, Jacek

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width