Sending Escape codes to printer

93 views
Skip to first unread message

Hugh Myrie

unread,
Apr 3, 2021, 5:55:19 PM4/3/21
to golang-nuts
Given the following, how do I send escape codes to print?

for _, line := range lines {
fmt.Fprintf(p, "%s\r\n", line)
}

How do I send escape sequences using the above print command?

Below is a C# example:

output = Chr(&H1D) & "V" & Chr(66) & Chr(0);

I want to send the escape codes to a receipt printer to control the perform cetrain functions.

Some commands include:
ESC "J" 4  <--Feed paper 

 GS "!" 0x11  <-- change character size

Kurtis Rader

unread,
Apr 3, 2021, 6:15:41 PM4/3/21
to Hugh Myrie, golang-nuts
Start here: https://golang.org/ref/spec#Rune_literals. Then read the next section about string literals and note that rune escape sequences are recognized inside double-quoted strings. For example, your feed paper command could be written "\033J\004" or "\x1bJ\x04". There are other ways, of course, to construct such strings that may be more readable by using constant declarations such as `const Esc '\x1b'`.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/b420e7fc-55c4-452c-822e-e84a3b96da85n%40googlegroups.com.


--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

Hugh Myrie

unread,
Apr 3, 2021, 7:43:55 PM4/3/21
to Kurtis Rader, golang-nuts
Awesome, thanks! 
--
Reply all
Reply to author
Forward
0 new messages