Solved

Send Cut Command to POS printer.

Posted on 2004-09-20
20
18,411 Views
Last Modified: 2008-02-20
I have a Star Micronics SP300 (POS) printer. It is installed as a
windows printer with Generic Text Only drivers. I'm using RawPrinter
Helper Class to
send data to the printer. See: http://support.microsoft.com/?id=322090
. It works correctly printing the text.

My only problem is that this printer has an AutoCuter feature (to cut
the ticket paper) but to make it work, I have to send a special code
to the printer.

I tried using the SendStringToPrinter method from the
rawprinteerhelper class (VB.NET), but it did not work.

I need to make this printer cut the paper under VB.NET (with
the printer installed under windows).

One problem is that this printer is serial (COM1) so, I cannot just
open the port and send the data because when it is installed as a
printer, the com1 is under exclusive access by windows. And also the
OPOS driver that has a function to send the cut command does not work
if the printer is installed in windows.

I think that a solution would be to use SendBytesToPrinter from
Rawprinterhelper class, but I just dont know how this function works.

A few Reference URL's you can find useful:

http://return.no-ip.org/n54/index49/1013655327.html
http://www.starmicronics.com/printers/printers_pages/support/programming.html

Also download the Developer guides from starmicronics.com to see a
complete code reference.
0
Comment
Question by:emiliodabdoub
20 Comments
 
LVL 12

Expert Comment

by:fulscher
ID: 12109871
Ok, if I understand correctly, you have to send out the
    CHR$(27) & CHR$(100); & CHR$(51)
to the printer. So the only problem is how to use the SendBytesToPrinter sample from MSDN.

I assume you have copied all the sample code from MSDN, is that right? What doesn't work? Compiler errors? Or run-time errors?

Jan
0
 
LVL 2

Expert Comment

by:TeddyZero
ID: 12116369
With the POS Driver try to do this...

' PAPER CUT - PARTIAL CUT
POSPrinter1.PrintNormal PTR_S_RECEIPT, Chr$(27) + "|99P"

' PAPER CUT - FULL CUT
POSPrinter1.PrintNormal PTR_S_RECEIPT, Chr$(27) + "|100P"

' FEED TO THE CUTTING POSITION AND THEN CUT
POSPrinter1.PrintNormal PTR_S_RECEIPT, Chr$(27) + "|fP"

0
 
LVL 1

Author Comment

by:emiliodabdoub
ID: 12117259
Jan:
I compiled and ran the MSDN sample as I posted in the question. I can print with the sendstring to printer which at the same time uses sendbutestoprinter.

My problem is that if I use: sendStringtoprinter( CHR$(27) & CHR$(100); & CHR$(51))

it just dont make anything.

In the programming samples comes a sample in VB6 with: Print #1, CHR$(27) ; CHR$(100); ; CHR$(51)

but I dont know if it is the same as concatenating with &, they use a ;
and also they open the port directly, not using the printer drivers.

TeddyZero:
As I stated on the question I cant use the Opos Drivers because the printer is installed as a window printer.
0
 
LVL 12

Expert Comment

by:fulscher
ID: 12117431
Emilio,

thanks for the explanation. So, first we have to find out whether the printer accepts input from SendStringToPrinter. To do so, we could just send a long string of text:

Dim s as String
s = "The quick brown fox jumps over the lazy dog" & CHR(13) & CHR(10).
sendStringtoprinter(s)
sendStringtoprinter(s)
sendStringtoprinter(s)
sendStringtoprinter(s)
sendStringtoprinter(s)

This should print five lines. Can you try this, please?

Jan
0
 
LVL 1

Author Comment

by:emiliodabdoub
ID: 12119358
yes, it printed 5 lines..
0
 
LVL 12

Expert Comment

by:fulscher
ID: 12119964
Excellent - this means that sendStringToPrinter works as expected.

According to http://www.starmicronics.com/printers/printers_pages/support/programming.html, the CUT command sequence is as follows:

' FEED TO CUT POSITION THEN PERFORM PARTIAL CUT ( ONLY WORKS WITH PRINTERS THAT HAVE AUTO
' CUTTING CAPABILITY)
' IF PRINTER DOES NOT HAVE FULL CUT CAPABILITY, PARTIAL CUT WILL BE PERFORMED
' CMD:  <ESC> "d" "3"
' PRINT #1, CHR$(27); CHR$(100); CHR$(51);

So, this translates to
SendStringToPrinter(CHR(27) & "d3")

Can you try this?

If it doesn't work, add a CR/LF:
SendStringToPrinter(CHR(27) & "d3" & CHR(13) & CHF(10))

Jan
0
 
LVL 12

Expert Comment

by:fulscher
ID: 12119979
... and if this doesn't work, can you try

SendStringToPrinter(Chr$(27) & "|100P")

... and if this doesn't work, can you try

SendStringToPrinter(Chr$(27) & "|100P" & CHR(13) & CHR(10))

The documentation is not consistent about the CUT command, so we'll have to experiment.

Jan


0
 
LVL 1

Author Comment

by:emiliodabdoub
ID: 12120078
Hi, I spent 2 hours researching, and found a lot of users with the same problem, it is incredible that nobody has the answer to this. To mention just a few URL's :

