Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with printing to receipt printer

Status
Not open for further replies.

johnsun1976

Programmer
Jan 28, 2002
34
CA
Hi.. I'm using a Star SP200 receipt printer and trying to format text on it..

I found this example on the printer's homepage in VB:

PRINT #1, CHR$(27); CHR$(112);
PRINT #1, "14-dot pitch font"

What I'm trying to do is this:

byte []ba = new byte[32];

h = CreateFile("LPT1", GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);

ba[0] = 0x1B;
ba[1] = 0x0D;
ba[2] = 0x0A;
WriteFile(h, p, 3, &n, 0);

ba[0] = 0x70;
ba[1] = 0x0D;
ba[2] = 0x0A;
WriteFile(h, p, 3, &n, 0);

count = stob("14-dot pitch font", ba);
WriteFile(h, p, count, &n, 0);


private int stob(string str, byte []ba)
{
int i = 0;
for(i=0; (i<str.Length && i<ba.Length-2); i++)
{
ba = Convert.ToByte(str);
}

ba = 0x0D;
ba[i+1] = 0x0A;

return i+2;
}

stob is a function that take a string and return a byte array and the lengh for the parameters of WriteFile expects..

Nothing seems to happen when I print.. Does anyone know what I'm doing wrong?
Thanks
John
 
Where are you getting the CreateFile and WriteFile functions from? In .NET, you should be using a StreamWriter object.
Code:
StreamWriter sw = new StreamWriter(&quot;LPT1:&quot;);
sw.AutoFlush = true;
sw.Write(&quot;This is a test&quot;);
sw.Close();
Note: I haven't tried this opening the LPT1 device. Give it a try.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top