I am writing C# application that need to print data to POS STAR printer using RawPrinterHelper.
My printing works fine except when I sending characters like ŽĆČĐŠ. Then I get wrong data printed out.
Until now my research give me following results.
If I in PowerShell open good old edit and in txt file write my characters (ŽĆČĐŠ) and send that to printer I get print out as I wish
I can't that repeat using Notepad
How I can in C# encode my sting to looks like that one from command prompt (EIDTor). So when I send data to printer it print Desire fonts as it looks like in Windows environment.
I did also try to print using Star driver and their C# sample for sending data directly to printer but without success.
EDIT:
I did it, and for others Who in generally have troubles printing directly on Star printers using C# here is code for sample app from Star IO Programming Tool for using their driver.
using System;
using System.Text;
using StarMicronics.StarIO; // added as a reference from the "Dependencies" directory
// requires StarIOPort.dll, which is copied to the output directory by the Post-Build event
namespace TestEnkodera
{
class Program
{
static void Main(string[] args)
{
string portName = "LPT1";
string portSettings = string.Empty;
string print = string.Empty;
//Select code page
//Decimal 27 29 116 n
print += string.Format("{0}{1}{2}{3}{4}", (char)27, (char)29, (char)116, (char)5, Environment.NewLine);
print += "Đ Š Ž Ć Č ž ć č ć \n";
IPort port = null;
port = StarMicronics.StarIO.Factory.I.GetPort(portName, portSettings, 10 * 1000);
//byte[] command = ASCIIEncoding.ASCII.GetBytes(print); //This was orginal code provided by STAR
Encoding ec = Encoding.GetEncoding(852); //Here is way to set CODEPAGE to match with printer CODE PAGE
byte[] command = ec.GetBytes(print);
uint totalSizeCommunicated = WritePortHelper(port, command);
StarMicronics.StarIO.Factory.I.ReleasePort(port);
Console.ReadKey();
}
private static uint WritePortHelper(IPort port, byte[] writeBuffer)
{
uint zeroProgressOccurances = 0;
uint totalSizeCommunicated = 0;
while ((totalSizeCommunicated < writeBuffer.Length) && (zeroProgressOccurances < 2)) // adjust zeroProgressOccurances as needed
{
uint sizeCommunicated = port.WritePort(writeBuffer, totalSizeCommunicated, (uint)writeBuffer.Length - totalSizeCommunicated);
if (sizeCommunicated == 0)
{
zeroProgressOccurances++;
}
else
{
totalSizeCommunicated += sizeCommunicated;
zeroProgressOccurances = 0;
}
}
return totalSizeCommunicated;
}
}
}