http://www.dotnet247.com/247reference/msgs/7/35188.aspx
http://www.mail-archive.com/vb_dotnet@p2p.wrox.com/msg00488.html
http://www.dotnet247.com/247reference/msgs/24/121212.aspx

I already tried that, I found that the data passed that way is called Escale Sequences, and maybe they cant be sent as a plain String.

I found an interesting answer to a user here in experts exchange with teh same problem. The problem is that I dont know C++

check: http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_10163890.html?query=control+codes+printer&clearTAFilter=true

Check the accepted answer.
0
 
LVL 1

Author Comment

by:emiliodabdoub
ID: 12120085
sorry, not Escale Sequences, it is Escape Sequences.. and I tried all your samples in the past. That is why I'm here :)
0
 
LVL 1

Author Comment

by:emiliodabdoub
ID: 12120222
I found this:

this explains and resolves the problem, jus tell me how to implement it in VB.NET (through interop or anyway is good!) and you get the points
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 12

Accepted Solution

by:
fulscher earned 500 total points
ID: 12120470
Emilio,

The Chr(27) _is_ the Escape code; if you check an ASCII table, you'll find that CHR(27) is called ESCAPE. Most printers use ESC sequences for device control.

Since printing the string "the quick brown fox..." using SendStringToPrinter worked, we can assume that you CAN send escape sequences to the printer using SendStringToPrinter. So, this is the right way to go.

Next, we try whether we can do other things, like setting a text to bold. If this works, we know that SendStringToPrinter also processes ESC sequences correctly. From the manual (http://www.starmicronics.com/printers/printers_pages/support/manuals/SP300PM.PDF):

<ESC> “-” “1” 1B 2D 31  -  Select underline mode
<ESC> “-” <1> 1B 2D 01

<ESC> “-” “0” 1B 2D 30  -  Cancel underline mode
<ESC> “-” <0>

So, please try the following:

Const ESC = Chr(27)
Const CR = Chr(13)
Const LF = Chr(10)
Dim UnderlineOn as String
Dim UnderlineOff as String

UnderlineOn = ESC & Chr(&H2D) & Chr(&H31)
UnderlineOff = ESC & Chr(&H2D) & Chr(&H30)

SendStringToPrinter("The quick " & UnderlineOn & "brown fox" & UnderlineOff & " jumps." & CR & LF)


Does this print the string with underlines?

Jan
0
 
LVL 1

Author Comment

by:emiliodabdoub
ID: 12120520
YES!!! it prints in Underlines!!!
Damn, why it dont cut the paper?
0
 
LVL 1

Author Comment

by:emiliodabdoub
ID: 12120607
Maaaaan! you are the maaaaaaan! hahahahahahah

It worked! at last! I'm so happy!!!!

I got the Hex codes from the programmers manual...

CutPaper = ESC & Chr(&H64) & Chr(&H31)

Holy....

You have the points..

Many Thanks!!!
I can sleep now!!! zzzZZZzz
0
 
LVL 12

Expert Comment

by:fulscher
ID: 12120618
Because the ESC sequence was wrong or incomplete.

Let's check in the manual again:

Trigger auto-cutter drive (Auto-cutting models only)
<ESC> “d” “0” or <ESC> “d” <0>        (1B)H (64)H (30)H or (1B)H (64)H (00)H
<ESC> “d” “1” or <ESC> “d” <1>        (1B)H (64)H (31)H or (1B)H (64)H (01)H
OUTLINE This code causes the printer to trigger auto-cutter.

I do not understand why there are two ESC sequences, so we'll have to experiment.

Try to add the following code:
...
Dim Autocut1 as String
Dim Autocut2 as String

Autocut1 = ESC & Chr(&H64) & Chr(&H30)
Autocut2 = ESC & Chr(&H64) & Chr(&H31)
...

SendStringToPrinter("Before Autocut1" & CR & LF)
SendStringToPrinter(Autocut1)
SendStringToPrinter("After Autocut1" & CR & LF)
SendStringToPrinter("Before Autocut2" & CR & LF)
SendStringToPrinter(Autocut2)
SendStringToPrinter("After Autocut2" & CR & LF)

What happens now? It should cut twice...
0
 
LVL 12

Expert Comment

by:fulscher
ID: 12120797
Thanks for the points and good luck to you.
Jan
0
 
LVL 1

Author Comment

by:emiliodabdoub
ID: 12120897
just for curiosity..

Why char(27) & "d3" was not working?
0
 
LVL 12

Expert Comment

by:fulscher
ID: 12120988
I think ESC & "d3" is not valid. Valid codes are ESC & "d0" and ESC & "d1" according to the docs.

Jan
0
 
LVL 1

Author Comment

by:emiliodabdoub
ID: 12121006
damn.. right.

I tested and it works..

I should sue them.. they took about 10 hours of my time :@
0
 
LVL 12

Expert Comment

by:fulscher
ID: 12121141
Well, escape code can and do vary from manufacturer to manufacturer and from model to model. So, ESC & "d3" may work for model 299, but not 300...

0
 

Expert Comment

by:xuanru
ID: 14630356
I understand this is an old question, but i am facing the same problem now! The only difference is my POS printer is Wincor Nixdorf ND69. I am using Windows NT Generic/Text Only Driver, and i have to use JAVA but not VB to code the ESC Sequence. The ESC sequece to CUT Receipt is <1B>H <69>H . Can anybody tell me how can i make it works???
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now