Link to home
Start Free TrialLog in
Avatar of trstimac
trstimac

asked on

ESC Sequence for Citizen receipt printer from C++ application

I am trying to print to a receipt printer. I am using the following code:

ofstream print

print.open("LPT1"); // open stream

print << "Text will print fine"

print << "\0x0c" //This will produce a form feed...and it also works. \f also produced a form feed......
//the problem is the next line where I try to use the esc command sequence to tell the receipt printer to cut the paper...
print << "\0x1B 0x50 0x01";   //I've tried this line a million different ways and I cannot get it to work.  

print.close();

For some reason it seems to ignore the escape sequence..In visual basic I can get the printer to cut when I use printer.NewPage .....How do I do this in Visual C++?

Does anyone know how to solve my problem? It would be greatly appreciated!!!!!
Avatar of jkr
jkr
Flag of Germany image

Try to open the printer in 'binary' mode, e.g.

print.open("LPT1", ios_base::out | ios_base::binary); // open stream
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also you can try with:
print << "\0x1B\0x50\0x01";
But I think not all compilers supports these escape sequences  
Avatar of trstimac
trstimac

ASKER

This seems to cut the paper:  print << "\033\120\001";
But now I have another problem.

It seems to perform the command before all of the text is written.

I even tried to close the port and then reopen it and just use the cut sequence.

Please detail a bit more, your last post is not so clear.
Suggestion, try to use a CR or LF after cutting:

 "\033\120\001\n"  or  "\033\120\001\r"


My fault!!

Your code does the trick.  

The cuter is after the printer so you have to do a couple of \f (form feeds) at the end and then cut it.

Thank You for you quick response and all of your help!



Appears you forgot to close this question...
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: jaime_olivares

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

jhshukla
EE Cleanup Volunteer